Implement eth_getBlockTransactionCountByHash (#116)

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

View File

@ -172,24 +172,33 @@ func (e *PublicEthAPI) GetTransactionCount(address common.Address, blockNum Bloc
} }
// GetBlockTransactionCountByHash returns the number of transactions in the block identified by hash. // GetBlockTransactionCountByHash returns the number of transactions in the block identified by hash.
func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) hexutil.Uint { func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Uint {
return 0 res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryHashToHeight, hash.Hex()))
if err != nil {
// Return nil if block does not exist
return nil
}
var out types.QueryResBlockNumber
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
return e.getBlockTransactionCountByNumber(out.Number)
} }
// GetBlockTransactionCountByNumber returns the number of transactions in the block identified by number. // GetBlockTransactionCountByNumber returns the number of transactions in the block identified by number.
func (e *PublicEthAPI) GetBlockTransactionCountByNumber(blockNum BlockNumber) (hexutil.Uint, error) { func (e *PublicEthAPI) GetBlockTransactionCountByNumber(blockNum BlockNumber) *hexutil.Uint {
node, err := e.cliCtx.GetNode()
if err != nil {
return 0, err
}
height := blockNum.Int64() height := blockNum.Int64()
block, err := node.Block(&height) return e.getBlockTransactionCountByNumber(height)
}
func (e *PublicEthAPI) getBlockTransactionCountByNumber(number int64) *hexutil.Uint {
block, err := e.cliCtx.Client.Block(&number)
if err != nil { if err != nil {
return 0, err // Return nil if block doesn't exist
return nil
} }
return hexutil.Uint(block.Block.NumTxs), nil n := hexutil.Uint(block.Block.NumTxs)
return &n
} }
// GetUncleCountByBlockHash returns the number of uncles in the block idenfied by hash. Always zero. // GetUncleCountByBlockHash returns the number of uncles in the block idenfied by hash. Always zero.