From 1119c650c6f8f6e662ae88dcc99a9435f47efd15 Mon Sep 17 00:00:00 2001 From: Austin Abell Date: Sun, 29 Sep 2019 16:46:10 -0400 Subject: [PATCH] Implements gettransactionbyblockhashandindex (#115) --- rpc/eth_api.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rpc/eth_api.go b/rpc/eth_api.go index de15e99a0..94e29c598 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -516,14 +516,25 @@ func (e *PublicEthAPI) GetTransactionByHash(hash common.Hash) (*Transaction, err } // GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index. -func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexutil.Uint) *Transaction { - return nil +func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexutil.Uint) (*Transaction, error) { + res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryHashToHeight, hash.Hex())) + if err != nil { + return nil, err + } + + var out types.QueryResBlockNumber + e.cliCtx.Codec.MustUnmarshalJSON(res, &out) + return e.getTransactionByBlockNumberAndIndex(out.Number, idx) } // GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index. func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum BlockNumber, idx hexutil.Uint) (*Transaction, error) { value := blockNum.Int64() - block, err := e.cliCtx.Client.Block(&value) + return e.getTransactionByBlockNumberAndIndex(value, idx) +} + +func (e *PublicEthAPI) getTransactionByBlockNumberAndIndex(number int64, idx hexutil.Uint) (*Transaction, error) { + block, err := e.cliCtx.Client.Block(&number) if err != nil { return nil, err }