Skip to content

Commit 56720e4

Browse files
author
ian
committed
eth, internal: add debug_getBlockReceipts
1 parent bbfa648 commit 56720e4

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

eth/api.go

+27
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,30 @@ func (api *PrivateDebugAPI) getModifiedAccounts(startBlock, endBlock *types.Bloc
545545
}
546546
return dirty, nil
547547
}
548+
549+
// GetBlockReceipts returns all transaction receipts of the specified block.
550+
func (api *PrivateDebugAPI) GetBlockReceipts(ctx context.Context, blockHash common.Hash) ([]map[string]interface{}, error) {
551+
block := api.eth.blockchain.GetBlockByHash(blockHash)
552+
if block == nil {
553+
return nil, errors.New("block not found")
554+
}
555+
receipts := api.eth.blockchain.GetReceiptsByHash(blockHash)
556+
if receipts == nil {
557+
return nil, errors.New("receipts not found")
558+
}
559+
txs := block.Transactions()
560+
if len(txs) != len(receipts) {
561+
return nil, fmt.Errorf("txs length doesn't equal to receipts' length")
562+
}
563+
txReceipts := make([]map[string]interface{}, 0, len(txs))
564+
blockNumber := block.Header().Number
565+
for idx, receipt := range receipts {
566+
tx := txs[idx]
567+
fields, err := ethapi.ToTransactionReceipt(ctx, api.eth.APIBackend, tx, receipt, blockHash, tx.Hash(), blockNumber.Uint64(), uint64(idx))
568+
if err != nil {
569+
return nil, err
570+
}
571+
txReceipts = append(txReceipts, fields)
572+
}
573+
return txReceipts, nil
574+
}

internal/ethapi/api.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1600,9 +1600,13 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
16001600
}
16011601
receipt := receipts[index]
16021602

1603+
return ToTransactionReceipt(ctx, s.b, tx, receipt, blockHash, hash, blockNumber, index)
1604+
}
1605+
1606+
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) {
16031607
// Derive the sender.
16041608
bigblock := new(big.Int).SetUint64(blockNumber)
1605-
signer := types.MakeSigner(s.b.ChainConfig(), bigblock)
1609+
signer := types.MakeSigner(b.ChainConfig(), bigblock)
16061610
from, _ := types.Sender(signer, tx)
16071611

16081612
fields := map[string]interface{}{
@@ -1620,10 +1624,10 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
16201624
"type": hexutil.Uint(tx.Type()),
16211625
}
16221626
// Assign the effective gas price paid
1623-
if !s.b.ChainConfig().IsLondon(bigblock) {
1627+
if !b.ChainConfig().IsLondon(bigblock) {
16241628
fields["effectiveGasPrice"] = hexutil.Uint64(tx.GasPrice().Uint64())
16251629
} else {
1626-
header, err := s.b.HeaderByHash(ctx, blockHash)
1630+
header, err := b.HeaderByHash(ctx, blockHash)
16271631
if err != nil {
16281632
return nil, err
16291633
}

internal/web3ext/web3ext.go

+6
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ web3._extend({
453453
call: 'debug_freezeClient',
454454
params: 1,
455455
}),
456+
new web3._extend.Method({
457+
name: 'getBlockReceipts',
458+
call: 'debug_getBlockReceipts',
459+
params: 1,
460+
inputFormatter: [null],
461+
}),
456462
],
457463
properties: []
458464
});

0 commit comments

Comments
 (0)