From 6cfeb6e7545b974770595c87b40c76242ffd8555 Mon Sep 17 00:00:00 2001 From: Austin Abell Date: Wed, 25 Sep 2019 14:38:33 -0400 Subject: [PATCH] eth_getTransactionReceipt Impl (#109) * wip Implement get transaction receipt, waiting on details to finalize * Fix response format for tx receipt * Fix duplicate err check * remove cumulative gas field * Used byte conversion function --- rpc/eth_api.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++-- x/evm/handler.go | 2 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/rpc/eth_api.go b/rpc/eth_api.go index b2fc247b..e3c0f651 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -504,8 +504,56 @@ func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum BlockNumber, } // GetTransactionReceipt returns the transaction receipt identified by hash. -func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) map[string]interface{} { - return nil +func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]interface{}, error) { + tx, err := e.cliCtx.Client.Tx(hash.Bytes(), false) + if err != nil { + // Return nil for transaction when not found + return nil, nil + } + + // Query block for consensus hash + block, err := e.cliCtx.Client.Block(&tx.Height) + if err != nil { + return nil, err + } + blockHash := common.BytesToHash(block.BlockMeta.Header.ConsensusHash) + + // Convert tx bytes to eth transaction + ethTx, err := bytesToEthTx(e.cliCtx, tx.Tx) + if err != nil { + return nil, err + } + + from, _ := ethTx.VerifySig(ethTx.ChainID()) + + // Set status codes based on tx result + var status hexutil.Uint + if tx.TxResult.IsOK() { + status = hexutil.Uint(1) + } else { + status = hexutil.Uint(0) + } + + fields := map[string]interface{}{ + "blockHash": blockHash, + "blockNumber": hexutil.Uint64(tx.Height), + "transactionHash": hash, + "transactionIndex": hexutil.Uint64(tx.Index), + "from": from, + "to": ethTx.To(), + "gasUsed": hexutil.Uint64(tx.TxResult.GasUsed), + "cumulativeGasUsed": nil, // ignore until needed + "contractAddress": nil, + "logs": nil, // TODO: Do with #55 (eth_getLogs output) + "logsBloom": nil, + "status": status, + } + + if common.BytesToAddress(tx.TxResult.GetData()) != (common.Address{}) { + fields["contractAddress"] = hexutil.Bytes(tx.TxResult.GetData()) + } + + return fields, nil } // GetUncleByBlockHashAndIndex returns the uncle identified by hash and index. Always returns nil. diff --git a/x/evm/handler.go b/x/evm/handler.go index 043a49ae..f0b36554 100644 --- a/x/evm/handler.go +++ b/x/evm/handler.go @@ -106,7 +106,7 @@ func handleETHTxMsg(ctx sdk.Context, keeper Keeper, msg types.EthereumTxMsg) sdk // TODO: Consume gas from sender - return sdk.Result{Log: addr.Hex(), GasUsed: msg.Data.GasLimit - leftOverGas} + return sdk.Result{Data: addr.Bytes(), GasUsed: msg.Data.GasLimit - leftOverGas} } func refundGas(