Skip to content

eth, internal: add debug_getBlockReceipts #23277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,30 @@ func (api *PrivateDebugAPI) getModifiedAccounts(startBlock, endBlock *types.Bloc
}
return dirty, nil
}

// GetBlockReceipts returns all transaction receipts of the specified block.
func (api *PrivateDebugAPI) GetBlockReceipts(ctx context.Context, blockHash common.Hash) ([]map[string]interface{}, error) {
block := api.eth.blockchain.GetBlockByHash(blockHash)
if block == nil {
return nil, errors.New("block not found")
}
receipts := api.eth.blockchain.GetReceiptsByHash(blockHash)
if receipts == nil {
return nil, errors.New("receipts not found")
}
txs := block.Transactions()
if len(txs) != len(receipts) {
return nil, fmt.Errorf("txs length doesn't equal to receipts' length")
}
txReceipts := make([]map[string]interface{}, 0, len(txs))
blockNumber := block.Header().Number
for idx, receipt := range receipts {
tx := txs[idx]
fields, err := ethapi.ToTransactionReceipt(ctx, api.eth.APIBackend, tx, receipt, blockHash, tx.Hash(), blockNumber.Uint64(), uint64(idx))
if err != nil {
return nil, err
}
txReceipts = append(txReceipts, fields)
}
return txReceipts, nil
}
10 changes: 7 additions & 3 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1600,9 +1600,13 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
}
receipt := receipts[index]

return ToTransactionReceipt(ctx, s.b, tx, receipt, blockHash, hash, blockNumber, index)
}

func ToTransactionReceipt(ctx context.Context, b Backend, tx *types.Transaction, receipt *types.Receipt, blockHash common.Hash, hash common.Hash, blockNumber uint64, index uint64) (map[string]interface{}, error) {
// Derive the sender.
bigblock := new(big.Int).SetUint64(blockNumber)
signer := types.MakeSigner(s.b.ChainConfig(), bigblock)
signer := types.MakeSigner(b.ChainConfig(), bigblock)
from, _ := types.Sender(signer, tx)

fields := map[string]interface{}{
Expand All @@ -1620,10 +1624,10 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
"type": hexutil.Uint(tx.Type()),
}
// Assign the effective gas price paid
if !s.b.ChainConfig().IsLondon(bigblock) {
if !b.ChainConfig().IsLondon(bigblock) {
fields["effectiveGasPrice"] = hexutil.Uint64(tx.GasPrice().Uint64())
} else {
header, err := s.b.HeaderByHash(ctx, blockHash)
header, err := b.HeaderByHash(ctx, blockHash)
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ web3._extend({
call: 'debug_freezeClient',
params: 1,
}),
new web3._extend.Method({
name: 'getBlockReceipts',
call: 'debug_getBlockReceipts',
params: 1,
inputFormatter: [null],
}),
],
properties: []
});
Expand Down