commit b30d0c01db1a3afa2d06674620167fd4a4926981
parent e8d63768c152c00da0f87efed77d22081caca283
Author: William Casarin <jb55@jb55.com>
Date: Tue, 11 Apr 2023 12:44:56 -0700
nip19: allow empty relays in nprofile and nevent
Diffstat:
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/damus-c/nostr_bech32.c b/damus-c/nostr_bech32.c
@@ -135,7 +135,7 @@ static int tlvs_to_relays(struct nostr_tlvs *tlvs, struct relays *relays) {
str->end = (const char*)(tlv->value + tlv->len);
}
- return relays->num_relays > 0;
+ return 1;
}
static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *nevent) {
diff --git a/damus/Models/Mentions.swift b/damus/Models/Mentions.swift
@@ -349,7 +349,10 @@ func convert_mention_bech32_block(_ b: mention_bech32_block) -> Block?
case NOSTR_BECH32_NEVENT:
let nevent = b.bech32.data.nevent;
let event_id = hex_encode(Data(bytes: nevent.event_id, count: 32))
- let relay_id = strblock_to_string(nevent.relays.relays.0)
+ var relay_id: String? = nil
+ if nevent.relays.num_relays > 0 {
+ relay_id = strblock_to_string(nevent.relays.relays.0)
+ }
let event_id_ref = ReferencedId(ref_id: event_id, relay_id: relay_id, key: "e")
return .mention(Mention(index: nil, type: .event, ref: event_id_ref))
@@ -362,7 +365,10 @@ func convert_mention_bech32_block(_ b: mention_bech32_block) -> Block?
case NOSTR_BECH32_NPROFILE:
let nprofile = b.bech32.data.nprofile
let pubkey = hex_encode(Data(bytes: nprofile.pubkey, count: 32))
- let relay_id = strblock_to_string(nprofile.relays.relays.0)
+ var relay_id: String? = nil
+ if nprofile.relays.num_relays > 0 {
+ relay_id = strblock_to_string(nprofile.relays.relays.0)
+ }
let pubkey_ref = ReferencedId(ref_id: pubkey, relay_id: relay_id, key: "p")
return .mention(Mention(index: nil, type: .pubkey, ref: pubkey_ref))