Skip to content

Commit 104d41e

Browse files
committed
Improve performance of eth_getBlockReceipts endpoints by fetching all the receipts of a given block
1 parent 63ade51 commit 104d41e

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

api/api.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,25 @@ func (b *BlockChainAPI) GetBlockReceipts(
445445
return handleError[[]map[string]any](err, l, b.collector)
446446
}
447447

448-
receipts := make([]map[string]any, len(block.TransactionHashes))
449-
for i, hash := range block.TransactionHashes {
450-
tx, err := b.transactions.Get(hash)
451-
if err != nil {
452-
return handleError[[]map[string]any](err, l, b.collector)
453-
}
448+
receipts, err := b.receipts.GetByBlockHeight(block.Height)
449+
if err != nil {
450+
return handleError[[]map[string]any](err, l, b.collector)
451+
}
454452

455-
receipt, err := b.receipts.GetByTransactionID(hash)
453+
marshaledReceipts := make([]map[string]any, len(receipts))
454+
for i, receipt := range receipts {
455+
tx, err := b.transactions.Get(receipt.TxHash)
456456
if err != nil {
457457
return handleError[[]map[string]any](err, l, b.collector)
458458
}
459459

460-
receipts[i], err = ethTypes.MarshalReceipt(receipt, tx)
460+
marshaledReceipts[i], err = ethTypes.MarshalReceipt(receipt, tx)
461461
if err != nil {
462462
return handleError[[]map[string]any](err, l, b.collector)
463463
}
464464
}
465465

466-
return receipts, nil
466+
return marshaledReceipts, nil
467467
}
468468

469469
// GetBlockTransactionCountByHash returns the number of transactions

0 commit comments

Comments
 (0)