fetch: use relay hints from author pubkeys.

This commit is contained in:
fiatjaf 2023-10-15 09:22:39 -03:00
parent db157e6181
commit 459b127988
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -5,6 +5,7 @@ import (
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19" "github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/sdk"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -24,12 +25,14 @@ var fetch = &cli.Command{
} }
var relays []string var relays []string
var authorHint string
switch prefix { switch prefix {
case "nevent": case "nevent":
v := value.(nostr.EventPointer) v := value.(nostr.EventPointer)
filter.IDs = append(filter.IDs, v.ID) filter.IDs = append(filter.IDs, v.ID)
if v.Author != "" { if v.Author != "" {
// TODO fetch relays from nip65 authorHint = v.Author
} }
relays = v.Relays relays = v.Relays
case "naddr": case "naddr":
@ -37,20 +40,30 @@ var fetch = &cli.Command{
filter.Tags = nostr.TagMap{"d": []string{v.Identifier}} filter.Tags = nostr.TagMap{"d": []string{v.Identifier}}
filter.Kinds = append(filter.Kinds, v.Kind) filter.Kinds = append(filter.Kinds, v.Kind)
filter.Authors = append(filter.Authors, v.PublicKey) filter.Authors = append(filter.Authors, v.PublicKey)
// TODO fetch relays from nip65 authorHint = v.PublicKey
relays = v.Relays relays = v.Relays
case "nprofile": case "nprofile":
v := value.(nostr.ProfilePointer) v := value.(nostr.ProfilePointer)
filter.Authors = append(filter.Authors, v.PublicKey) filter.Authors = append(filter.Authors, v.PublicKey)
// TODO fetch relays from nip65 authorHint = v.PublicKey
relays = v.Relays 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 { if len(relays) == 0 {
return fmt.Errorf("no relay hints found") return fmt.Errorf("no relay hints found")
} }
pool := nostr.NewSimplePool(c.Context)
for ie := range pool.SubManyEose(c.Context, relays, nostr.Filters{filter}) { for ie := range pool.SubManyEose(c.Context, relays, nostr.Filters{filter}) {
fmt.Println(ie.Event) fmt.Println(ie.Event)
} }