mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
use FilterReceipts, avoid circular deps
This commit is contained in:
parent
3d083d02fd
commit
862c07ec36
5 changed files with 38 additions and 12 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue