1
- // Copyright 2023 Blink Labs Software
1
+ // Copyright 2024 Blink Labs Software
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -18,11 +18,12 @@ import (
18
18
"encoding/hex"
19
19
"strings"
20
20
21
+ "github.com/blinklabs-io/gouroboros/bech32"
22
+ "github.com/blinklabs-io/gouroboros/ledger"
23
+
21
24
"github.com/blinklabs-io/adder/event"
22
25
"github.com/blinklabs-io/adder/input/chainsync"
23
26
"github.com/blinklabs-io/adder/plugin"
24
- "github.com/blinklabs-io/gouroboros/bech32"
25
- "github.com/blinklabs-io/gouroboros/ledger"
26
27
)
27
28
28
29
type ChainSync struct {
@@ -193,6 +194,53 @@ func (c *ChainSync) Start() error {
193
194
continue
194
195
}
195
196
}
197
+ // Check pool filter
198
+ if len (c .filterPoolIds ) > 0 {
199
+ filterMatched := false
200
+ for _ , filterPoolId := range c .filterPoolIds {
201
+ if filterMatched {
202
+ break
203
+ }
204
+ isPoolBech32 := strings .HasPrefix (filterPoolId , "pool" )
205
+ foundMatch := false
206
+ for _ , certificate := range v .Certificates {
207
+ switch certificate .(type ) {
208
+ case * ledger.StakeDelegationCertificate :
209
+ cert := & ledger.StakeDelegationCertificate {}
210
+ b := & ledger.Blake2b224 {}
211
+ copy (b [:], cert .PoolKeyHash [:])
212
+ if b .String () == filterPoolId {
213
+ foundMatch = true
214
+ } else if isPoolBech32 {
215
+ // lifted from gouroboros/ledger
216
+ convData , err := bech32 .ConvertBits (certificate .Cbor (), 8 , 5 , true )
217
+ if err != nil {
218
+ continue
219
+ }
220
+ encoded , err := bech32 .Encode ("pool" , convData )
221
+ if err != nil {
222
+ continue
223
+ }
224
+ if encoded == filterPoolId {
225
+ foundMatch = true
226
+ }
227
+ }
228
+ if foundMatch {
229
+ filterMatched = true
230
+ break
231
+ }
232
+ }
233
+ }
234
+ if foundMatch {
235
+ filterMatched = true
236
+ break
237
+ }
238
+ }
239
+ // Skip the event if none of the filter values matched
240
+ if ! filterMatched {
241
+ continue
242
+ }
243
+ }
196
244
}
197
245
c .outputChan <- evt
198
246
}
0 commit comments