nostrdb/blocks: add note block iterator
This adds an api that walks along and pulls compact note block data out of nostrdb. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
Daniel D’Aquino
parent
6f9bd6c4f4
commit
034f2cc02f
+12
-17
@@ -4,12 +4,14 @@
|
||||
|
||||
#include "invoice.h"
|
||||
#include "str_block.h"
|
||||
#include "cursor.h"
|
||||
#include "nostr_bech32.h"
|
||||
#include "nostrdb.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
struct ndb_note_blocks {
|
||||
struct ndb_blocks {
|
||||
unsigned char version;
|
||||
unsigned char padding[3];
|
||||
|
||||
@@ -17,41 +19,34 @@ struct ndb_note_blocks {
|
||||
uint32_t num_blocks;
|
||||
uint32_t blocks_size;
|
||||
// future expansion
|
||||
uint32_t reserved[4];
|
||||
uint32_t reserved[2];
|
||||
unsigned char blocks[0]; // see ndb_block definition
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
enum block_type {
|
||||
BLOCK_HASHTAG = 1,
|
||||
BLOCK_TEXT = 2,
|
||||
BLOCK_MENTION_INDEX = 3,
|
||||
BLOCK_MENTION_BECH32 = 4,
|
||||
BLOCK_URL = 5,
|
||||
BLOCK_INVOICE = 6,
|
||||
};
|
||||
|
||||
|
||||
struct ndb_mention_bech32_block {
|
||||
struct str_block str;
|
||||
struct ndb_str_block str;
|
||||
struct nostr_bech32 bech32;
|
||||
};
|
||||
|
||||
struct ndb_invoice_block {
|
||||
struct str_block invstr;
|
||||
struct ndb_str_block invstr;
|
||||
struct ndb_invoice invoice;
|
||||
};
|
||||
|
||||
struct note_block {
|
||||
enum block_type type;
|
||||
struct ndb_block {
|
||||
enum ndb_block_type type;
|
||||
union {
|
||||
struct str_block str;
|
||||
struct ndb_str_block str;
|
||||
struct ndb_invoice_block invoice;
|
||||
struct ndb_mention_bech32_block mention_bech32;
|
||||
uint32_t mention_index;
|
||||
} block;
|
||||
};
|
||||
|
||||
int push_str_block(struct cursor *buf, const char *content, struct ndb_str_block *block);
|
||||
int pull_str_block(struct cursor *buf, const char *content, struct ndb_str_block *block);
|
||||
|
||||
|
||||
#endif // NDB_BLOCK_H
|
||||
|
||||
Reference in New Issue
Block a user