@ -347,48 +347,47 @@ func (f *Filter) pendingLogs() []*types.Log {
return nil
}
func includes ( addresses [ ] common . Address , a common . Address ) bool {
for _ , addr := range addresses {
if addr == a {
// includes returns true if the element is present in the list.
func includes [ T comparable ] ( things [ ] T , element T ) bool {
for _ , thing := range things {
if thing == element {
return true
}
}
return false
}
// filterLogs creates a slice of logs matching the given criteria.
func filterLogs ( logs [ ] * types . Log , fromBlock , toBlock * big . Int , addresses [ ] common . Address , topics [ ] [ ] common . Hash ) [ ] * types . Log {
var ret [ ] * types . Log
Logs :
for _ , log := range logs {
var check = func ( log * types . Log ) bool {
if fromBlock != nil && fromBlock . Int64 ( ) >= 0 && fromBlock . Uint64 ( ) > log . BlockNumber {
continu e
return false
}
if toBlock != nil && toBlock . Int64 ( ) >= 0 && toBlock . Uint64 ( ) < log . BlockNumber {
continu e
return fals e
}
if len ( addresses ) > 0 && ! includes ( addresses , log . Address ) {
continu e
return fals e
}
// If the to filtered topics is greater than the amount of topics in logs, skip.
if len ( topics ) > len ( log . Topics ) {
continu e
return fals e
}
for i , sub := range topics {
match := len ( sub ) == 0 // empty rule set == wildcard
for _ , topic := range sub {
if log . Topics [ i ] == topic {
match = true
break
}
if len ( sub ) == 0 {
continue // empty rule set == wildcard
}
if ! match {
continue Logs
if ! includes ( sub , log . Topics [ i ] ) {
return false
}
}
ret = append ( ret , log )
return true
}
var ret [ ] * types . Log
for _ , log := range logs {
if check ( log ) {
ret = append ( ret , log )
}
}
return ret
}