forked from cerc-io/laconicd-deprecated
Implement eth_getTransactionByBlockNumberAndIndex (#107)
* Implements eth_getTransactionByBlockNumberAndIndex * reuse convenience function for converting bytes to eth tx
This commit is contained in:
parent
cfca4d10e6
commit
26e90e729e
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user