Implement eth_getBlockTransactionCountByHash (#116)
This commit is contained in:
parent
09a71a2a3a
commit
81fc39a9bc
@ -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.
|
||||
func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) hexutil.Uint {
|
||||
return 0
|
||||
func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Uint {
|
||||
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.
|
||||
func (e *PublicEthAPI) GetBlockTransactionCountByNumber(blockNum BlockNumber) (hexutil.Uint, error) {
|
||||
node, err := e.cliCtx.GetNode()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
func (e *PublicEthAPI) GetBlockTransactionCountByNumber(blockNum BlockNumber) *hexutil.Uint {
|
||||
height := blockNum.Int64()
|
||||
block, err := node.Block(&height)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return e.getBlockTransactionCountByNumber(height)
|
||||
}
|
||||
|
||||
return hexutil.Uint(block.Block.NumTxs), nil
|
||||
func (e *PublicEthAPI) getBlockTransactionCountByNumber(number int64) *hexutil.Uint {
|
||||
block, err := e.cliCtx.Client.Block(&number)
|
||||
if err != nil {
|
||||
// Return nil if block doesn't exist
|
||||
return nil
|
||||
}
|
||||
|
||||
n := hexutil.Uint(block.Block.NumTxs)
|
||||
return &n
|
||||
}
|
||||
|
||||
// GetUncleCountByBlockHash returns the number of uncles in the block idenfied by hash. Always zero.
|
||||
|
Loading…
Reference in New Issue
Block a user