From 26e90e729e68a2e07b0358df6a1dd4d55abb67c8 Mon Sep 17 00:00:00 2001 From: Austin Abell Date: Wed, 25 Sep 2019 09:26:42 -0400 Subject: [PATCH] Implement eth_getTransactionByBlockNumberAndIndex (#107) * Implements eth_getTransactionByBlockNumberAndIndex * reuse convenience function for converting bytes to eth tx --- rpc/eth_api.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/rpc/eth_api.go b/rpc/eth_api.go index e782a52c..b2fc247b 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -482,8 +482,25 @@ func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx h } // GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index. -func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNumber BlockNumber, idx hexutil.Uint) *Transaction { - return nil +func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum BlockNumber, idx hexutil.Uint) (*Transaction, error) { + value := blockNum.Int64() + block, err := e.cliCtx.Client.Block(&value) + if err != nil { + return nil, err + } + header := block.BlockMeta.Header + + txs := block.Block.Txs + if uint64(idx) >= uint64(len(txs)) { + return nil, nil + } + ethTx, err := bytesToEthTx(e.cliCtx, txs[idx]) + if err != nil { + return nil, err + } + + transaction := newRPCTransaction(ethTx, common.BytesToHash(header.ConsensusHash.Bytes()), uint64(header.Height), uint64(idx)) + return transaction, nil } // GetTransactionReceipt returns the transaction receipt identified by hash.