Skip to content

Commit

Permalink
Merge pull request #38 from blinklabs-io/feat/filter-chainsync-stake-…
Browse files Browse the repository at this point in the history
…address

feat: filtering on stake address
  • Loading branch information
agaffney authored Jun 11, 2023
2 parents 886c845 + cf29f9a commit c764137
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,11 @@ Only output transactions with outputs matching a particular address
```bash
$ snek -filter-type chainsync.transaction -filter-address addr1qyht4ja0zcn45qvyx477qlyp6j5ftu5ng0prt9608dxp6l2j2c79gy9l76sdg0xwhd7r0c0kna0tycz4y5s6mlenh8pq4jxtdy
```

#### Filtering on a stake address

Only output transactions with outputs matching a particular stake address

```bash
$ snek -filter-type chainsync.transaction -filter-address stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz
```
18 changes: 16 additions & 2 deletions filter/chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package chainsync

import (
"strings"

"github.com/blinklabs-io/gouroboros/ledger"
"github.com/blinklabs-io/snek/event"
"github.com/blinklabs-io/snek/input/chainsync"
Expand Down Expand Up @@ -56,14 +58,26 @@ func (c *ChainSync) Start() error {
case chainsync.TransactionEvent:
// Check address filter
if c.filterAddress != "" {
isStakeAddress := false
if strings.HasPrefix(c.filterAddress, "stake") {
isStakeAddress = true
}
foundMatch := false
// TODO: extract and compare stake addresses when this is done
// https://github.com/blinklabs-io/gouroboros/issues/302
for _, output := range v.Outputs {
if output.Address().String() == c.filterAddress {
foundMatch = true
break
}
if isStakeAddress {
stakeAddr := output.Address().StakeAddress()
if stakeAddr == nil {
continue
}
if stakeAddr.String() == c.filterAddress {
foundMatch = true
break
}
}
}
if !foundMatch {
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/blinklabs-io/snek
go 1.18

require (
github.com/blinklabs-io/gouroboros v0.44.0
github.com/blinklabs-io/gouroboros v0.45.1
github.com/kelseyhightower/envconfig v1.4.0
go.uber.org/zap v1.24.0
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/blinklabs-io/gouroboros v0.44.0 h1:bvhMAqU9ZUh1WYrx8lMUj87h4QeFCXLZJaZ4bLlfxlE=
github.com/blinklabs-io/gouroboros v0.44.0/go.mod h1:YNHQqwU1yv620T5C+umkDmYf8BgBHlm6QpI9LUQ3Jhw=
github.com/blinklabs-io/gouroboros v0.45.1 h1:DhlQMeiBphuEMWn3grVAZsWO5OcM62UHsEe69+qCEnM=
github.com/blinklabs-io/gouroboros v0.45.1/go.mod h1:YNHQqwU1yv620T5C+umkDmYf8BgBHlm6QpI9LUQ3Jhw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit c764137

Please sign in to comment.