damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit b8bef86ea1aa34044ebdfe2862386108fc22a76d
parent b128330b2a34be555263fc64390c287978f81a2d
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  1 Feb 2024 14:36:59 -0800

nostrdb: port kernelkind's to the new bech32 parser

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mnostrdb/src/nostr_bech32.c | 18++++++++++++++++++
Mnostrdb/src/nostrdb.h | 8++++++--
2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/nostrdb/src/nostr_bech32.c b/nostrdb/src/nostr_bech32.c @@ -102,6 +102,11 @@ static int add_relay(struct ndb_relays *relays, struct nostr_tlv *tlv) return 1; } +static uint32_t decode_tlv_u32(const uint8_t *bytes) { + beint32_t *be32_bytes = (beint32_t*)bytes; + return be32_to_cpu(*be32_bytes); +} + static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *nevent) { struct nostr_tlv tlv; int i; @@ -109,6 +114,7 @@ static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *n nevent->event_id = NULL; nevent->pubkey = NULL; nevent->relays.num_relays = 0; + nevent->has_kind = 0; for (i = 0; i < MAX_TLVS; i++) { if (!parse_nostr_tlv(cur, &tlv)) @@ -120,6 +126,12 @@ static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *n return 0; nevent->event_id = tlv.value; break; + case TLV_KIND: + if (tlv.len != 4) + return 0; + nevent->kind = decode_tlv-U32(tlv.value); + nevent->has_kind = 1; + break; case TLV_AUTHOR: if (tlv.len != 32) return 0; @@ -141,6 +153,7 @@ static int parse_nostr_bech32_naddr(struct cursor *cur, struct bech32_naddr *nad naddr->identifier.str = NULL; naddr->identifier.len = 0; naddr->pubkey = NULL; + naddr->has_kind = 0; naddr->relays.num_relays = 0; for (i = 0; i < MAX_TLVS; i++) { @@ -156,6 +169,11 @@ static int parse_nostr_bech32_naddr(struct cursor *cur, struct bech32_naddr *nad if (tlv.len != 32) return 0; naddr->pubkey = tlv.value; break; + case TLV_KIND: + if (tlv.len != 4) return 0; + naddr->kind = decode_tlv_u32(tlv.value); + naddr->has_kind = 1; + break; case TLV_RELAY: add_relay(&naddr->relays, &tlv); break; diff --git a/nostrdb/src/nostrdb.h b/nostrdb/src/nostrdb.h @@ -337,6 +337,8 @@ struct bech32_nevent { struct ndb_relays relays; const unsigned char *event_id; const unsigned char *pubkey; // optional + uint32_t kind; + int has_kind; }; struct bech32_nprofile { @@ -348,13 +350,15 @@ struct bech32_naddr { struct ndb_relays relays; struct ndb_str_block identifier; const unsigned char *pubkey; + uint32_t kind; + int has_kind; }; struct bech32_nrelay { struct ndb_str_block relay; }; -struct nostr_bech32 { +typedef struct nostr_bech32 { enum nostr_bech32_type type; union { @@ -366,7 +370,7 @@ struct nostr_bech32 { struct bech32_naddr naddr; struct bech32_nrelay nrelay; }; -}; +} nostr_bech32_t; struct ndb_mention_bech32_block {