@@ -444,92 +444,10 @@ func (es *EventSystem) handleChainEvent(filters filterIndex, ev core.ChainEvent)
444444 }
445445
446446 // Handle transaction receipts subscriptions when a new block is added
447- es .handleReceiptsEvent (filters , ev )
448- }
449-
450- // ReceiptWithTx contains a receipt and its corresponding transaction for websocket subscription
451- type ReceiptWithTx struct {
452- Receipt * types.Receipt
453- Transaction * types.Transaction
454- }
455-
456- func (es * EventSystem ) handleReceiptsEvent (filters filterIndex , ev core.ChainEvent ) {
457- // If there are no transaction receipt subscriptions, skip processing
458- if len (filters [TransactionReceiptsSubscription ]) == 0 {
459- return
460- }
461-
462- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
463- defer cancel ()
464-
465- // Get receipts for this block
466- receipts , err := es .backend .GetReceipts (ctx , ev .Header .Hash ())
467- if err != nil {
468- log .Warn ("Failed to get receipts for block" , "hash" , ev .Header .Hash (), "err" , err )
469- return
470- }
471-
472- // Get body to retrieve transactions
473- body , err := es .backend .GetBody (ctx , ev .Header .Hash (), rpc .BlockNumber (ev .Header .Number .Int64 ()))
474- if err != nil {
475- log .Warn ("Failed to get block for receipts" , "hash" , ev .Header .Hash (), "err" , err )
476- return
477- }
478-
479- txs := body .Transactions
480- if len (txs ) != len (receipts ) {
481- log .Warn ("Transaction count mismatch" , "txs" , len (txs ), "receipts" , len (receipts ))
482- return
483- }
484-
485447 for _ , f := range filters [TransactionReceiptsSubscription ] {
486- var filteredReceipts []* ReceiptWithTx
487-
488- if len (f .txHashes ) == 0 {
489- // No filter, send all receipts with their transactions.
490- filteredReceipts = make ([]* ReceiptWithTx , len (receipts ))
491- for i , receipt := range receipts {
492- filteredReceipts [i ] = & ReceiptWithTx {
493- Receipt : receipt ,
494- Transaction : txs [i ],
495- }
496- }
497- } else if len (f .txHashes ) == 1 {
498- // Filter by single transaction hash.
499- // This is a common case, so we distinguish it from filtering by multiple tx hashes and made a small optimization.
500- for i , receipt := range receipts {
501- if receipt .TxHash == f .txHashes [0 ] {
502- filteredReceipts = append (filteredReceipts , & ReceiptWithTx {
503- Receipt : receipt ,
504- Transaction : txs [i ],
505- })
506- break
507- }
508- }
509- } else {
510- // Filter by multiple transaction hashes.
511- txHashMap := make (map [common.Hash ]bool , len (f .txHashes ))
512- for _ , hash := range f .txHashes {
513- txHashMap [hash ] = true
514- }
515-
516- for i , receipt := range receipts {
517- if txHashMap [receipt .TxHash ] {
518- filteredReceipts = append (filteredReceipts , & ReceiptWithTx {
519- Receipt : receipt ,
520- Transaction : txs [i ],
521- })
522-
523- // Early exit if all receipts are found
524- if len (filteredReceipts ) == len (f .txHashes ) {
525- break
526- }
527- }
528- }
529- }
530-
531- if len (filteredReceipts ) > 0 {
532- f .receipts <- filteredReceipts
448+ matchedReceipts := filterReceipts (f .txHashes , ev )
449+ if len (matchedReceipts ) > 0 {
450+ f .receipts <- matchedReceipts
533451 }
534452 }
535453}
0 commit comments