diff --git a/fetch.go b/fetch.go index 36e866d..e6dc299 100644 --- a/fetch.go +++ b/fetch.go @@ -5,6 +5,7 @@ import ( "github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr/nip19" + "github.com/nbd-wtf/go-nostr/sdk" "github.com/urfave/cli/v2" ) @@ -24,12 +25,14 @@ var fetch = &cli.Command{ } var relays []string + var authorHint string + switch prefix { case "nevent": v := value.(nostr.EventPointer) filter.IDs = append(filter.IDs, v.ID) if v.Author != "" { - // TODO fetch relays from nip65 + authorHint = v.Author } relays = v.Relays case "naddr": @@ -37,20 +40,30 @@ var fetch = &cli.Command{ filter.Tags = nostr.TagMap{"d": []string{v.Identifier}} filter.Kinds = append(filter.Kinds, v.Kind) filter.Authors = append(filter.Authors, v.PublicKey) - // TODO fetch relays from nip65 + authorHint = v.PublicKey relays = v.Relays case "nprofile": v := value.(nostr.ProfilePointer) filter.Authors = append(filter.Authors, v.PublicKey) - // TODO fetch relays from nip65 + authorHint = v.PublicKey relays = v.Relays } + pool := nostr.NewSimplePool(c.Context) + if authorHint != "" { + relayList := sdk.FetchRelaysForPubkey(c.Context, pool, authorHint, + "wss://purplepag.es", "wss://offchain.pub", "wss://public.relaying.io") + for _, relayListItem := range relayList { + if relayListItem.Outbox { + relays = append(relays, relayListItem.URL) + } + } + } + if len(relays) == 0 { return fmt.Errorf("no relay hints found") } - pool := nostr.NewSimplePool(c.Context) for ie := range pool.SubManyEose(c.Context, relays, nostr.Filters{filter}) { fmt.Println(ie.Event) }