@@ -144,22 +144,32 @@ func (b BlockChains) TonChains() map[uint64]ton.Chain {
144
144
type ChainSelectorsOption func (* chainSelectorsOptions )
145
145
146
146
type chainSelectorsOptions struct {
147
- family string
148
- excluding []uint64
147
+ // Use map for faster lookups
148
+ includedFamilies map [string ]struct {}
149
+ excludedChainSels map [uint64 ]struct {}
149
150
}
150
151
151
152
// WithFamily returns an option to filter chains by family (evm, solana, aptos)
152
153
// Use constants from chain_selectors package eg WithFamily(chain_selectors.FamilySolana)
154
+ // This can be used more than once to include multiple families.
153
155
func WithFamily (family string ) ChainSelectorsOption {
154
156
return func (o * chainSelectorsOptions ) {
155
- o .family = family
157
+ if o .includedFamilies == nil {
158
+ o .includedFamilies = make (map [string ]struct {})
159
+ }
160
+ o .includedFamilies [family ] = struct {}{}
156
161
}
157
162
}
158
163
159
164
// WithChainSelectorsExclusion returns an option to exclude specific chain selectors
160
165
func WithChainSelectorsExclusion (chainSelectors []uint64 ) ChainSelectorsOption {
161
166
return func (o * chainSelectorsOptions ) {
162
- o .excluding = chainSelectors
167
+ if o .excludedChainSels == nil {
168
+ o .excludedChainSels = make (map [uint64 ]struct {})
169
+ }
170
+ for _ , selector := range chainSelectors {
171
+ o .excludedChainSels [selector ] = struct {}{}
172
+ }
163
173
}
164
174
}
165
175
@@ -168,11 +178,7 @@ func WithChainSelectorsExclusion(chainSelectors []uint64) ChainSelectorsOption {
168
178
// - WithFamily: filter by family eg WithFamily(chain_selectors.FamilySolana)
169
179
// - WithChainSelectorsExclusion: exclude specific chain selectors
170
180
func (b BlockChains ) ListChainSelectors (options ... ChainSelectorsOption ) []uint64 {
171
- // Initialize default options
172
- opts := chainSelectorsOptions {
173
- family : "" ,
174
- excluding : []uint64 {},
175
- }
181
+ opts := chainSelectorsOptions {}
176
182
177
183
// Apply all provided options
178
184
for _ , option := range options {
@@ -182,14 +188,13 @@ func (b BlockChains) ListChainSelectors(options ...ChainSelectorsOption) []uint6
182
188
selectors := make ([]uint64 , 0 , len (b .chains ))
183
189
184
190
for selector , chain := range b .chains {
185
- // Skip if in exclusion list
186
- if slices .Contains (opts .excluding , selector ) {
187
- continue
191
+ if opts .excludedChainSels != nil {
192
+ if _ , excluded := opts .excludedChainSels [selector ]; excluded {
193
+ continue
194
+ }
188
195
}
189
-
190
- // Apply family filter if specified
191
- if opts .family != "" {
192
- if opts .family != chain .Family () {
196
+ if opts .includedFamilies != nil {
197
+ if _ , ok := opts .includedFamilies [chain .Family ()]; ! ok {
193
198
continue
194
199
}
195
200
}
0 commit comments