nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 4e4ffe2e537b4094d84e4ed0f5e553984f04636c
parent e9a8a7e2475816db0fcbf04953ccabdfacec515a
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 30 Dec 2023 06:27:05 -0800

header: move bech32 around

Diffstat:
Msrc/nostrdb.h | 152++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 76 insertions(+), 76 deletions(-)

diff --git a/src/nostrdb.h b/src/nostrdb.h @@ -284,6 +284,80 @@ struct ndb_text_search_results { int num_results; }; +enum ndb_block_type { + BLOCK_HASHTAG = 1, + BLOCK_TEXT = 2, + BLOCK_MENTION_INDEX = 3, + BLOCK_MENTION_BECH32 = 4, + BLOCK_URL = 5, + BLOCK_INVOICE = 6, +}; +#define NDB_NUM_BLOCK_TYPES 6 +#define NDB_MAX_RELAYS 24 + +struct ndb_relays { + struct ndb_str_block relays[NDB_MAX_RELAYS]; + int num_relays; +}; + +enum nostr_bech32_type { + NOSTR_BECH32_NOTE = 1, + NOSTR_BECH32_NPUB = 2, + NOSTR_BECH32_NPROFILE = 3, + NOSTR_BECH32_NEVENT = 4, + NOSTR_BECH32_NRELAY = 5, + NOSTR_BECH32_NADDR = 6, + NOSTR_BECH32_NSEC = 7, +}; +#define NOSTR_BECH32_KNOWN_TYPES 7 + +struct bech32_note { + const unsigned char *event_id; +}; + +struct bech32_npub { + const unsigned char *pubkey; +}; + +struct bech32_nsec { + const unsigned char *nsec; +}; + +struct bech32_nevent { + struct ndb_relays relays; + const unsigned char *event_id; + const unsigned char *pubkey; // optional +}; + +struct bech32_nprofile { + struct ndb_relays relays; + const unsigned char *pubkey; +}; + +struct bech32_naddr { + struct ndb_relays relays; + struct ndb_str_block identifier; + const unsigned char *pubkey; +}; + +struct bech32_nrelay { + struct ndb_str_block relay; +}; + +struct nostr_bech32 { + enum nostr_bech32_type type; + + union { + struct bech32_note note; + struct bech32_npub npub; + struct bech32_nsec nsec; + struct bech32_nevent nevent; + struct bech32_nprofile nprofile; + struct bech32_naddr naddr; + struct bech32_nrelay nrelay; + }; +}; + // CONFIG void ndb_default_config(struct ndb_config *); @@ -394,83 +468,9 @@ int ndb_parse_content(unsigned char *buf, int buf_size, struct ndb_blocks **blocks_p); // BLOCKS -enum ndb_block_type { - BLOCK_HASHTAG = 1, - BLOCK_TEXT = 2, - BLOCK_MENTION_INDEX = 3, - BLOCK_MENTION_BECH32 = 4, - BLOCK_URL = 5, - BLOCK_INVOICE = 6, -}; -#define NDB_NUM_BLOCK_TYPES 6 - -#define NDB_MAX_RELAYS 24 - -struct ndb_relays { - struct ndb_str_block relays[NDB_MAX_RELAYS]; - int num_relays; -}; - -enum nostr_bech32_type { - NOSTR_BECH32_NOTE = 1, - NOSTR_BECH32_NPUB = 2, - NOSTR_BECH32_NPROFILE = 3, - NOSTR_BECH32_NEVENT = 4, - NOSTR_BECH32_NRELAY = 5, - NOSTR_BECH32_NADDR = 6, - NOSTR_BECH32_NSEC = 7, -}; -#define NOSTR_BECH32_KNOWN_TYPES 7 - -struct bech32_note { - const unsigned char *event_id; -}; - -struct bech32_npub { - const unsigned char *pubkey; -}; - -struct bech32_nsec { - const unsigned char *nsec; -}; - -struct bech32_nevent { - struct ndb_relays relays; - const unsigned char *event_id; - const unsigned char *pubkey; // optional -}; - -struct bech32_nprofile { - struct ndb_relays relays; - const unsigned char *pubkey; -}; - -struct bech32_naddr { - struct ndb_relays relays; - struct ndb_str_block identifier; - const unsigned char *pubkey; -}; - -struct bech32_nrelay { - struct ndb_str_block relay; -}; - -struct nostr_bech32 { - enum nostr_bech32_type type; - - union { - struct bech32_note note; - struct bech32_npub npub; - struct bech32_nsec nsec; - struct bech32_nevent nevent; - struct bech32_nprofile nprofile; - struct bech32_naddr naddr; - struct bech32_nrelay nrelay; - }; -}; +enum ndb_block_type ndb_block_type(struct ndb_blocks *blocks); -enum ndb_block_type ndb_block_type(struct ndb_blocks *blocks); // BLOCK ITERATORS struct ndb_block_iterator *ndb_blocks_iterate_start(const char *, struct ndb_blocks *); @@ -482,8 +482,8 @@ enum ndb_block_type ndb_get_block_type(struct ndb_block *block); struct ndb_str_block *ndb_block_str(struct ndb_block *); const char *ndb_str_block_ptr(struct ndb_str_block *); uint32_t ndb_str_block_len(struct ndb_str_block *); -struct nostr_bech32 *ndb_bech32_block(struct ndb_block *block); // BECH32 BLOCKS +struct nostr_bech32 *ndb_bech32_block(struct ndb_block *block); #endif