@@ -158,6 +158,8 @@ const (
158158 PendingTransactionsSubscription
159159 // BlocksSubscription queries hashes for blocks that are imported
160160 BlocksSubscription
161+ // TransactionReceiptsSubscription queries for transaction receipts when transactions are included in blocks
162+ TransactionReceiptsSubscription
161163 // LastIndexSubscription keeps track of the last index
162164 LastIndexSubscription
163165)
@@ -182,6 +184,8 @@ type subscription struct {
182184 logs chan []* types.Log
183185 txs chan []* types.Transaction
184186 headers chan * types.Header
187+ receipts chan []* ReceiptWithTx
188+ txHashes []common.Hash // contains transaction hashes for transactionReceipts subscription filtering
185189 installed chan struct {} // closed when the filter is installed
186190 err chan error // closed when the filter is uninstalled
187191}
@@ -268,6 +272,7 @@ func (sub *Subscription) Unsubscribe() {
268272 case <- sub .f .logs :
269273 case <- sub .f .txs :
270274 case <- sub .f .headers :
275+ case <- sub .f .receipts :
271276 }
272277 }
273278
@@ -353,6 +358,7 @@ func (es *EventSystem) subscribeLogs(crit ethereum.FilterQuery, logs chan []*typ
353358 logs : logs ,
354359 txs : make (chan []* types.Transaction ),
355360 headers : make (chan * types.Header ),
361+ receipts : make (chan []* ReceiptWithTx ),
356362 installed : make (chan struct {}),
357363 err : make (chan error ),
358364 }
@@ -369,6 +375,7 @@ func (es *EventSystem) SubscribeNewHeads(headers chan *types.Header) *Subscripti
369375 logs : make (chan []* types.Log ),
370376 txs : make (chan []* types.Transaction ),
371377 headers : headers ,
378+ receipts : make (chan []* ReceiptWithTx ),
372379 installed : make (chan struct {}),
373380 err : make (chan error ),
374381 }
@@ -385,6 +392,26 @@ func (es *EventSystem) SubscribePendingTxs(txs chan []*types.Transaction) *Subsc
385392 logs : make (chan []* types.Log ),
386393 txs : txs ,
387394 headers : make (chan * types.Header ),
395+ receipts : make (chan []* ReceiptWithTx ),
396+ installed : make (chan struct {}),
397+ err : make (chan error ),
398+ }
399+ return es .subscribe (sub )
400+ }
401+
402+ // SubscribeTransactionReceipts creates a subscription that writes transaction receipts for
403+ // transactions when they are included in blocks. If txHashes is provided, only receipts
404+ // for those specific transaction hashes will be delivered.
405+ func (es * EventSystem ) SubscribeTransactionReceipts (txHashes []common.Hash , receipts chan []* ReceiptWithTx ) * Subscription {
406+ sub := & subscription {
407+ id : rpc .NewID (),
408+ typ : TransactionReceiptsSubscription ,
409+ created : time .Now (),
410+ logs : make (chan []* types.Log ),
411+ txs : make (chan []* types.Transaction ),
412+ headers : make (chan * types.Header ),
413+ receipts : receipts ,
414+ txHashes : txHashes ,
388415 installed : make (chan struct {}),
389416 err : make (chan error ),
390417 }
@@ -415,6 +442,14 @@ func (es *EventSystem) handleChainEvent(filters filterIndex, ev core.ChainEvent)
415442 for _ , f := range filters [BlocksSubscription ] {
416443 f .headers <- ev .Header
417444 }
445+
446+ // Handle transaction receipts subscriptions when a new block is added
447+ for _ , f := range filters [TransactionReceiptsSubscription ] {
448+ matchedReceipts := filterReceipts (f .txHashes , ev )
449+ if len (matchedReceipts ) > 0 {
450+ f .receipts <- matchedReceipts
451+ }
452+ }
418453}
419454
420455// eventLoop (un)installs filters and processes mux events.
0 commit comments