mirror of
https://github.com/fiatjaf/nak.git
synced 2024-10-30 00:59:07 -04:00
fix count again, it was sending REQs instead of COUNTs to relays. only use the first relay.
This commit is contained in:
parent
3896ef323b
commit
e4a9b3ccc7
30
count.go
30
count.go
|
@ -9,8 +9,6 @@ import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CATEGORY_COUNT_ATTRIBUTES = "FILTER ATTRIBUTES"
|
|
||||||
|
|
||||||
var count = &cli.Command{
|
var count = &cli.Command{
|
||||||
Name: "count",
|
Name: "count",
|
||||||
Usage: "generates encoded COUNT messages and optionally use them to talk to relays",
|
Usage: "generates encoded COUNT messages and optionally use them to talk to relays",
|
||||||
|
@ -62,10 +60,6 @@ var count = &cli.Command{
|
||||||
Usage: "only accept up to this number of events",
|
Usage: "only accept up to this number of events",
|
||||||
Category: CATEGORY_FILTER_ATTRIBUTES,
|
Category: CATEGORY_FILTER_ATTRIBUTES,
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "bare",
|
|
||||||
Usage: "when printing the filter, print just the filter, not enveloped in a [\"COUNT\", ...] array",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
ArgsUsage: "[relay...]",
|
ArgsUsage: "[relay...]",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
@ -118,22 +112,22 @@ var count = &cli.Command{
|
||||||
filter.Limit = limit
|
filter.Limit = limit
|
||||||
}
|
}
|
||||||
|
|
||||||
relays := c.Args().Slice()
|
relay := c.Args().First()
|
||||||
if len(relays) > 0 {
|
if relay != "" {
|
||||||
pool := nostr.NewSimplePool(c.Context)
|
relay, err := nostr.RelayConnect(c.Context, relay)
|
||||||
for ie := range pool.SubManyEose(c.Context, relays, nostr.Filters{filter}) {
|
if err != nil {
|
||||||
fmt.Println(ie.Event)
|
return err
|
||||||
}
|
}
|
||||||
|
count, err := relay.Count(c.Context, nostr.Filters{filter})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(count)
|
||||||
} else {
|
} else {
|
||||||
// no relays given, will just print the filter
|
// no relays given, will just print the filter
|
||||||
var result string
|
var result string
|
||||||
if c.Bool("bare") {
|
j, _ := json.Marshal([]any{"COUNT", "nak", filter})
|
||||||
result = filter.String()
|
result = string(j)
|
||||||
} else {
|
|
||||||
j, _ := json.Marshal([]any{"COUNT", "nak", filter})
|
|
||||||
result = string(j)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(result)
|
fmt.Println(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user