From 87eb51646865e789b73d9adbae9f3dbb17a240ba Mon Sep 17 00:00:00 2001 From: austinabell Date: Fri, 30 Aug 2019 16:08:22 -0400 Subject: [PATCH 1/2] Implements eth_getBlockTransactionCountByNumber --- rpc/eth_api.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rpc/eth_api.go b/rpc/eth_api.go index affa731cc..2c3985c85 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -115,7 +115,12 @@ func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) hexutil. // GetBlockTransactionCountByNumber returns the number of transactions in the block identified by number. func (e *PublicEthAPI) GetBlockTransactionCountByNumber(blockNum rpc.BlockNumber) hexutil.Uint { - return 0 + node, _ := e.cliCtx.GetNode() + + height := blockNum.Int64() + block, _ := node.Block(&height) + + return hexutil.Uint(block.Block.NumTxs) } // GetUncleCountByBlockHash returns the number of uncles in the block idenfied by hash. Always zero. From 9f87238da434881b5905cabba0de15a79337a53f Mon Sep 17 00:00:00 2001 From: austinabell Date: Fri, 30 Aug 2019 16:42:37 -0400 Subject: [PATCH 2/2] Added error handling for getting block at height --- rpc/eth_api.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rpc/eth_api.go b/rpc/eth_api.go index 2c3985c85..6068b15d9 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -114,13 +114,19 @@ func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) hexutil. } // GetBlockTransactionCountByNumber returns the number of transactions in the block identified by number. -func (e *PublicEthAPI) GetBlockTransactionCountByNumber(blockNum rpc.BlockNumber) hexutil.Uint { - node, _ := e.cliCtx.GetNode() +func (e *PublicEthAPI) GetBlockTransactionCountByNumber(blockNum rpc.BlockNumber) (hexutil.Uint, error) { + node, err := e.cliCtx.GetNode() + if err != nil { + return 0, err + } height := blockNum.Int64() - block, _ := node.Block(&height) + block, err := node.Block(&height) + if err != nil { + return 0, err + } - return hexutil.Uint(block.Block.NumTxs) + return hexutil.Uint(block.Block.NumTxs), nil } // GetUncleCountByBlockHash returns the number of uncles in the block idenfied by hash. Always zero.