@@ -63,9 +63,10 @@ type SimulatedBackend struct {
63
63
database ethdb.Database // In memory database to store our testing data
64
64
blockchain * core.BlockChain // Ethereum blockchain to handle the consensus
65
65
66
- mu sync.Mutex
67
- pendingBlock * types.Block // Currently pending block that will be imported on request
68
- pendingState * state.StateDB // Currently pending state that will be the active on request
66
+ mu sync.Mutex
67
+ pendingBlock * types.Block // Currently pending block that will be imported on request
68
+ pendingState * state.StateDB // Currently pending state that will be the active on request
69
+ pendingReceipts types.Receipts // Currently receipts for the pending block
69
70
70
71
events * filters.EventSystem // Event system for filtering log events live
71
72
@@ -84,8 +85,8 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
84
85
database : database ,
85
86
blockchain : blockchain ,
86
87
config : genesis .Config ,
87
- events : filters .NewEventSystem (& filterBackend {database , blockchain }, false ),
88
88
}
89
+ backend .events = filters .NewEventSystem (& filterBackend {database , blockchain , backend }, false )
89
90
backend .rollback (blockchain .CurrentBlock ())
90
91
return backend
91
92
}
@@ -662,7 +663,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
662
663
return fmt .Errorf ("invalid transaction nonce: got %d, want %d" , tx .Nonce (), nonce )
663
664
}
664
665
// Include tx in chain
665
- blocks , _ := core .GenerateChain (b .config , block , ethash .NewFaker (), b .database , 1 , func (number int , block * core.BlockGen ) {
666
+ blocks , receipts := core .GenerateChain (b .config , block , ethash .NewFaker (), b .database , 1 , func (number int , block * core.BlockGen ) {
666
667
for _ , tx := range b .pendingBlock .Transactions () {
667
668
block .AddTxWithChain (b .blockchain , tx )
668
669
}
@@ -672,6 +673,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
672
673
673
674
b .pendingBlock = blocks [0 ]
674
675
b .pendingState , _ = state .New (b .pendingBlock .Root (), stateDB .Database (), nil )
676
+ b .pendingReceipts = receipts [0 ]
675
677
return nil
676
678
}
677
679
@@ -683,7 +685,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.Filter
683
685
var filter * filters.Filter
684
686
if query .BlockHash != nil {
685
687
// Block filter requested, construct a single-shot filter
686
- filter = filters .NewBlockFilter (& filterBackend {b .database , b .blockchain }, * query .BlockHash , query .Addresses , query .Topics )
688
+ filter = filters .NewBlockFilter (& filterBackend {b .database , b .blockchain , b }, * query .BlockHash , query .Addresses , query .Topics )
687
689
} else {
688
690
// Initialize unset filter boundaries to run from genesis to chain head
689
691
from := int64 (0 )
@@ -695,7 +697,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.Filter
695
697
to = query .ToBlock .Int64 ()
696
698
}
697
699
// Construct the range filter
698
- filter = filters .NewRangeFilter (& filterBackend {b .database , b .blockchain }, from , to , query .Addresses , query .Topics )
700
+ filter = filters .NewRangeFilter (& filterBackend {b .database , b .blockchain , b }, from , to , query .Addresses , query .Topics )
699
701
}
700
702
// Run the filter and return all the logs
701
703
logs , err := filter .Logs (ctx )
@@ -816,8 +818,9 @@ func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
816
818
// filterBackend implements filters.Backend to support filtering for logs without
817
819
// taking bloom-bits acceleration structures into account.
818
820
type filterBackend struct {
819
- db ethdb.Database
820
- bc * core.BlockChain
821
+ db ethdb.Database
822
+ bc * core.BlockChain
823
+ backend * SimulatedBackend
821
824
}
822
825
823
826
func (fb * filterBackend ) ChainDb () ethdb.Database { return fb .db }
@@ -834,6 +837,10 @@ func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*t
834
837
return fb .bc .GetHeaderByHash (hash ), nil
835
838
}
836
839
840
+ func (fb * filterBackend ) PendingBlockAndReceipts () (* types.Block , types.Receipts ) {
841
+ return fb .backend .pendingBlock , fb .backend .pendingReceipts
842
+ }
843
+
837
844
func (fb * filterBackend ) GetReceipts (ctx context.Context , hash common.Hash ) (types.Receipts , error ) {
838
845
number := rawdb .ReadHeaderNumber (fb .db , hash )
839
846
if number == nil {
0 commit comments