mirror of
https://github.com/fiatjaf/nak.git
synced 2024-11-25 17:19:07 -05: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
26
count.go
26
count.go
|
@ -9,8 +9,6 @@ import (
|
|||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
const CATEGORY_COUNT_ATTRIBUTES = "FILTER ATTRIBUTES"
|
||||
|
||||
var count = &cli.Command{
|
||||
Name: "count",
|
||||
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",
|
||||
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...]",
|
||||
Action: func(c *cli.Context) error {
|
||||
|
@ -118,22 +112,22 @@ var count = &cli.Command{
|
|||
filter.Limit = limit
|
||||
}
|
||||
|
||||
relays := c.Args().Slice()
|
||||
if len(relays) > 0 {
|
||||
pool := nostr.NewSimplePool(c.Context)
|
||||
for ie := range pool.SubManyEose(c.Context, relays, nostr.Filters{filter}) {
|
||||
fmt.Println(ie.Event)
|
||||
relay := c.Args().First()
|
||||
if relay != "" {
|
||||
relay, err := nostr.RelayConnect(c.Context, relay)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
count, err := relay.Count(c.Context, nostr.Filters{filter})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(count)
|
||||
} else {
|
||||
// no relays given, will just print the filter
|
||||
var result string
|
||||
if c.Bool("bare") {
|
||||
result = filter.String()
|
||||
} else {
|
||||
j, _ := json.Marshal([]any{"COUNT", "nak", filter})
|
||||
result = string(j)
|
||||
}
|
||||
|
||||
fmt.Println(result)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user