Skip to content

Commit

Permalink
internal/ethapi: add debug_getRawReceipts RPC method (ethereum#24773)
Browse files Browse the repository at this point in the history
Adds a method to retrieve all the binary encoded receipts from a block
  • Loading branch information
ryanschneider authored and cp-wjhan committed Dec 1, 2022
1 parent 36631fc commit a1eefdd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,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))
Expand Down
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,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',
Expand Down

0 comments on commit a1eefdd

Please sign in to comment.