From ae7d834bc752a2d94fef9d354ee78fcb9425f3d1 Mon Sep 17 00:00:00 2001 From: Ryan Schneider Date: Sat, 14 May 2022 13:33:41 -0700 Subject: [PATCH] internal/ethapi: add debug_getRawReceipts RPC method (#24773) Adds a method to retrieve all the binary encoded receipts from a block --- internal/ethapi/api.go | 27 +++++++++++++++++++++++++++ internal/web3ext/web3ext.go | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 82531bef7..fc08fdb91 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1874,6 +1874,33 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexu return rlp.EncodeToBytes(block) } +// GetRawReceipts retrieves the binary-encoded raw receipts of a single block. +func (api *PublicDebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) { + var hash common.Hash + if h, ok := blockNrOrHash.Hash(); ok { + hash = h + } else { + block, err := api.b.BlockByNumberOrHash(ctx, blockNrOrHash) + if err != nil { + return nil, err + } + hash = block.Hash() + } + receipts, err := api.b.GetReceipts(ctx, hash) + if err != nil { + return nil, err + } + result := make([]hexutil.Bytes, len(receipts)) + for i, receipt := range receipts { + b, err := receipt.MarshalBinary() + if err != nil { + return nil, err + } + result[i] = b + } + return result, nil +} + // PrintBlock retrieves a block and returns its pretty printed form. func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) { block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index c8c4d4e40..d0e54a1c5 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -233,6 +233,11 @@ web3._extend({ call: 'debug_getBlockRlp', params: 1 }), + new web3._extend.Method({ + name: 'getRawReceipts', + call: 'debug_getRawReceipts', + params: 1 + }), new web3._extend.Method({ name: 'setHead', call: 'debug_setHead',