Implements gettransactionbyblockhashandindex (#115)

This commit is contained in:
Austin Abell 2019-09-29 16:46:10 -04:00 committed by GitHub
parent 81fc39a9bc
commit 1119c650c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -516,14 +516,25 @@ func (e *PublicEthAPI) GetTransactionByHash(hash common.Hash) (*Transaction, err
} }
// GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index. // GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index.
func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexutil.Uint) *Transaction { func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexutil.Uint) (*Transaction, error) {
return nil 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. // GetTransactionByBlockNumberAndIndex returns the transaction identified by number and index.
func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum BlockNumber, idx hexutil.Uint) (*Transaction, error) { func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum BlockNumber, idx hexutil.Uint) (*Transaction, error) {
value := blockNum.Int64() 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 { if err != nil {
return nil, err return nil, err
} }