Skip to content

Commit cf29f9a

Browse files
committed
feat: filtering on stake address
Fixes #37
1 parent 886c845 commit cf29f9a

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,11 @@ Only output transactions with outputs matching a particular address
203203
```bash
204204
$ snek -filter-type chainsync.transaction -filter-address addr1qyht4ja0zcn45qvyx477qlyp6j5ftu5ng0prt9608dxp6l2j2c79gy9l76sdg0xwhd7r0c0kna0tycz4y5s6mlenh8pq4jxtdy
205205
```
206+
207+
#### Filtering on a stake address
208+
209+
Only output transactions with outputs matching a particular stake address
210+
211+
```bash
212+
$ snek -filter-type chainsync.transaction -filter-address stake1u9f9v0z5zzlldgx58n8tklphu8mf7h4jvp2j2gddluemnssjfnkzz
213+
```

filter/chainsync/chainsync.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package chainsync
1616

1717
import (
18+
"strings"
19+
1820
"github.com/blinklabs-io/gouroboros/ledger"
1921
"github.com/blinklabs-io/snek/event"
2022
"github.com/blinklabs-io/snek/input/chainsync"
@@ -56,14 +58,26 @@ func (c *ChainSync) Start() error {
5658
case chainsync.TransactionEvent:
5759
// Check address filter
5860
if c.filterAddress != "" {
61+
isStakeAddress := false
62+
if strings.HasPrefix(c.filterAddress, "stake") {
63+
isStakeAddress = true
64+
}
5965
foundMatch := false
60-
// TODO: extract and compare stake addresses when this is done
61-
// https://github.com/blinklabs-io/gouroboros/issues/302
6266
for _, output := range v.Outputs {
6367
if output.Address().String() == c.filterAddress {
6468
foundMatch = true
6569
break
6670
}
71+
if isStakeAddress {
72+
stakeAddr := output.Address().StakeAddress()
73+
if stakeAddr == nil {
74+
continue
75+
}
76+
if stakeAddr.String() == c.filterAddress {
77+
foundMatch = true
78+
break
79+
}
80+
}
6781
}
6882
if !foundMatch {
6983
continue

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/blinklabs-io/snek
33
go 1.18
44

55
require (
6-
github.com/blinklabs-io/gouroboros v0.44.0
6+
github.com/blinklabs-io/gouroboros v0.45.1
77
github.com/kelseyhightower/envconfig v1.4.0
88
go.uber.org/zap v1.24.0
99
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
2-
github.com/blinklabs-io/gouroboros v0.44.0 h1:bvhMAqU9ZUh1WYrx8lMUj87h4QeFCXLZJaZ4bLlfxlE=
3-
github.com/blinklabs-io/gouroboros v0.44.0/go.mod h1:YNHQqwU1yv620T5C+umkDmYf8BgBHlm6QpI9LUQ3Jhw=
2+
github.com/blinklabs-io/gouroboros v0.45.1 h1:DhlQMeiBphuEMWn3grVAZsWO5OcM62UHsEe69+qCEnM=
3+
github.com/blinklabs-io/gouroboros v0.45.1/go.mod h1:YNHQqwU1yv620T5C+umkDmYf8BgBHlm6QpI9LUQ3Jhw=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
66
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

0 commit comments

Comments
 (0)