@@ -8,58 +8,22 @@ import (
88 "github.com/onflow/flow-evm-gateway/storage"
99 "github.com/onflow/go-ethereum/common"
1010 gethTypes "github.com/onflow/go-ethereum/core/types"
11+ "github.com/onflow/go-ethereum/eth/filters"
1112)
1213
13- // The maximum number of topic criteria allowed
14- const maxTopics = 4
15-
16- // The maximum number of addresses allowed
17- const maxAddresses = 6
18-
19- // FilterCriteria for log filtering.
20- // Address of the contract emitting the log.
21- // Topics that match the log topics, following the format:
22- // [] “anything”
23- // [A] “A in first position (and anything after)”
24- // [null, B] “anything in first position AND B in second position (and anything after)”
25- // [A, B] “A in first position AND B in second position (and anything after)”
26- // [[A, B], [A, B]] “(A OR B) in first position AND (A OR B) in second position (and anything after)”
27- type FilterCriteria struct {
28- Addresses []common.Address
29- Topics [][]common.Hash
30- }
31-
32- func NewFilterCriteria (addresses []common.Address , topics [][]common.Hash ) (* FilterCriteria , error ) {
33- if len (topics ) > maxTopics {
34- return nil , fmt .Errorf ("max topics exceeded, only %d allowed, got %d" , maxTopics , len (topics ))
35- }
36- if len (addresses ) > maxAddresses {
37- return nil , fmt .Errorf ("max addresses exceeded, only %d allowed, got %d" , maxAddresses , len (addresses ))
38- }
39-
40- return & FilterCriteria {
41- Addresses : addresses ,
42- Topics : topics ,
43- }, nil
44- }
45-
4614// RangeFilter matches all the indexed logs within the range defined as
4715// start and end block height. The start must be strictly smaller or equal than end value.
4816type RangeFilter struct {
4917 start , end uint64
50- criteria * FilterCriteria
18+ criteria filters. FilterCriteria
5119 receipts storage.ReceiptIndexer
5220}
5321
5422func NewRangeFilter (
5523 start , end uint64 ,
56- criteria FilterCriteria ,
24+ criteria filters. FilterCriteria ,
5725 receipts storage.ReceiptIndexer ,
5826) (* RangeFilter , error ) {
59- if len (criteria .Topics ) > maxTopics {
60- return nil , fmt .Errorf ("max topics exceeded, only %d allowed, got %d" , maxTopics , len (criteria .Topics ))
61- }
62-
6327 // make sure that beginning number is not bigger than end
6428 if start > end {
6529 return nil , fmt .Errorf (
@@ -73,7 +37,7 @@ func NewRangeFilter(
7337 return & RangeFilter {
7438 start : start ,
7539 end : end ,
76- criteria : & criteria ,
40+ criteria : criteria ,
7741 receipts : receipts ,
7842 }, nil
7943}
@@ -126,24 +90,23 @@ func (r *RangeFilter) Match() ([]*gethTypes.Log, error) {
12690// by the provided block ID.
12791type IDFilter struct {
12892 id common.Hash
129- criteria * FilterCriteria
93+ criteria filters. FilterCriteria
13094 blocks storage.BlockIndexer
13195 receipts storage.ReceiptIndexer
13296}
13397
13498func NewIDFilter (
135- id common.Hash ,
136- criteria FilterCriteria ,
99+ criteria filters.FilterCriteria ,
137100 blocks storage.BlockIndexer ,
138101 receipts storage.ReceiptIndexer ,
139102) (* IDFilter , error ) {
140- if len ( criteria .Topics ) > maxTopics {
141- return nil , fmt .Errorf ("max topics exceeded, only %d allowed, got %d" , maxTopics , len ( criteria . Topics ) )
103+ if criteria .BlockHash == nil {
104+ return nil , fmt .Errorf ("filter criteria should have a non-nil block hash" )
142105 }
143106
144107 return & IDFilter {
145- id : id ,
146- criteria : & criteria ,
108+ id : * criteria . BlockHash ,
109+ criteria : criteria ,
147110 blocks : blocks ,
148111 receipts : receipts ,
149112 }, nil
@@ -173,7 +136,7 @@ func (i *IDFilter) Match() ([]*gethTypes.Log, error) {
173136}
174137
175138// ExactMatch checks the topic and address values of the log match the filter exactly.
176- func ExactMatch (log * gethTypes.Log , criteria * FilterCriteria ) bool {
139+ func ExactMatch (log * gethTypes.Log , criteria filters. FilterCriteria ) bool {
177140 // check criteria doesn't have more topics than the log, but it can have less due to wildcards
178141 if len (criteria .Topics ) > len (log .Topics ) {
179142 return false
@@ -203,7 +166,7 @@ func ExactMatch(log *gethTypes.Log, criteria *FilterCriteria) bool {
203166// If true is returned we should further check against the exactMatch to really make sure the log is matched.
204167//
205168// source: https://github.com/ethereum/go-ethereum/blob/8d1db1601d3a9e4fd067558a49db6f0b879c9b48/eth/filters/filter.go#L395
206- func bloomMatch (bloom gethTypes.Bloom , criteria * FilterCriteria ) bool {
169+ func bloomMatch (bloom gethTypes.Bloom , criteria filters. FilterCriteria ) bool {
207170 if len (criteria .Addresses ) > 0 {
208171 var included bool
209172 for _ , addr := range criteria .Addresses {
0 commit comments