From 862c07ec363aa668aa8672ee2838cc0861997ea9 Mon Sep 17 00:00:00 2001 From: aodhgan Date: Thu, 9 Oct 2025 16:55:23 -0700 Subject: [PATCH] use FilterReceipts, avoid circular deps --- eth/api_backend.go | 29 +++++++++++++++++++++++++++++ eth/filters/filter.go | 10 ++++------ eth/filters/filter_system.go | 2 +- internal/ethapi/api.go | 6 +++--- internal/ethapi/api_test.go | 3 +-- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index 766a99fc1e..984e6ff5f6 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -36,10 +36,12 @@ import ( "github.com/ethereum/go-ethereum/core/txpool/locals" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" ) @@ -494,3 +496,30 @@ func (b *EthAPIBackend) RPCTxSyncDefaultTimeout() time.Duration { func (b *EthAPIBackend) RPCTxSyncMaxTimeout() time.Duration { return b.eth.config.TxSyncMaxTimeout } + +func (b *EthAPIBackend) SubscribeTransactionReceipts( + txHashes []common.Hash, + out chan<- []*ethapi.ReceiptWithTx, +) event.Subscription { + ch := make(chan core.ChainEvent, 16) + sub := b.eth.blockchain.SubscribeChainEvent(ch) + + go func() { + defer sub.Unsubscribe() + for { + select { + case ev, ok := <-ch: + if !ok { + return + } + batch := filters.FilterReceipts(txHashes, ev) + if len(batch) > 0 { + out <- batch + } + case <-sub.Err(): + return + } + } + }() + return sub +} diff --git a/eth/filters/filter.go b/eth/filters/filter.go index 02399bc801..ee93a985f0 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/core/filtermaps" "github.com/ethereum/go-ethereum/core/history" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" ) @@ -554,16 +555,13 @@ func bloomFilter(bloom types.Bloom, addresses []common.Address, topics [][]commo } // ReceiptWithTx contains a receipt and its corresponding transaction -type ReceiptWithTx struct { - Receipt *types.Receipt - Transaction *types.Transaction -} +type ReceiptWithTx = ethapi.ReceiptWithTx -// filterReceipts returns the receipts matching the given criteria +// FilterReceipts returns the receipts matching the given criteria // In addition to returning receipts, it also returns the corresponding transactions. // This is because receipts only contain low-level data, while user-facing data // may require additional information from the Transaction. -func filterReceipts(txHashes []common.Hash, ev core.ChainEvent) []*ReceiptWithTx { +func FilterReceipts(txHashes []common.Hash, ev core.ChainEvent) []*ReceiptWithTx { var ret []*ReceiptWithTx receipts := ev.Receipts diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 02783fa5ec..9210dba21c 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -445,7 +445,7 @@ func (es *EventSystem) handleChainEvent(filters filterIndex, ev core.ChainEvent) // Handle transaction receipts subscriptions when a new block is added for _, f := range filters[TransactionReceiptsSubscription] { - matchedReceipts := filterReceipts(f.txHashes, ev) + matchedReceipts := FilterReceipts(f.txHashes, ev) if len(matchedReceipts) > 0 { f.receipts <- matchedReceipts } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index bb3de426fb..a3d6aebd4d 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1653,8 +1653,8 @@ func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil } type ReceiptWithTx struct { - Receipt *types.Receipt - Tx *types.Transaction + Receipt *types.Receipt + Transaction *types.Transaction } // SendRawTransactionSync will add the signed transaction to the transaction pool @@ -1729,7 +1729,7 @@ func (api *TransactionAPI) SendRawTransactionSync(ctx context.Context, input hex rwt.Receipt.BlockHash, rwt.Receipt.BlockNumber.Uint64(), api.signer, - rwt.Tx, + rwt.Transaction, int(rwt.Receipt.TransactionIndex), ), nil } diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index c6da3669a8..3105bba532 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -441,7 +441,6 @@ type testBackend struct { pending *types.Block pendingReceipts types.Receipts - // test-only fields for SendRawTransactionSync receiptsFeed *event.Feed autoMine bool @@ -624,7 +623,7 @@ func (b *testBackend) SendTx(ctx context.Context, tx *types.Transaction) error { CumulativeGasUsed: 21000, GasUsed: 21000, } - b.receiptsFeed.Send([]*ReceiptWithTx{{Receipt: r, Tx: tx}}) + b.receiptsFeed.Send([]*ReceiptWithTx{{Receipt: r, Transaction: tx}}) } return nil }