mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +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/txpool/locals"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"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/gasprice"
|
||||||
"github.com/ethereum/go-ethereum/eth/tracers"
|
"github.com/ethereum/go-ethereum/eth/tracers"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
)
|
)
|
||||||
|
|
@ -494,3 +496,30 @@ func (b *EthAPIBackend) RPCTxSyncDefaultTimeout() time.Duration {
|
||||||
func (b *EthAPIBackend) RPCTxSyncMaxTimeout() time.Duration {
|
func (b *EthAPIBackend) RPCTxSyncMaxTimeout() time.Duration {
|
||||||
return b.eth.config.TxSyncMaxTimeout
|
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/filtermaps"
|
||||||
"github.com/ethereum/go-ethereum/core/history"
|
"github.com/ethereum/go-ethereum/core/history"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"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/log"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"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
|
// ReceiptWithTx contains a receipt and its corresponding transaction
|
||||||
type ReceiptWithTx struct {
|
type ReceiptWithTx = ethapi.ReceiptWithTx
|
||||||
Receipt *types.Receipt
|
|
||||||
Transaction *types.Transaction
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
// In addition to returning receipts, it also returns the corresponding transactions.
|
||||||
// This is because receipts only contain low-level data, while user-facing data
|
// This is because receipts only contain low-level data, while user-facing data
|
||||||
// may require additional information from the Transaction.
|
// 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
|
var ret []*ReceiptWithTx
|
||||||
|
|
||||||
receipts := ev.Receipts
|
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
|
// Handle transaction receipts subscriptions when a new block is added
|
||||||
for _, f := range filters[TransactionReceiptsSubscription] {
|
for _, f := range filters[TransactionReceiptsSubscription] {
|
||||||
matchedReceipts := filterReceipts(f.txHashes, ev)
|
matchedReceipts := FilterReceipts(f.txHashes, ev)
|
||||||
if len(matchedReceipts) > 0 {
|
if len(matchedReceipts) > 0 {
|
||||||
f.receipts <- matchedReceipts
|
f.receipts <- matchedReceipts
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1653,8 +1653,8 @@ func (api *TransactionAPI) SendRawTransaction(ctx context.Context, input hexutil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReceiptWithTx struct {
|
type ReceiptWithTx struct {
|
||||||
Receipt *types.Receipt
|
Receipt *types.Receipt
|
||||||
Tx *types.Transaction
|
Transaction *types.Transaction
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendRawTransactionSync will add the signed transaction to the transaction pool
|
// 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.BlockHash,
|
||||||
rwt.Receipt.BlockNumber.Uint64(),
|
rwt.Receipt.BlockNumber.Uint64(),
|
||||||
api.signer,
|
api.signer,
|
||||||
rwt.Tx,
|
rwt.Transaction,
|
||||||
int(rwt.Receipt.TransactionIndex),
|
int(rwt.Receipt.TransactionIndex),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -441,7 +441,6 @@ type testBackend struct {
|
||||||
pending *types.Block
|
pending *types.Block
|
||||||
pendingReceipts types.Receipts
|
pendingReceipts types.Receipts
|
||||||
|
|
||||||
// test-only fields for SendRawTransactionSync
|
|
||||||
receiptsFeed *event.Feed
|
receiptsFeed *event.Feed
|
||||||
autoMine bool
|
autoMine bool
|
||||||
|
|
||||||
|
|
@ -624,7 +623,7 @@ func (b *testBackend) SendTx(ctx context.Context, tx *types.Transaction) error {
|
||||||
CumulativeGasUsed: 21000,
|
CumulativeGasUsed: 21000,
|
||||||
GasUsed: 21000,
|
GasUsed: 21000,
|
||||||
}
|
}
|
||||||
b.receiptsFeed.Send([]*ReceiptWithTx{{Receipt: r, Tx: tx}})
|
b.receiptsFeed.Send([]*ReceiptWithTx{{Receipt: r, Transaction: tx}})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue