nostrdb

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

commit 05acd3b8170e7a16dd50a97f4780a6566d15b98e
parent 1e300b5487c243daa034f6af3a0fb2ff657928ef
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 27 Aug 2023 18:25:52 -0700

ndb: add note foreign key to profile

Diffstat:
Mbindings/c/profile_builder.h | 13++++++++-----
Mbindings/c/profile_json_parser.h | 87+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Mbindings/c/profile_reader.h | 3++-
Mbindings/c/profile_verifier.h | 3++-
Mbindings/swift/NdbProfile.swift | 14++++++++++++--
Mnostrdb.c | 97++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
Mschemas/profile.fbs | 1+
Mtest.c | 4++++
Mtestdata/random.json | 2+-
9 files changed, 155 insertions(+), 69 deletions(-)

diff --git a/bindings/c/profile_builder.h b/bindings/c/profile_builder.h @@ -25,7 +25,7 @@ __flatbuffers_build_table(flatbuffers_, NdbProfile, 12) static const flatbuffers_voffset_t __NdbProfileRecord_required[] = { 0 }; typedef flatbuffers_ref_t NdbProfileRecord_ref_t; static NdbProfileRecord_ref_t NdbProfileRecord_clone(flatbuffers_builder_t *B, NdbProfileRecord_table_t t); -__flatbuffers_build_table(flatbuffers_, NdbProfileRecord, 3) +__flatbuffers_build_table(flatbuffers_, NdbProfileRecord, 4) #define __NdbProfile_formal_args ,\ flatbuffers_string_ref_t v0, flatbuffers_string_ref_t v1, flatbuffers_string_ref_t v2, flatbuffers_string_ref_t v3,\ @@ -38,8 +38,8 @@ __flatbuffers_build_table(flatbuffers_, NdbProfileRecord, 3) static inline NdbProfile_ref_t NdbProfile_create(flatbuffers_builder_t *B __NdbProfile_formal_args); __flatbuffers_build_table_prolog(flatbuffers_, NdbProfile, NdbProfile_file_identifier, NdbProfile_type_identifier) -#define __NdbProfileRecord_formal_args , NdbProfile_ref_t v0, uint64_t v1, flatbuffers_string_ref_t v2 -#define __NdbProfileRecord_call_args , v0, v1, v2 +#define __NdbProfileRecord_formal_args , NdbProfile_ref_t v0, uint64_t v1, uint64_t v2, flatbuffers_string_ref_t v3 +#define __NdbProfileRecord_call_args , v0, v1, v2, v3 static inline NdbProfileRecord_ref_t NdbProfileRecord_create(flatbuffers_builder_t *B __NdbProfileRecord_formal_args); __flatbuffers_build_table_prolog(flatbuffers_, NdbProfileRecord, NdbProfileRecord_file_identifier, NdbProfileRecord_type_identifier) @@ -99,14 +99,16 @@ static NdbProfile_ref_t NdbProfile_clone(flatbuffers_builder_t *B, NdbProfile_ta __flatbuffers_build_table_field(0, flatbuffers_, NdbProfileRecord_profile, NdbProfile, NdbProfileRecord) __flatbuffers_build_scalar_field(1, flatbuffers_, NdbProfileRecord_received_at, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), NdbProfileRecord) -__flatbuffers_build_string_field(2, flatbuffers_, NdbProfileRecord_lnurl, NdbProfileRecord) +__flatbuffers_build_scalar_field(2, flatbuffers_, NdbProfileRecord_note_key, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), NdbProfileRecord) +__flatbuffers_build_string_field(3, flatbuffers_, NdbProfileRecord_lnurl, NdbProfileRecord) static inline NdbProfileRecord_ref_t NdbProfileRecord_create(flatbuffers_builder_t *B __NdbProfileRecord_formal_args) { if (NdbProfileRecord_start(B) || NdbProfileRecord_received_at_add(B, v1) + || NdbProfileRecord_note_key_add(B, v2) || NdbProfileRecord_profile_add(B, v0) - || NdbProfileRecord_lnurl_add(B, v2)) { + || NdbProfileRecord_lnurl_add(B, v3)) { return 0; } return NdbProfileRecord_end(B); @@ -117,6 +119,7 @@ static NdbProfileRecord_ref_t NdbProfileRecord_clone(flatbuffers_builder_t *B, N __flatbuffers_memoize_begin(B, t); if (NdbProfileRecord_start(B) || NdbProfileRecord_received_at_pick(B, t) + || NdbProfileRecord_note_key_pick(B, t) || NdbProfileRecord_profile_pick(B, t) || NdbProfileRecord_lnurl_pick(B, t)) { return 0; diff --git a/bindings/c/profile_json_parser.h b/bindings/c/profile_json_parser.h @@ -273,17 +273,17 @@ static const char *NdbProfileRecord_parse_json_table(flatcc_json_parser_t *ctx, uint64_t w; *result = 0; - if (flatcc_builder_start_table(ctx->ctx, 3)) goto failed; + if (flatcc_builder_start_table(ctx->ctx, 4)) goto failed; buf = flatcc_json_parser_object_start(ctx, buf, end, &more); while (more) { buf = flatcc_json_parser_symbol_start(ctx, buf, end); w = flatcc_json_parser_symbol_part(buf, end); - if (w < 0x70726f66696c6500) { /* branch "profile" */ + if (w < 0x6e6f74655f6b6579) { /* branch "note_key" */ if ((w & 0xffffffffff000000) == 0x6c6e75726c000000) { /* "lnurl" */ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5); if (mark != buf) { buf = flatcc_json_parser_build_string(ctx, buf, end, &ref); - if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 2))) goto failed; + if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 3))) goto failed; *pref = ref; } else { buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); @@ -291,26 +291,10 @@ static const char *NdbProfileRecord_parse_json_table(flatcc_json_parser_t *ctx, } else { /* "lnurl" */ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); } /* "lnurl" */ - } else { /* branch "profile" */ - if ((w & 0xffffffffffffff00) == 0x70726f66696c6500) { /* "profile" */ - buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7); - if (mark != buf) { - buf = NdbProfile_parse_json_table(ctx, buf, end, &ref); - if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed; - *pref = ref; - } else { - goto pfguard1; - } - } else { /* "profile" */ - goto pfguard1; - } /* "profile" */ - goto endpfguard1; -pfguard1: - if (w == 0x7265636569766564) { /* descend "received" */ - buf += 8; - w = flatcc_json_parser_symbol_part(buf, end); - if ((w & 0xffffff0000000000) == 0x5f61740000000000) { /* "_at" */ - buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3); + } else { /* branch "note_key" */ + if (w < 0x70726f66696c6500) { /* branch "profile" */ + if (w == 0x6e6f74655f6b6579) { /* "note_key" */ + buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 8); if (mark != buf) { uint64_t val = 0; static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { @@ -322,21 +306,62 @@ pfguard1: if (buf == mark || buf == end) goto failed; } if (val != UINT64_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { - if (!(pval = flatcc_builder_table_add(ctx->ctx, 1, 8, 8))) goto failed; + if (!(pval = flatcc_builder_table_add(ctx->ctx, 2, 8, 8))) goto failed; flatbuffers_uint64_write_to_pe(pval, val); } } else { buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); } - } else { /* "_at" */ + } else { /* "note_key" */ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); - } /* "_at" */ - } else { /* descend "received" */ - buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); - } /* descend "received" */ + } /* "note_key" */ + } else { /* branch "profile" */ + if ((w & 0xffffffffffffff00) == 0x70726f66696c6500) { /* "profile" */ + buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7); + if (mark != buf) { + buf = NdbProfile_parse_json_table(ctx, buf, end, &ref); + if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed; + *pref = ref; + } else { + goto pfguard1; + } + } else { /* "profile" */ + goto pfguard1; + } /* "profile" */ + goto endpfguard1; +pfguard1: + if (w == 0x7265636569766564) { /* descend "received" */ + buf += 8; + w = flatcc_json_parser_symbol_part(buf, end); + if ((w & 0xffffff0000000000) == 0x5f61740000000000) { /* "_at" */ + buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3); + if (mark != buf) { + uint64_t val = 0; + static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = { + profile_local_json_parser_enum, + profile_global_json_parser_enum, 0 }; + buf = flatcc_json_parser_uint64(ctx, (mark = buf), end, &val); + if (mark == buf) { + buf = flatcc_json_parser_symbolic_uint64(ctx, (mark = buf), end, symbolic_parsers, &val); + if (buf == mark || buf == end) goto failed; + } + if (val != UINT64_C(0) || (ctx->flags & flatcc_json_parser_f_force_add)) { + if (!(pval = flatcc_builder_table_add(ctx->ctx, 1, 8, 8))) goto failed; + flatbuffers_uint64_write_to_pe(pval, val); + } + } else { + buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); + } + } else { /* "_at" */ + buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); + } /* "_at" */ + } else { /* descend "received" */ + buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end); + } /* descend "received" */ endpfguard1: - (void)0; - } /* branch "profile" */ + (void)0; + } /* branch "profile" */ + } /* branch "note_key" */ buf = flatcc_json_parser_object_end(ctx, buf, end, &more); } if (ctx->error) goto failed; diff --git a/bindings/c/profile_reader.h b/bindings/c/profile_reader.h @@ -85,7 +85,8 @@ __flatbuffers_table_as_root(NdbProfileRecord) __flatbuffers_define_table_field(0, NdbProfileRecord, profile, NdbProfile_table_t, 0) __flatbuffers_define_scalar_field(1, NdbProfileRecord, received_at, flatbuffers_uint64, uint64_t, UINT64_C(0)) -__flatbuffers_define_string_field(2, NdbProfileRecord, lnurl, 0) +__flatbuffers_define_scalar_field(2, NdbProfileRecord, note_key, flatbuffers_uint64, uint64_t, UINT64_C(0)) +__flatbuffers_define_string_field(3, NdbProfileRecord, lnurl, 0) #include "flatcc/flatcc_epilogue.h" diff --git a/bindings/c/profile_verifier.h b/bindings/c/profile_verifier.h @@ -55,7 +55,8 @@ static int NdbProfileRecord_verify_table(flatcc_table_verifier_descriptor_t *td) int ret; if ((ret = flatcc_verify_table_field(td, 0, 0, &NdbProfile_verify_table) /* profile */)) return ret; if ((ret = flatcc_verify_field(td, 1, 8, 8) /* received_at */)) return ret; - if ((ret = flatcc_verify_string_field(td, 2, 0) /* lnurl */)) return ret; + if ((ret = flatcc_verify_field(td, 2, 8, 8) /* note_key */)) return ret; + if ((ret = flatcc_verify_string_field(td, 3, 0) /* lnurl */)) return ret; return flatcc_verify_ok; } diff --git a/bindings/swift/NdbProfile.swift b/bindings/swift/NdbProfile.swift @@ -166,29 +166,34 @@ public struct NdbProfileRecord: FlatBufferObject, Verifiable { private enum VTOFFSET: VOffset { case profile = 4 case receivedAt = 6 - case lnurl = 8 + case noteKey = 8 + case lnurl = 10 var v: Int32 { Int32(self.rawValue) } var p: VOffset { self.rawValue } } public var profile: NdbProfile? { let o = _accessor.offset(VTOFFSET.profile.v); return o == 0 ? nil : NdbProfile(_accessor.bb, o: _accessor.indirect(o + _accessor.postion)) } public var receivedAt: UInt64 { let o = _accessor.offset(VTOFFSET.receivedAt.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } + public var noteKey: UInt64 { let o = _accessor.offset(VTOFFSET.noteKey.v); return o == 0 ? 0 : _accessor.readBuffer(of: UInt64.self, at: o) } public var lnurl: String? { let o = _accessor.offset(VTOFFSET.lnurl.v); return o == 0 ? nil : _accessor.string(at: o) } public var lnurlSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.lnurl.v) } - public static func startNdbProfileRecord(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 3) } + public static func startNdbProfileRecord(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 4) } public static func add(profile: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: profile, at: VTOFFSET.profile.p) } public static func add(receivedAt: UInt64, _ fbb: inout FlatBufferBuilder) { fbb.add(element: receivedAt, def: 0, at: VTOFFSET.receivedAt.p) } + public static func add(noteKey: UInt64, _ fbb: inout FlatBufferBuilder) { fbb.add(element: noteKey, def: 0, at: VTOFFSET.noteKey.p) } public static func add(lnurl: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: lnurl, at: VTOFFSET.lnurl.p) } public static func endNdbProfileRecord(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end } public static func createNdbProfileRecord( _ fbb: inout FlatBufferBuilder, profileOffset profile: Offset = Offset(), receivedAt: UInt64 = 0, + noteKey: UInt64 = 0, lnurlOffset lnurl: Offset = Offset() ) -> Offset { let __start = NdbProfileRecord.startNdbProfileRecord(&fbb) NdbProfileRecord.add(profile: profile, &fbb) NdbProfileRecord.add(receivedAt: receivedAt, &fbb) + NdbProfileRecord.add(noteKey: noteKey, &fbb) NdbProfileRecord.add(lnurl: lnurl, &fbb) return NdbProfileRecord.endNdbProfileRecord(&fbb, start: __start) } @@ -197,6 +202,7 @@ public struct NdbProfileRecord: FlatBufferObject, Verifiable { var _v = try verifier.visitTable(at: position) try _v.visit(field: VTOFFSET.profile.p, fieldName: "profile", required: false, type: ForwardOffset<NdbProfile>.self) try _v.visit(field: VTOFFSET.receivedAt.p, fieldName: "receivedAt", required: false, type: UInt64.self) + try _v.visit(field: VTOFFSET.noteKey.p, fieldName: "noteKey", required: false, type: UInt64.self) try _v.visit(field: VTOFFSET.lnurl.p, fieldName: "lnurl", required: false, type: ForwardOffset<String>.self) _v.finish() } @@ -207,6 +213,7 @@ extension NdbProfileRecord: Encodable { enum CodingKeys: String, CodingKey { case profile = "profile" case receivedAt = "received_at" + case noteKey = "note_key" case lnurl = "lnurl" } public func encode(to encoder: Encoder) throws { @@ -215,6 +222,9 @@ extension NdbProfileRecord: Encodable { if receivedAt != 0 { try container.encodeIfPresent(receivedAt, forKey: .receivedAt) } + if noteKey != 0 { + try container.encodeIfPresent(noteKey, forKey: .noteKey) + } try container.encodeIfPresent(lnurl, forKey: .lnurl) } } diff --git a/nostrdb.c b/nostrdb.c @@ -36,6 +36,10 @@ static const int DEFAULT_QUEUE_SIZE = 1000000; #define NDB_PARSED_TAGS (1 << 6) #define NDB_PARSED_ALL (NDB_PARSED_ID|NDB_PARSED_PUBKEY|NDB_PARSED_SIG|NDB_PARSED_CREATED_AT|NDB_PARSED_KIND|NDB_PARSED_CONTENT|NDB_PARSED_TAGS) +struct ndb_profile_record_builder { + flatcc_builder_t *builder; + void *flatbuf; +}; // controls whether to continue or stop the json parser enum ndb_idres { @@ -184,8 +188,7 @@ struct ndb_writer_note { struct ndb_writer_profile { struct ndb_writer_note note; - void *profile_flatbuf; - size_t profile_len; + struct ndb_profile_record_builder record; }; struct ndb_ingester_msg { @@ -358,22 +361,43 @@ static int ndbprofile_parse_json(flatcc_builder_t *B, return 1; } -static int ndb_process_profile_note(struct ndb_note *note, void **profile, - size_t *profile_len) +void ndb_profile_record_builder_init(struct ndb_profile_record_builder *b) +{ + b->builder = malloc(sizeof(*b->builder)); + b->flatbuf = NULL; +} + +void ndb_profile_record_builder_free(struct ndb_profile_record_builder *b) +{ + if (b->builder) + free(b->builder); + if (b->flatbuf) + free(b->flatbuf); + + b->builder = NULL; + b->flatbuf = NULL; +} + +static int ndb_process_profile_note(struct ndb_note *note, + struct ndb_profile_record_builder *profile) { NdbProfile_ref_t profile_table; - flatcc_builder_t builder; - flatcc_builder_init(&builder); + flatcc_builder_t *builder; - NdbProfileRecord_start_as_root(&builder); + ndb_profile_record_builder_init(profile); + builder = profile->builder; + flatcc_builder_init(builder); + + NdbProfileRecord_start_as_root(builder); //printf("parsing profile '%.*s'\n", note->content_length, ndb_note_content(note)); - if (!ndbprofile_parse_json(&builder, ndb_note_content(note), + if (!ndbprofile_parse_json(builder, ndb_note_content(note), note->content_length, flatcc_json_parser_f_skip_unknown, &profile_table)) { ndb_debug("profile_parse_json failed %d '%.*s'\n", res, note->content_length, ndb_note_content(note)); + ndb_profile_record_builder_free(profile); return 0; } @@ -381,15 +405,13 @@ static int ndb_process_profile_note(struct ndb_note *note, void **profile, const char *lnurl = "fixme"; flatcc_builder_ref_t lnurl_off; - lnurl_off = flatcc_builder_create_string_str(&builder, lnurl); - - NdbProfileRecord_profile_add(&builder, profile_table); - NdbProfileRecord_received_at_add(&builder, received_at); - NdbProfileRecord_lnurl_add(&builder, lnurl_off); + lnurl_off = flatcc_builder_create_string_str(builder, lnurl); - NdbProfileRecord_end_as_root(&builder); + NdbProfileRecord_profile_add(builder, profile_table); + NdbProfileRecord_received_at_add(builder, received_at); + NdbProfileRecord_lnurl_add(builder, lnurl_off); - *profile = flatcc_builder_finalize_aligned_buffer(&builder, profile_len); + //*profile = flatcc_builder_finalize_aligned_buffer(builder, profile_len); return 1; } @@ -405,8 +427,8 @@ static int ndb_ingester_process_event(secp256k1_context *ctx, struct ndb_note *note; struct ndb_ingest_controller controller; struct ndb_id_cb cb; - void *buf, *flatbuf; - size_t bufsize, note_size, profile_len; + void *buf; + size_t bufsize, note_size; // we will use this to check if we already have it in the DB during // ID parsing @@ -460,13 +482,15 @@ static int ndb_ingester_process_event(secp256k1_context *ctx, // to the writer thread note = realloc(note, note_size); - if (note->kind == 0 && - ndb_process_profile_note(note, &flatbuf, &profile_len)) { + if (note->kind == 0) { + struct ndb_profile_record_builder *b = + &out->profile.record; + + ndb_process_profile_note(note, b); + out->type = NDB_WRITER_PROFILE; out->profile.note.note = note; out->profile.note.note_len = note_size; - out->profile.profile_flatbuf = flatbuf; - out->profile.profile_len = profile_len; } else { out->type = NDB_WRITER_NOTE; out->note.note = note; @@ -505,11 +529,14 @@ static uint64_t ndb_get_last_key(MDB_txn *txn, MDB_dbi db) } static int ndb_write_profile(struct ndb_lmdb *lmdb, MDB_txn *txn, - struct ndb_writer_profile *profile) + struct ndb_writer_profile *profile, + uint64_t note_key) { uint64_t profile_key; struct ndb_tsid tsid; struct ndb_note *note; + void *flatbuf; + size_t flatbuf_len; int rc; MDB_val key, val; @@ -517,6 +544,14 @@ static int ndb_write_profile(struct ndb_lmdb *lmdb, MDB_txn *txn, note = profile->note.note; + // add note_key to profile record + NdbProfileRecord_note_key_add(profile->record.builder, note_key); + NdbProfileRecord_end_as_root(profile->record.builder); + + flatbuf = profile->record.flatbuf = + flatcc_builder_finalize_aligned_buffer(profile->record.builder, + &flatbuf_len); + // get dbs profile_db = lmdb->dbs[NDB_DB_PROFILE]; pk_db = lmdb->dbs[NDB_DB_PROFILE_PK]; @@ -527,8 +562,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 + 4; - val.mv_size = profile->profile_len - 4; + val.mv_data = flatbuf + 4; + val.mv_size = flatbuf_len - 4; //ndb_debug("profile_len %ld\n", profile->profile_len); if ((rc = mdb_put(txn, profile_db, &key, &val, 0))) { @@ -602,6 +637,7 @@ static void *ndb_writer_thread(void *data) struct ndb_writer *writer = data; struct ndb_writer_msg msgs[THREAD_QUEUE_BATCH], *msg; int i, popped, done, any_note; + uint64_t note_nkey; MDB_txn *txn; done = 0; @@ -637,9 +673,14 @@ static void *ndb_writer_thread(void *data) done = 1; continue; case NDB_WRITER_PROFILE: - ndb_write_note(writer->lmdb, txn, &msg->note); - // TODO: save note_key with profile - ndb_write_profile(writer->lmdb, txn, &msg->profile); + note_nkey = + ndb_write_note(writer->lmdb, txn, &msg->note); + if (msg->profile.record.builder) { + // only write if parsing didn't fail + ndb_write_profile(writer->lmdb, txn, + &msg->profile, + note_nkey); + } break; case NDB_WRITER_NOTE: ndb_write_note(writer->lmdb, txn, &msg->note); @@ -660,8 +701,8 @@ static void *ndb_writer_thread(void *data) if (msg->type == NDB_WRITER_NOTE) free(msg->note.note); else if (msg->type == NDB_WRITER_PROFILE) { - free(msg->profile.profile_flatbuf); free(msg->profile.note.note); + ndb_profile_record_builder_free(&msg->profile.record); } } } diff --git a/schemas/profile.fbs b/schemas/profile.fbs @@ -17,6 +17,7 @@ table NdbProfile { table NdbProfileRecord { profile:NdbProfile; received_at:ulong; + note_key:ulong; // artifacts lnurl:string; diff --git a/test.c b/test.c @@ -280,11 +280,15 @@ static void test_fetch_last_noteid() NdbProfile_table_t profile = NdbProfileRecord_profile_get(profile_record); const char *lnurl = NdbProfileRecord_lnurl_get(profile_record); const char *name = NdbProfile_name_get(profile); + uint64_t key = NdbProfileRecord_note_key_get(profile_record); assert(name); assert(lnurl); assert(!strcmp(name, "jb55")); assert(!strcmp(lnurl, "fixme")); + printf("note_key %" PRIu64 "\n", key); + assert(key == 2); + //fwrite(profile, len, 1, stdout); ndb_destroy(ndb); diff --git a/testdata/random.json b/testdata/random.json @@ -1,5 +1,5 @@ -["EVENT","s",{"id":"d12c17bde3094ad32f4ab862a6cc6f5c289cfe7d5802270bdf34904df585f349","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650049978,"kind":0,"tags":[],"content":"{\"name\":\"jb55\",\"picture\":\"http://cdn.jb55.com/img/red-me.jpg\",\"about\":\"bitcoin, lightning and nostr dev\",\"nip05\":\"jb55.com\"}","sig":"1315045da793c4825de1517149172bf35a6da39d91b7787afb3263721e07bc816cb898996ed8d69af05d6efcd1c926a089bd66cad870bcc361405c11ba302c51"}] ["EVENT","s",{"id":"b2e03951843b191b5d9d1969f48db0156b83cc7dbd841f543f109362e24c4a9c","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650050002,"kind":1,"tags":[],"content":"hello, this is my new key","sig":"4342eff1d78a82b42522cd26ec66a5293eca997f81d4b80efd02230d3d27317fb63d42656e8f32383562f075a2b6d999b60dcf70e2df18cf5e8b3801faeb0bd6"}] +["EVENT","s",{"id":"d12c17bde3094ad32f4ab862a6cc6f5c289cfe7d5802270bdf34904df585f349","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650049978,"kind":0,"tags":[],"content":"{\"name\":\"jb55\",\"picture\":\"http://cdn.jb55.com/img/red-me.jpg\",\"about\":\"bitcoin, lightning and nostr dev\",\"nip05\":\"jb55.com\"}","sig":"1315045da793c4825de1517149172bf35a6da39d91b7787afb3263721e07bc816cb898996ed8d69af05d6efcd1c926a089bd66cad870bcc361405c11ba302c51"}] ["EVENT","s",{"id":"00000e1253a8888a195da04ebc528d2b44a3d4e2788e79b85ec1a2c61eef3733","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650051200,"kind":1,"tags":[["nonce","2255367"]],"content":"I am a robot beep boop! This note took 4 seconds to mine 20 bits after 2255367 tries!\n\nThis was generated with https://github.com/jb55/nostril","sig":"97aa14e528c3bef66ebfc767592c5e1488f191b949862b7ca9f061839698d3c2048ba252fa767ab688aafc81107a1d1a81f4ae74ff6d7e2dfe4460807dfab98a"}] ["EVENT","s",{"id":"a4b73fc5b901b74f4d96c6f7104fc58472deae474a225fa172eccaf88df50505","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650053582,"kind":1,"tags":[["p","6cad545430904b84a8101c5783b65043f19ae29d2da1076b8fc3e64892736f03","wss://nostr-relay.untethr.me"]],"content":"I made a robot friend that mines nostr events: #[0] ","sig":"d9104549d77ca9b4966b68659d1eddd6dc0c8056642ab013f95a434454311b0110b4eb3bfeee7411f63a784059b03214116186023b03f34701441894ba838eb7"}] ["EVENT","s",{"id":"dc964f4c898364138e8196f0c73338c8cc3ebfa3afddbc7dd158b4847c1ebfa0","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650054135,"kind":1,"tags":[["p","fd3fdb0d0d8d6f9a7667b53211de8ae3c5246b79bdaf64ebac849d5148b5615f"],["p","8c0da4862130283ff9e67d889df264177a508974e2feb96de139804ea66d6168","wss://nostr-relay.untethr.me"],["e","8bc0f167205a099454f6638043c3747b474b16bca77966a0f0c09dfaec0768bf"],["e","f78f0480da11b55fd04211268814e3e285ff7d19a40463e304e98cb49a2ec849"]],"content":"I'm at this account now","sig":"3011b712245b9633405e7b9c901311ef98d61e2bcccac95e554d87870a1a4a974d64191170b39e474ffe8e2746efe704761c13d7b22c19005e69d51cf188453f"}]