@@ -61,9 +61,10 @@ type SimulatedBackend struct {
6161 database ethdb.Database // In memory database to store our testing data
6262 blockchain * core.BlockChain // Ethereum blockchain to handle the consensus
6363
64- mu sync.Mutex
65- pendingBlock * types.Block // Currently pending block that will be imported on request
66- pendingState * state.StateDB // Currently pending state that will be the active on on request
64+ mu sync.Mutex
65+ pendingBlock * types.Block // Currently pending block that will be imported on request
66+ pendingState * state.StateDB // Currently pending state that will be the active on request
67+ pendingReceipts types.Receipts // Currently receipts for the pending block
6768
6869 events * filters.EventSystem // Event system for filtering log events live
6970
@@ -126,8 +127,8 @@ func NewXDCSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64, chainConfi
126127 database : database ,
127128 blockchain : blockchain ,
128129 config : genesis .Config ,
129- events : filters .NewEventSystem (& filterBackend {database , blockchain }, false ),
130130 }
131+ backend .events = filters .NewEventSystem (& filterBackend {database , blockchain , backend }, false )
131132 blockchain .Client = backend
132133 backend .rollback ()
133134 return backend
@@ -146,8 +147,8 @@ func NewSimulatedBackend(alloc core.GenesisAlloc) *SimulatedBackend {
146147 database : database ,
147148 blockchain : blockchain ,
148149 config : genesis .Config ,
149- events : filters .NewEventSystem (& filterBackend {database , blockchain }, false ),
150150 }
151+ backend .events = filters .NewEventSystem (& filterBackend {database , blockchain , backend }, false )
151152 backend .rollback ()
152153 return backend
153154}
@@ -400,7 +401,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
400401 }
401402
402403 // Include tx in chain.
403- blocks , _ := core .GenerateChain (b .config , block , b .blockchain .Engine (), b .database , 1 , func (number int , block * core.BlockGen ) {
404+ blocks , receipts := core .GenerateChain (b .config , block , b .blockchain .Engine (), b .database , 1 , func (number int , block * core.BlockGen ) {
404405 for _ , tx := range b .pendingBlock .Transactions () {
405406 block .AddTxWithChain (b .blockchain , tx )
406407 }
@@ -410,6 +411,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
410411
411412 b .pendingBlock = blocks [0 ]
412413 b .pendingState , _ = state .New (b .pendingBlock .Root (), statedb .Database ())
414+ b .pendingReceipts = receipts [0 ]
413415 return nil
414416}
415417
@@ -421,7 +423,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query XDPoSChain.Filt
421423 var filter * filters.Filter
422424 if query .BlockHash != nil {
423425 // Block filter requested, construct a single-shot filter
424- filter = filters .NewBlockFilter (& filterBackend {b .database , b .blockchain }, * query .BlockHash , query .Addresses , query .Topics )
426+ filter = filters .NewBlockFilter (& filterBackend {b .database , b .blockchain , b }, * query .BlockHash , query .Addresses , query .Topics )
425427 } else {
426428 // Initialize unset filter boundaried to run from genesis to chain head
427429 from := int64 (0 )
@@ -433,7 +435,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query XDPoSChain.Filt
433435 to = query .ToBlock .Int64 ()
434436 }
435437 // Construct the range filter
436- filter = filters .NewRangeFilter (& filterBackend {b .database , b .blockchain }, from , to , query .Addresses , query .Topics )
438+ filter = filters .NewRangeFilter (& filterBackend {b .database , b .blockchain , b }, from , to , query .Addresses , query .Topics )
437439 }
438440 // Run the filter and return all the logs
439441 logs , err := filter .Logs (ctx )
@@ -523,8 +525,9 @@ func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
523525// filterBackend implements filters.Backend to support filtering for logs without
524526// taking bloom-bits acceleration structures into account.
525527type filterBackend struct {
526- db ethdb.Database
527- bc * core.BlockChain
528+ db ethdb.Database
529+ bc * core.BlockChain
530+ backend * SimulatedBackend
528531}
529532
530533func (fb * filterBackend ) ChainDb () ethdb.Database { return fb .db }
@@ -545,6 +548,10 @@ func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
545548 return core .GetBlockReceipts (fb .db , hash , core .GetBlockNumber (fb .db , hash )), nil
546549}
547550
551+ func (fb * filterBackend ) PendingBlockAndReceipts () (* types.Block , types.Receipts ) {
552+ return fb .backend .pendingBlock , fb .backend .pendingReceipts
553+ }
554+
548555func (fb * filterBackend ) GetLogs (ctx context.Context , hash common.Hash ) ([][]* types.Log , error ) {
549556 receipts := core .GetBlockReceipts (fb .db , hash , core .GetBlockNumber (fb .db , hash ))
550557 if receipts == nil {
0 commit comments