Skip to content

Commit ae7d834

Browse files
internal/ethapi: add debug_getRawReceipts RPC method (#24773)
Adds a method to retrieve all the binary encoded receipts from a block
1 parent 440c9fc commit ae7d834

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

internal/ethapi/api.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,33 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (hexu
18741874
return rlp.EncodeToBytes(block)
18751875
}
18761876

1877+
// GetRawReceipts retrieves the binary-encoded raw receipts of a single block.
1878+
func (api *PublicDebugAPI) GetRawReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]hexutil.Bytes, error) {
1879+
var hash common.Hash
1880+
if h, ok := blockNrOrHash.Hash(); ok {
1881+
hash = h
1882+
} else {
1883+
block, err := api.b.BlockByNumberOrHash(ctx, blockNrOrHash)
1884+
if err != nil {
1885+
return nil, err
1886+
}
1887+
hash = block.Hash()
1888+
}
1889+
receipts, err := api.b.GetReceipts(ctx, hash)
1890+
if err != nil {
1891+
return nil, err
1892+
}
1893+
result := make([]hexutil.Bytes, len(receipts))
1894+
for i, receipt := range receipts {
1895+
b, err := receipt.MarshalBinary()
1896+
if err != nil {
1897+
return nil, err
1898+
}
1899+
result[i] = b
1900+
}
1901+
return result, nil
1902+
}
1903+
18771904
// PrintBlock retrieves a block and returns its pretty printed form.
18781905
func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) {
18791906
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))

internal/web3ext/web3ext.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ web3._extend({
233233
call: 'debug_getBlockRlp',
234234
params: 1
235235
}),
236+
new web3._extend.Method({
237+
name: 'getRawReceipts',
238+
call: 'debug_getRawReceipts',
239+
params: 1
240+
}),
236241
new web3._extend.Method({
237242
name: 'setHead',
238243
call: 'debug_setHead',

0 commit comments

Comments
 (0)