Skip to content

Commit 1f34735

Browse files
authored
feat: filter transactions for pool (de)registrations (#210)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 084b3be commit 1f34735

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

filter/chainsync/chainsync.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ func (c *ChainSync) Start() error {
204204
isPoolBech32 := strings.HasPrefix(filterPoolId, "pool")
205205
foundMatch := false
206206
for _, certificate := range v.Certificates {
207-
switch certificate.(type) {
207+
switch cert := certificate.(type) {
208208
case *ledger.StakeDelegationCertificate:
209-
cert := &ledger.StakeDelegationCertificate{}
210209
b := &ledger.Blake2b224{}
211210
copy(b[:], cert.PoolKeyHash[:])
212211
if b.String() == filterPoolId {
@@ -229,6 +228,52 @@ func (c *ChainSync) Start() error {
229228
filterMatched = true
230229
break
231230
}
231+
case *ledger.PoolRetirementCertificate:
232+
b := &ledger.Blake2b224{}
233+
copy(b[:], cert.PoolKeyHash[:])
234+
if b.String() == filterPoolId {
235+
foundMatch = true
236+
} else if isPoolBech32 {
237+
// lifted from gouroboros/ledger
238+
convData, err := bech32.ConvertBits(certificate.Cbor(), 8, 5, true)
239+
if err != nil {
240+
continue
241+
}
242+
encoded, err := bech32.Encode("pool", convData)
243+
if err != nil {
244+
continue
245+
}
246+
if encoded == filterPoolId {
247+
foundMatch = true
248+
}
249+
}
250+
if foundMatch {
251+
filterMatched = true
252+
break
253+
}
254+
case *ledger.PoolRegistrationCertificate:
255+
b := &ledger.Blake2b224{}
256+
copy(b[:], cert.Operator[:])
257+
if b.String() == filterPoolId {
258+
foundMatch = true
259+
} else if isPoolBech32 {
260+
// lifted from gouroboros/ledger
261+
convData, err := bech32.ConvertBits(certificate.Cbor(), 8, 5, true)
262+
if err != nil {
263+
continue
264+
}
265+
encoded, err := bech32.Encode("pool", convData)
266+
if err != nil {
267+
continue
268+
}
269+
if encoded == filterPoolId {
270+
foundMatch = true
271+
}
272+
}
273+
if foundMatch {
274+
filterMatched = true
275+
break
276+
}
232277
}
233278
}
234279
if foundMatch {

0 commit comments

Comments
 (0)