diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-06 16:53:21 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-06 16:53:21 +0800 |
commit | 35add89c879dd1d12e7ed702d7543f5a749a1d3e (patch) | |
tree | 003efe1e5d1ee270700b63264b8050c41aba14d6 | |
parent | 46e7c8512edd6de49c546467505673155ebbd1c2 (diff) | |
parent | 6c7f5e3d0e6f4166f161278fdced3d90dfd6f9cc (diff) | |
download | dexon-35add89c879dd1d12e7ed702d7543f5a749a1d3e.tar.gz dexon-35add89c879dd1d12e7ed702d7543f5a749a1d3e.tar.zst dexon-35add89c879dd1d12e7ed702d7543f5a749a1d3e.zip |
Merge pull request #1397 from tgerring/rpcreceipt
getTransactionReceipt RPC support
-rw-r--r-- | rpc/api/eth.go | 26 | ||||
-rw-r--r-- | rpc/api/parsing.go | 33 | ||||
-rw-r--r-- | rpc/api/utils.go | 1 | ||||
-rw-r--r-- | xeth/xeth.go | 1 |
4 files changed, 60 insertions, 1 deletions
diff --git a/rpc/api/eth.go b/rpc/api/eth.go index db0b4b024..6d759a087 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -77,6 +77,7 @@ var ( "eth_submitWork": (*ethApi).SubmitWork, "eth_resend": (*ethApi).Resend, "eth_pendingTransactions": (*ethApi).PendingTransactions, + "eth_getTransactionReceipt": (*ethApi).GetTransactionReceipt, } ) @@ -596,3 +597,28 @@ func (self *ethApi) PendingTransactions(req *shared.Request) (interface{}, error return ltxs, nil } + +func (self *ethApi) GetTransactionReceipt(req *shared.Request) (interface{}, error) { + args := new(HashArgs) + if err := self.codec.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + + txhash := common.BytesToHash(common.FromHex(args.Hash)) + tx, bhash, bnum, txi := self.xeth.EthTransactionByHash(args.Hash) + rec := self.xeth.GetTxReceipt(txhash) + // We could have an error of "not found". Should disambiguate + // if err != nil { + // return err, nil + // } + if rec != nil && tx != nil { + v := NewReceiptRes(rec) + v.BlockHash = newHexData(bhash) + v.BlockNumber = newHexNum(bnum) + v.GasUsed = newHexNum(tx.Gas().Bytes()) + v.TransactionIndex = newHexNum(txi) + return v, nil + } + + return nil, nil +} diff --git a/rpc/api/parsing.go b/rpc/api/parsing.go index 632462c31..4209ea7e3 100644 --- a/rpc/api/parsing.go +++ b/rpc/api/parsing.go @@ -1,6 +1,7 @@ package api import ( + "bytes" "encoding/binary" "encoding/hex" "encoding/json" @@ -402,6 +403,38 @@ func NewUncleRes(h *types.Header) *UncleRes { // WorkProved string `json:"workProved"` // } +type ReceiptRes struct { + TransactionHash *hexdata `json:transactionHash` + TransactionIndex *hexnum `json:transactionIndex` + BlockNumber *hexnum `json:blockNumber` + BlockHash *hexdata `json:blockHash` + CumulativeGasUsed *hexnum `json:cumulativeGasUsed` + GasUsed *hexnum `json:gasUsed` + ContractAddress *hexdata `json:contractAddress` + Logs *[]interface{} `json:logs` +} + +func NewReceiptRes(rec *types.Receipt) *ReceiptRes { + if rec == nil { + return nil + } + + var v = new(ReceiptRes) + v.TransactionHash = newHexData(rec.TxHash) + // v.TransactionIndex = newHexNum(input) + // v.BlockNumber = newHexNum(input) + // v.BlockHash = newHexData(input) + v.CumulativeGasUsed = newHexNum(rec.CumulativeGasUsed) + // v.GasUsed = newHexNum(input) + // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation + if bytes.Compare(rec.ContractAddress.Bytes(), bytes.Repeat([]byte{0}, 20)) != 0 { + v.ContractAddress = newHexData(rec.ContractAddress) + } + // v.Logs = rec.Logs() + + return v +} + func numString(raw interface{}) (*big.Int, error) { var number *big.Int // Parse as integer diff --git a/rpc/api/utils.go b/rpc/api/utils.go index e6a01d3d6..54ca28774 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -86,6 +86,7 @@ var ( "submitWork", "pendingTransactions", "resend", + "getTransactionReceipt", }, "miner": []string{ "hashrate", diff --git a/xeth/xeth.go b/xeth/xeth.go index 1cec82e5e..88d802820 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -969,7 +969,6 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS if contractCreation { addr := crypto.CreateAddress(from, nonce) glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr) - return addr.Hex(), nil } else { glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To()) } |