try to prevent pointer to pointer bug.

This commit is contained in:
fiatjaf 2025-03-10 16:16:44 -03:00
parent 769887fac1
commit 74e121075e
2 changed files with 16 additions and 2 deletions

View File

@ -16,12 +16,26 @@ func EncodePointer(pointer nostr.Pointer) string {
res, _ := EncodeProfile(v.PublicKey, v.Relays)
return res
}
case *nostr.ProfilePointer:
if v.Relays == nil {
res, _ := EncodePublicKey(v.PublicKey)
return res
} else {
res, _ := EncodeProfile(v.PublicKey, v.Relays)
return res
}
case nostr.EventPointer:
res, _ := EncodeEvent(v.ID, v.Relays, v.Author)
return res
case *nostr.EventPointer:
res, _ := EncodeEvent(v.ID, v.Relays, v.Author)
return res
case nostr.EntityPointer:
res, _ := EncodeEntity(v.PublicKey, v.Kind, v.Identifier, v.Relays)
return res
case *nostr.EntityPointer:
res, _ := EncodeEntity(v.PublicKey, v.Kind, v.Identifier, v.Relays)
return res
}
return ""
}

View File

@ -31,7 +31,7 @@ func ParseReferences(evt nostr.Event) iter.Seq[Reference] {
if prefix, data, err := nip19.Decode(nip19code); err == nil {
switch prefix {
case "npub":
pointer := &nostr.ProfilePointer{
pointer := nostr.ProfilePointer{
PublicKey: data.(string), Relays: []string{},
}
tag := evt.Tags.FindWithValue("p", pointer.PublicKey)
@ -52,7 +52,7 @@ func ParseReferences(evt nostr.Event) iter.Seq[Reference] {
}
case "note":
// we don't even bother here because people using note1 codes aren't including relay hints anyway
reference.Pointer = &nostr.EventPointer{ID: data.(string), Relays: nil}
reference.Pointer = nostr.EventPointer{ID: data.(string), Relays: nil}
case "nevent":
pointer := data.(nostr.EventPointer)
tag := evt.Tags.FindWithValue("e", pointer.ID)