Skip to content
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