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
This commit is contained in:
Austin Abell 2019-09-25 14:38:33 -04:00 committed by GitHub
parent 26e90e729e
commit 6cfeb6e754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 3 deletions

View File

@ -504,8 +504,56 @@ func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum BlockNumber,
} }
// GetTransactionReceipt returns the transaction receipt identified by hash. // GetTransactionReceipt returns the transaction receipt identified by hash.
func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) map[string]interface{} { func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]interface{}, error) {
return nil 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. // GetUncleByBlockHashAndIndex returns the uncle identified by hash and index. Always returns nil.

View File

@ -106,7 +106,7 @@ func handleETHTxMsg(ctx sdk.Context, keeper Keeper, msg types.EthereumTxMsg) sdk
// TODO: Consume gas from sender // 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( func refundGas(