@@ -206,12 +206,12 @@ func (s *PublicFilterAPI) newLogFilter(earliest, latest int64, addresses []commo
206206 filter .SetEndBlock (latest )
207207 filter .SetAddresses (addresses )
208208 filter .SetTopics (topics )
209- filter .LogsCallback = func (logs vm.Logs ) {
209+ filter .LogCallback = func (log * vm.Log , removed bool ) {
210210 s .logMu .Lock ()
211211 defer s .logMu .Unlock ()
212212
213213 if queue := s .logQueue [id ]; queue != nil {
214- queue .add (logs ... )
214+ queue .add (vmlog { log , removed } )
215215 }
216216 }
217217
@@ -365,14 +365,14 @@ func (s *PublicFilterAPI) NewFilter(args NewFilterArgs) (string, error) {
365365}
366366
367367// GetLogs returns the logs matching the given argument.
368- func (s * PublicFilterAPI ) GetLogs (args NewFilterArgs ) vm. Logs {
368+ func (s * PublicFilterAPI ) GetLogs (args NewFilterArgs ) [] vmlog {
369369 filter := New (s .chainDb )
370370 filter .SetBeginBlock (args .FromBlock .Int64 ())
371371 filter .SetEndBlock (args .ToBlock .Int64 ())
372372 filter .SetAddresses (args .Addresses )
373373 filter .SetTopics (args .Topics )
374374
375- return returnLogs (filter .Find ())
375+ return toRPCLogs (filter .Find (), false )
376376}
377377
378378// UninstallFilter removes the filter with the given filter id.
@@ -447,7 +447,7 @@ func (s *PublicFilterAPI) transactionFilterChanged(id int) []common.Hash {
447447}
448448
449449// logFilterChanged returns a collection of logs for the log filter with the given id.
450- func (s * PublicFilterAPI ) logFilterChanged (id int ) vm. Logs {
450+ func (s * PublicFilterAPI ) logFilterChanged (id int ) [] vmlog {
451451 s .logMu .Lock ()
452452 defer s .logMu .Unlock ()
453453
@@ -458,17 +458,17 @@ func (s *PublicFilterAPI) logFilterChanged(id int) vm.Logs {
458458}
459459
460460// GetFilterLogs returns the logs for the filter with the given id.
461- func (s * PublicFilterAPI ) GetFilterLogs (filterId string ) vm. Logs {
461+ func (s * PublicFilterAPI ) GetFilterLogs (filterId string ) [] vmlog {
462462 id , ok := s .filterMapping [filterId ]
463463 if ! ok {
464- return returnLogs (nil )
464+ return toRPCLogs (nil , false )
465465 }
466466
467467 if filter := s .filterManager .Get (id ); filter != nil {
468- return returnLogs (filter .Find ())
468+ return toRPCLogs (filter .Find (), false )
469469 }
470470
471- return returnLogs (nil )
471+ return toRPCLogs (nil , false )
472472}
473473
474474// GetFilterChanges returns the logs for the filter with the given id since last time is was called.
@@ -488,28 +488,33 @@ func (s *PublicFilterAPI) GetFilterChanges(filterId string) interface{} {
488488 case transactionFilterTy :
489489 return returnHashes (s .transactionFilterChanged (id ))
490490 case logFilterTy :
491- return returnLogs ( s .logFilterChanged (id ) )
491+ return s .logFilterChanged (id )
492492 }
493493
494494 return []interface {}{}
495495}
496496
497+ type vmlog struct {
498+ * vm.Log
499+ Removed bool `json:"removed"`
500+ }
501+
497502type logQueue struct {
498503 mu sync.Mutex
499504
500- logs vm. Logs
505+ logs [] vmlog
501506 timeout time.Time
502507 id int
503508}
504509
505- func (l * logQueue ) add (logs ... * vm. Log ) {
510+ func (l * logQueue ) add (logs ... vmlog ) {
506511 l .mu .Lock ()
507512 defer l .mu .Unlock ()
508513
509514 l .logs = append (l .logs , logs ... )
510515}
511516
512- func (l * logQueue ) get () vm. Logs {
517+ func (l * logQueue ) get () [] vmlog {
513518 l .mu .Lock ()
514519 defer l .mu .Unlock ()
515520
@@ -556,13 +561,16 @@ func newFilterId() (string, error) {
556561 return "0x" + hex .EncodeToString (subid [:]), nil
557562}
558563
559- // returnLogs is a helper that will return an empty logs array case the given logs is nil, otherwise is will return the
560- // given logs. The RPC interfaces defines that always an array is returned.
561- func returnLogs (logs vm.Logs ) vm.Logs {
562- if logs == nil {
563- return vm.Logs {}
564+ // toRPCLogs is a helper that will convert a vm.Logs array to an structure which
565+ // can hold additional information about the logs such as whether it was deleted.
566+ // Additionally when nil is given it will by default instead create an empty slice
567+ // instead. This is required by the RPC specification.
568+ func toRPCLogs (logs vm.Logs , removed bool ) []vmlog {
569+ convertedLogs := make ([]vmlog , len (logs ))
570+ for i , log := range logs {
571+ convertedLogs [i ] = vmlog {Log : log , Removed : removed }
564572 }
565- return logs
573+ return convertedLogs
566574}
567575
568576// returnHashes is a helper that will return an empty hash array case the given hash array is nil, otherwise is will
0 commit comments