Implement eth_getTransactionByBlockNumberAndIndex (#107)

* Implements eth_getTransactionByBlockNumberAndIndex

* reuse convenience function for converting bytes to eth tx
This commit is contained in:
Austin Abell 2019-09-25 09:26:42 -04:00 committed by GitHub
parent cfca4d10e6
commit 26e90e729e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -482,8 +482,25 @@ func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx h
} }
// GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index. // GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index.
func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNumber BlockNumber, idx hexutil.Uint) *Transaction { func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum BlockNumber, idx hexutil.Uint) (*Transaction, error) {
return nil 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. // GetTransactionReceipt returns the transaction receipt identified by hash.