From 95bed5d5a84659d55e80992e35797e31d27b8240 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 12 Feb 2025 16:37:17 -0300 Subject: [PATCH] nak req --ids-only --- go.mod | 4 ++-- go.sum | 4 ++-- req.go | 39 +++++++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index d4264cb..beb0af0 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,8 @@ require ( github.com/mailru/easyjson v0.9.0 github.com/mark3labs/mcp-go v0.8.3 github.com/markusmobius/go-dateparser v1.2.3 - github.com/nbd-wtf/go-nostr v0.49.3 + github.com/nbd-wtf/go-nostr v0.49.7 + golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 ) require ( @@ -62,7 +63,6 @@ require ( github.com/wasilibs/go-re2 v1.3.0 // indirect github.com/x448/float16 v0.8.4 // indirect golang.org/x/crypto v0.32.0 // indirect - golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect golang.org/x/net v0.34.0 // indirect golang.org/x/sys v0.29.0 // indirect golang.org/x/text v0.21.0 // indirect diff --git a/go.sum b/go.sum index 0b1a34a..29d0121 100644 --- a/go.sum +++ b/go.sum @@ -128,8 +128,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/nbd-wtf/go-nostr v0.49.3 h1:7tsEdMZOtJ764JuMLffkbhVUi4yyf688dbqArLvItPs= -github.com/nbd-wtf/go-nostr v0.49.3/go.mod h1:M50QnhkraC5Ol93v3jqxSMm1aGxUQm5mlmkYw5DJzh8= +github.com/nbd-wtf/go-nostr v0.49.7 h1:4D9XCqjTJYqUPMuNJI27W5gaiklnTI12IzzWIAOFepE= +github.com/nbd-wtf/go-nostr v0.49.7/go.mod h1:M50QnhkraC5Ol93v3jqxSMm1aGxUQm5mlmkYw5DJzh8= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/req.go b/req.go index a5442da..3a1a4bf 100644 --- a/req.go +++ b/req.go @@ -9,6 +9,7 @@ import ( "github.com/fiatjaf/cli/v3" "github.com/mailru/easyjson" "github.com/nbd-wtf/go-nostr" + "github.com/nbd-wtf/go-nostr/nip77" ) const ( @@ -32,6 +33,10 @@ example: DisableSliceFlagSeparator: true, Flags: append(defaultKeyFlags, append(reqFilterFlags, + &cli.BoolFlag{ + Name: "ids-only", + Usage: "use nip77 to fetch just a list of ids", + }, &cli.BoolFlag{ Name: "stream", Usage: "keep the subscription open, printing all events as they are returned", @@ -121,15 +126,33 @@ example: } if len(relayUrls) > 0 { - fn := sys.Pool.SubManyEose - if c.Bool("paginate") { - fn = paginateWithParams(c.Duration("paginate-interval"), c.Uint("paginate-global-limit")) - } else if c.Bool("stream") { - fn = sys.Pool.SubMany - } + if c.Bool("ids-only") { + seen := make(map[string]struct{}, max(500, filter.Limit)) + for _, url := range relayUrls { + ch, err := nip77.FetchIDsOnly(ctx, url, filter) + if err != nil { + log("negentropy call to %s failed: %s", url, err) + continue + } + for id := range ch { + if _, ok := seen[id]; ok { + continue + } + seen[id] = struct{}{} + stdout(id) + } + } + } else { + fn := sys.Pool.SubManyEose + if c.Bool("paginate") { + fn = paginateWithParams(c.Duration("paginate-interval"), c.Uint("paginate-global-limit")) + } else if c.Bool("stream") { + fn = sys.Pool.SubMany + } - for ie := range fn(ctx, relayUrls, nostr.Filters{filter}) { - stdout(ie.Event) + for ie := range fn(ctx, relayUrls, nostr.Filters{filter}) { + stdout(ie.Event) + } } } else { // no relays given, will just print the filter