From 1f3473595382b84588cf52471d696998eb346ec6 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Thu, 16 May 2024 12:10:55 -0400 Subject: [PATCH] feat: filter transactions for pool (de)registrations (#210) Signed-off-by: Chris Gianelloni --- filter/chainsync/chainsync.go | 49 +++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/filter/chainsync/chainsync.go b/filter/chainsync/chainsync.go index 248e531..bd2d8ab 100644 --- a/filter/chainsync/chainsync.go +++ b/filter/chainsync/chainsync.go @@ -204,9 +204,8 @@ func (c *ChainSync) Start() error { isPoolBech32 := strings.HasPrefix(filterPoolId, "pool") foundMatch := false for _, certificate := range v.Certificates { - switch certificate.(type) { + switch cert := certificate.(type) { case *ledger.StakeDelegationCertificate: - cert := &ledger.StakeDelegationCertificate{} b := &ledger.Blake2b224{} copy(b[:], cert.PoolKeyHash[:]) if b.String() == filterPoolId { @@ -229,6 +228,52 @@ func (c *ChainSync) Start() error { filterMatched = true break } + case *ledger.PoolRetirementCertificate: + b := &ledger.Blake2b224{} + copy(b[:], cert.PoolKeyHash[:]) + if b.String() == filterPoolId { + foundMatch = true + } else if isPoolBech32 { + // lifted from gouroboros/ledger + convData, err := bech32.ConvertBits(certificate.Cbor(), 8, 5, true) + if err != nil { + continue + } + encoded, err := bech32.Encode("pool", convData) + if err != nil { + continue + } + if encoded == filterPoolId { + foundMatch = true + } + } + if foundMatch { + filterMatched = true + break + } + case *ledger.PoolRegistrationCertificate: + b := &ledger.Blake2b224{} + copy(b[:], cert.Operator[:]) + if b.String() == filterPoolId { + foundMatch = true + } else if isPoolBech32 { + // lifted from gouroboros/ledger + convData, err := bech32.ConvertBits(certificate.Cbor(), 8, 5, true) + if err != nil { + continue + } + encoded, err := bech32.Encode("pool", convData) + if err != nil { + continue + } + if encoded == filterPoolId { + foundMatch = true + } + } + if foundMatch { + filterMatched = true + break + } } } if foundMatch {