1+ // Copyright 2025 The Swarm Authors. All rights reserved.
2+ // Use of this source code is governed by a BSD-style
3+ // license that can be found in the LICENSE file.
4+
15package node
26
37import (
@@ -91,19 +95,17 @@ func (f *SnapshotBlockHeightContractFilterer) parseLogs(reader io.Reader) error
9195
9296func (f * SnapshotBlockHeightContractFilterer ) FilterLogs (ctx context.Context , query ethereum.FilterQuery ) ([]types.Log , error ) {
9397 f .logger .Debug ("filtering pre-loaded logs" , "total_logs" , len (f .loadedLogs ), "query" , query )
94-
95- var filtered []types.Log
96-
98+
99+ filtered := make ( []types.Log , 0 , len ( f . loadedLogs ))
100+
97101 for _ , log := range f .loadedLogs {
98- // Filter by block range
99102 if query .FromBlock != nil && log .BlockNumber < query .FromBlock .Uint64 () {
100103 continue
101104 }
102105 if query .ToBlock != nil && log .BlockNumber > query .ToBlock .Uint64 () {
103106 continue
104107 }
105-
106- // Filter by addresses
108+
107109 if len (query .Addresses ) > 0 {
108110 addressMatch := false
109111 for _ , addr := range query .Addresses {
@@ -116,48 +118,42 @@ func (f *SnapshotBlockHeightContractFilterer) FilterLogs(ctx context.Context, qu
116118 continue
117119 }
118120 }
119-
120- // Filter by topics
121+
121122 if len (query .Topics ) > 0 {
122123 topicMatch := true
123-
124- // We have a max of 4 topics in Ethereum logs
124+
125125 for i := 0 ; i < len (query .Topics ) && i < 4 ; i ++ {
126- // Skip if no filter for this topic position or empty filter array
127126 if i >= len (query .Topics ) || len (query .Topics [i ]) == 0 {
128127 continue
129128 }
130-
131- // If we're filtering for this topic position but log doesn't have enough topics
129+
132130 if i >= len (log .Topics ) {
133131 topicMatch = false
134132 break
135133 }
136-
137- // Check if this topic matches any in the filter array for this position
134+
138135 hasMatch := false
139136 for _ , topic := range query .Topics [i ] {
140137 if log .Topics [i ] == topic {
141138 hasMatch = true
142139 break
143140 }
144141 }
145-
142+
146143 if ! hasMatch {
147144 topicMatch = false
148145 break
149146 }
150147 }
151-
148+
152149 if ! topicMatch {
153150 continue
154151 }
155152 }
156-
157- // If we got here, log passed all filters
153+
158154 filtered = append (filtered , log )
159155 }
160-
156+
161157 f .logger .Debug ("filtered logs" , "input_count" , len (f .loadedLogs ), "output_count" , len (filtered ))
162158 return filtered , nil
163159}
0 commit comments