nostrdb

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

commit a5d5428c467e32d215419b74a140ef0adde2869e
parent 8189014adc4495c48992e2213ede97390b9f6ebd
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 26 Aug 2023 20:34:01 -0700

ndb: test profile flatbuffers

Diffstat:
MMakefile | 4++--
Mnostrdb.c | 4++--
Mschemas/profile.fbs | 2--
Mtest.c | 24++++++++++++++++++------
4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ -CFLAGS = -Wall -Wno-unused-function -Werror -O2 -g -Ideps/secp256k1/include -Ideps/lmdb -Ideps/flatcc/include -HEADERS = sha256.h nostrdb.h cursor.h hex.h jsmn.h config.h sha256.h random.h memchr.h +CFLAGS = -Wall -Wno-unused-function -Werror -O0 -g -Ideps/secp256k1/include -Ideps/lmdb -Ideps/flatcc/include +HEADERS = sha256.h nostrdb.h cursor.h hex.h jsmn.h config.h sha256.h random.h memchr.h $(C_BINDINGS) FLATCC_SRCS=deps/flatcc/src/runtime/json_parser.c deps/flatcc/src/runtime/builder.c deps/flatcc/src/runtime/emitter.c deps/flatcc/src/runtime/refmap.c SRCS = nostrdb.c sha256.c $(FLATCC_SRCS) LDS = $(SRCS) $(ARS) diff --git a/nostrdb.c b/nostrdb.c @@ -504,8 +504,8 @@ static int ndb_write_profile(struct ndb_lmdb *lmdb, MDB_txn *txn, // write profile to profile store key.mv_data = &profile_key; key.mv_size = sizeof(profile_key); - val.mv_data = profile->profile_flatbuf; - val.mv_size = profile->profile_len; + val.mv_data = profile->profile_flatbuf + 4; + val.mv_size = profile->profile_len - 4; //ndb_debug("profile_len %ld\n", profile->profile_len); if ((rc = mdb_put(txn, profile_db, &key, &val, 0))) { diff --git a/schemas/profile.fbs b/schemas/profile.fbs @@ -1,7 +1,5 @@ table NdbProfile { - evid:uint64; - name:string; website:string; about:string; diff --git a/test.c b/test.c @@ -4,6 +4,7 @@ #include "io.h" #include "protected_queue.h" #include "memchr.h" +#include "bindings/c/profile_reader.h" #include <stdio.h> #include <assert.h> @@ -250,7 +251,7 @@ static void test_fetch_last_noteid() char *json = malloc(alloc_size); unsigned char *buf = malloc(alloc_size); struct ndb *ndb; - size_t mapsize; + size_t mapsize, len; int written, ingester_threads; mapsize = 1024 * 1024 * 100; @@ -264,13 +265,24 @@ static void test_fetch_last_noteid() assert(ndb_init(&ndb, test_dir, mapsize, ingester_threads)); - unsigned char id[32] = { 0xdc, 0x96, 0x4f, 0x4c, 0x89, 0x83, 0x64, - 0x13, 0x8e, 0x81, 0x96, 0xf0, 0xc7, 0x33, 0x38, 0xc8, 0xcc, - 0x3e, 0xbf, 0xa3, 0xaf, 0xdd, 0xbc, 0x7d, 0xd1, 0x58, 0xb4, - 0x84, 0x7c, 0x1e, 0xbf, 0xa0 }; + unsigned char id[32] = { 0xdc, 0x96, 0x4f, 0x4c, 0x89, 0x83, 0x64, 0x13, 0x8e, 0x81, 0x96, 0xf0, 0xc7, 0x33, 0x38, 0xc8, 0xcc, 0x3e, 0xbf, 0xa3, 0xaf, 0xdd, 0xbc, 0x7d, 0xd1, 0x58, 0xb4, 0x84, 0x7c, 0x1e, 0xbf, 0xa0 }; - struct ndb_note *note = ndb_get_note_by_id(ndb, id); + struct ndb_note *note = ndb_get_note_by_id(ndb, id, &len); assert(note != NULL); + assert(note->created_at == 1650054135); + + unsigned char pk[32] = { 0x32, 0xe1, 0x82, 0x76, 0x35, 0x45, 0x0e, 0xbb, 0x3c, 0x5a, 0x7d, 0x12, 0xc1, 0xf8, 0xe7, 0xb2, 0xb5, 0x14, 0x43, 0x9a, 0xc1, 0x0a, 0x67, 0xee, 0xf3, 0xd9, 0xfd, 0x9c, 0x5c, 0x68, 0xe2, 0x45 }; + + void *profile = ndb_get_profile_by_pubkey(ndb, pk, &len); + + assert(profile); + + const char *name = NdbProfile_name_get(profile); + assert(name); + printf("name '%s'\n", name); + assert(!strcmp(name, "jb55")); + + //fwrite(profile, len, 1, stdout); ndb_destroy(ndb);