From 86f56c9079b46d0ebac0b53d53f6f52789c3ec4e Mon Sep 17 00:00:00 2001 From: winsvega Date: Tue, 11 Feb 2020 10:54:05 +0100 Subject: [PATCH] cmd/geth retesteth: add eth_getBlockByHash (#20621) --- cmd/geth/retesteth.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/geth/retesteth.go b/cmd/geth/retesteth.go index 716b227fe..7a4575284 100644 --- a/cmd/geth/retesteth.go +++ b/cmd/geth/retesteth.go @@ -83,6 +83,7 @@ type RetestethEthAPI interface { SendRawTransaction(ctx context.Context, rawTx hexutil.Bytes) (common.Hash, error) BlockNumber(ctx context.Context) (uint64, error) GetBlockByNumber(ctx context.Context, blockNr math.HexOrDecimal64, fullTx bool) (map[string]interface{}, error) + GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error) GetBalance(ctx context.Context, address common.Address, blockNr math.HexOrDecimal64) (*math.HexOrDecimal256, error) GetCode(ctx context.Context, address common.Address, blockNr math.HexOrDecimal64) (hexutil.Bytes, error) GetTransactionCount(ctx context.Context, address common.Address, blockNr math.HexOrDecimal64) (uint64, error) @@ -628,6 +629,20 @@ func (api *RetestethAPI) GetBlockByNumber(_ context.Context, blockNr math.HexOrD return nil, fmt.Errorf("block %d not found", blockNr) } +func (api *RetestethAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error) { + block := api.blockchain.GetBlockByHash(blockHash) + if block != nil { + response, err := RPCMarshalBlock(block, true, fullTx) + if err != nil { + return nil, err + } + response["author"] = response["miner"] + response["totalDifficulty"] = (*hexutil.Big)(api.blockchain.GetTd(block.Hash(), block.Number().Uint64())) + return response, err + } + return nil, fmt.Errorf("block 0x%x not found", blockHash) +} + func (api *RetestethAPI) AccountRange(ctx context.Context, blockHashOrNumber *math.HexOrDecimal256, txIndex uint64, addressHash *math.HexOrDecimal256, maxResults uint64,