From ac089bf557eabcc1ea2fa4417523ae24a58f122d Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Wed, 29 May 2019 23:56:55 -0700 Subject: [PATCH] hmy_blockNumber (#910) --- internal/hmyapi/README.md | 2 +- internal/hmyapi/blockchain.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/hmyapi/README.md b/internal/hmyapi/README.md index 8e33d8b8c..acd84eecc 100644 --- a/internal/hmyapi/README.md +++ b/internal/hmyapi/README.md @@ -14,7 +14,7 @@ ### BlockChain info related * [ ] hmy_gasPrice - return min-gas-price * [ ] hmy_estimateGas - calculating estimate gas using signed bytes -* [ ] hmy_blockNumber - get latest block number +* [x] hmy_blockNumber - get latest block number * [x] hmy_getBlockByHash - get block by block hash * [x] hmy_getBlockByNumber * [ ] hmy_getUncleByBlockHashAndIndex - get uncle by block hash and index number diff --git a/internal/hmyapi/blockchain.go b/internal/hmyapi/blockchain.go index 820df6097..372f6e313 100644 --- a/internal/hmyapi/blockchain.go +++ b/internal/hmyapi/blockchain.go @@ -78,3 +78,9 @@ func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Add } return (*hexutil.Big)(state.GetBalance(address)), state.Error() } + +// BlockNumber returns the block number of the chain head. +func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 { + header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available + return hexutil.Uint64(header.Number.Uint64()) +}