Skip to content

Commit

Permalink
feat: filter transactions for pool (de)registrations (#210)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored May 16, 2024
1 parent 084b3be commit 1f34735
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions filter/chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 1f34735

Please sign in to comment.