@@ -63,9 +63,10 @@ type SimulatedBackend struct {
6363 database ethdb.Database // In memory database to store our testing data
6464 blockchain * core.BlockChain // Ethereum blockchain to handle the consensus
6565
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
6970
7071 events * filters.EventSystem // Event system for filtering log events live
7172
@@ -84,8 +85,8 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
8485 database : database ,
8586 blockchain : blockchain ,
8687 config : genesis .Config ,
87- events : filters .NewEventSystem (& filterBackend {database , blockchain }, false ),
8888 }
89+ backend .events = filters .NewEventSystem (& filterBackend {database , blockchain , backend }, false )
8990 backend .rollback (blockchain .CurrentBlock ())
9091 return backend
9192}
@@ -662,7 +663,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
662663 return fmt .Errorf ("invalid transaction nonce: got %d, want %d" , tx .Nonce (), nonce )
663664 }
664665 // 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 ) {
666667 for _ , tx := range b .pendingBlock .Transactions () {
667668 block .AddTxWithChain (b .blockchain , tx )
668669 }
@@ -672,6 +673,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
672673
673674 b .pendingBlock = blocks [0 ]
674675 b .pendingState , _ = state .New (b .pendingBlock .Root (), stateDB .Database (), nil )
676+ b .pendingReceipts = receipts [0 ]
675677 return nil
676678}
677679
@@ -683,7 +685,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.Filter
683685 var filter * filters.Filter
684686 if query .BlockHash != nil {
685687 // 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 )
687689 } else {
688690 // Initialize unset filter boundaries to run from genesis to chain head
689691 from := int64 (0 )
@@ -695,7 +697,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.Filter
695697 to = query .ToBlock .Int64 ()
696698 }
697699 // 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 )
699701 }
700702 // Run the filter and return all the logs
701703 logs , err := filter .Logs (ctx )
@@ -819,8 +821,9 @@ func (m callMsg) FeePayer() *common.Address { return m.CallMsg.FeePayer }
819821// filterBackend implements filters.Backend to support filtering for logs without
820822// taking bloom-bits acceleration structures into account.
821823type filterBackend struct {
822- db ethdb.Database
823- bc * core.BlockChain
824+ db ethdb.Database
825+ bc * core.BlockChain
826+ backend * SimulatedBackend
824827}
825828
826829func (fb * filterBackend ) ChainDb () ethdb.Database { return fb .db }
@@ -837,6 +840,10 @@ func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*t
837840 return fb .bc .GetHeaderByHash (hash ), nil
838841}
839842
843+ func (fb * filterBackend ) PendingBlockAndReceipts () (* types.Block , types.Receipts ) {
844+ return fb .backend .pendingBlock , fb .backend .pendingReceipts
845+ }
846+
840847func (fb * filterBackend ) GetReceipts (ctx context.Context , hash common.Hash ) (types.Receipts , error ) {
841848 number := rawdb .ReadHeaderNumber (fb .db , hash )
842849 if number == nil {
0 commit comments