forked from cerc-io/laconicd-deprecated
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:
parent
26e90e729e
commit
6cfeb6e754
@ -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.
|
||||||
|
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user