Skip to content

Commit dcffb77

Browse files
authored
cmd/geth retesteth: add eth_getBlockByHash (#20621)
1 parent 8694d14 commit dcffb77

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmd/geth/retesteth.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type RetestethEthAPI interface {
8080
SendRawTransaction(ctx context.Context, rawTx hexutil.Bytes) (common.Hash, error)
8181
BlockNumber(ctx context.Context) (uint64, error)
8282
GetBlockByNumber(ctx context.Context, blockNr math.HexOrDecimal64, fullTx bool) (map[string]interface{}, error)
83+
GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error)
8384
GetBalance(ctx context.Context, address common.Address, blockNr math.HexOrDecimal64) (*math.HexOrDecimal256, error)
8485
GetCode(ctx context.Context, address common.Address, blockNr math.HexOrDecimal64) (hexutil.Bytes, error)
8586
GetTransactionCount(ctx context.Context, address common.Address, blockNr math.HexOrDecimal64) (uint64, error)
@@ -618,6 +619,20 @@ func (api *RetestethAPI) GetBlockByNumber(ctx context.Context, blockNr math.HexO
618619
return nil, fmt.Errorf("block %d not found", blockNr)
619620
}
620621

622+
func (api *RetestethAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fullTx bool) (map[string]interface{}, error) {
623+
block := api.blockchain.GetBlockByHash(blockHash)
624+
if block != nil {
625+
response, err := RPCMarshalBlock(block, true, fullTx)
626+
if err != nil {
627+
return nil, err
628+
}
629+
response["author"] = response["miner"]
630+
response["totalDifficulty"] = (*hexutil.Big)(api.blockchain.GetTd(block.Hash(), block.Number().Uint64()))
631+
return response, err
632+
}
633+
return nil, fmt.Errorf("block 0x%x not found", blockHash)
634+
}
635+
621636
func (api *RetestethAPI) AccountRange(ctx context.Context,
622637
blockHashOrNumber *math.HexOrDecimal256, txIndex uint64,
623638
addressHash *math.HexOrDecimal256, maxResults uint64,

0 commit comments

Comments
 (0)