nostrdb: port everything over to be in as sync as possible
for now
This commit is contained in:
committed by
Daniel D’Aquino
parent
954f48b23d
commit
1fb88a912a
168
nostrdb/Makefile
Normal file
168
nostrdb/Makefile
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
CFLAGS = -Wall -Wno-misleading-indentation -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 cpu.h $(C_BINDINGS)
|
||||||
|
FLATCC_SRCS=deps/flatcc/src/runtime/json_parser.c deps/flatcc/src/runtime/verifier.c deps/flatcc/src/runtime/builder.c deps/flatcc/src/runtime/emitter.c deps/flatcc/src/runtime/refmap.c
|
||||||
|
BOLT11_SRCS = bolt11/bolt11.c bolt11/bech32.c bolt11/tal.c bolt11/talstr.c bolt11/take.c bolt11/list.c bolt11/utf8.c bolt11/amount.c bolt11/hash_u5.c
|
||||||
|
SRCS = nostrdb.c sha256.c $(BOLT11_SRCS) $(FLATCC_SRCS)
|
||||||
|
LDS = $(OBJS) $(ARS)
|
||||||
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
DEPS = $(OBJS) $(HEADERS) $(ARS)
|
||||||
|
ARS = deps/lmdb/liblmdb.a deps/secp256k1/.libs/libsecp256k1.a
|
||||||
|
LMDB_VER=0.9.31
|
||||||
|
FLATCC_VER=05dc16dc2b0316e61063bb1fc75426647badce48
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
SUBMODULES = deps/secp256k1
|
||||||
|
C_BINDINGS_PROFILE=bindings/c/profile_builder.h bindings/c/profile_reader.h bindings/c/profile_verifier.h bindings/c/profile_json_parser.h
|
||||||
|
C_BINDINGS_META=bindings/c/meta_builder.h bindings/c/meta_reader.h bindings/c/meta_verifier.h bindings/c/meta_json_parser.h
|
||||||
|
C_BINDINGS_COMMON=bindings/c/flatbuffers_common_builder.h bindings/c/flatbuffers_common_reader.h
|
||||||
|
C_BINDINGS=$(C_BINDINGS_COMMON) $(C_BINDINGS_PROFILE) $(C_BINDINGS_META)
|
||||||
|
BINDINGS=bindings
|
||||||
|
BIN=ndb
|
||||||
|
|
||||||
|
CHECKDATA=testdata/db/v0/data.mdb
|
||||||
|
|
||||||
|
all: lib ndb
|
||||||
|
|
||||||
|
lib: benches test
|
||||||
|
|
||||||
|
ndb: ndb.c $(DEPS)
|
||||||
|
$(CC) $(CFLAGS) ndb.c $(LDS) -o $@
|
||||||
|
|
||||||
|
bindings: bindings-swift bindings-rust bindings-c
|
||||||
|
|
||||||
|
check: test $(CHECKDATA)
|
||||||
|
rm -rf testdata/db/*.mdb
|
||||||
|
./test || rm -rf testdata/db/v0
|
||||||
|
rm -rf testdata/db/v0
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf test bench bench-ingest bench-ingest-many
|
||||||
|
|
||||||
|
benches: bench
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
rm -rf deps
|
||||||
|
|
||||||
|
tags:
|
||||||
|
find . -name '*.c' -or -name '*.h' | xargs ctags
|
||||||
|
|
||||||
|
configurator: configurator.c
|
||||||
|
$(CC) $< -o $@
|
||||||
|
|
||||||
|
config.h: configurator
|
||||||
|
./configurator > $@
|
||||||
|
|
||||||
|
bindings-c: $(C_BINDINGS)
|
||||||
|
|
||||||
|
bindings/%/.dir:
|
||||||
|
mkdir -p $(shell dirname $@)
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
bindings/c/%_builder.h: schemas/%.fbs bindings/c/.dir
|
||||||
|
flatcc --builder $< -o bindings/c
|
||||||
|
|
||||||
|
bindings/c/%_verifier.h bindings/c/%_reader.h: schemas/%.fbs bindings/c/.dir
|
||||||
|
flatcc --verifier -o bindings/c $<
|
||||||
|
|
||||||
|
bindings/c/flatbuffers_common_reader.h: bindings/c/.dir
|
||||||
|
flatcc --common_reader -o bindings/c
|
||||||
|
|
||||||
|
bindings/c/flatbuffers_common_builder.h: bindings/c/.dir
|
||||||
|
flatcc --common_builder -o bindings/c
|
||||||
|
|
||||||
|
bindings/c/%_json_parser.h: schemas/%.fbs bindings/c/.dir
|
||||||
|
flatcc --json-parser $< -o bindings/c
|
||||||
|
|
||||||
|
bindings-rust: bindings/rust/ndb_profile.rs bindings/rust/ndb_meta.rs
|
||||||
|
|
||||||
|
bindings/rust/ndb_profile.rs: schemas/profile.fbs bindings/rust
|
||||||
|
flatc --gen-json-emit --rust $<
|
||||||
|
@mv profile_generated.rs $@
|
||||||
|
|
||||||
|
bindings/rust/ndb_meta.rs: schemas/meta.fbs bindings/swift
|
||||||
|
flatc --rust $<
|
||||||
|
@mv meta_generated.rs $@
|
||||||
|
|
||||||
|
bindings-swift: bindings/swift/NdbProfile.swift bindings/swift/NdbMeta.swift
|
||||||
|
|
||||||
|
bindings/swift/NdbProfile.swift: schemas/profile.fbs bindings/swift
|
||||||
|
flatc --gen-json-emit --swift $<
|
||||||
|
@mv profile_generated.swift $@
|
||||||
|
|
||||||
|
bindings/swift/NdbMeta.swift: schemas/meta.fbs bindings/swift
|
||||||
|
flatc --swift $<
|
||||||
|
@mv meta_generated.swift $@
|
||||||
|
|
||||||
|
deps/.dir:
|
||||||
|
@mkdir -p deps
|
||||||
|
touch deps/.dir
|
||||||
|
|
||||||
|
deps/LMDB_$(LMDB_VER).tar.gz: deps/.dir
|
||||||
|
curl -L https://github.com/LMDB/lmdb/archive/refs/tags/LMDB_$(LMDB_VER).tar.gz -o $@
|
||||||
|
|
||||||
|
deps/flatcc_$(FLATCC_VER).tar.gz: deps/.dir
|
||||||
|
curl -L https://github.com/jb55/flatcc/archive/$(FLATCC_VER).tar.gz -o $@
|
||||||
|
|
||||||
|
deps/flatcc/src/runtime/json_parser.c: deps/flatcc_$(FLATCC_VER).tar.gz deps/.dir
|
||||||
|
tar xf $<
|
||||||
|
rm -rf deps/flatcc
|
||||||
|
mv flatcc-$(FLATCC_VER) deps/flatcc
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
deps/lmdb/lmdb.h: deps/LMDB_$(LMDB_VER).tar.gz deps/.dir
|
||||||
|
tar xf $<
|
||||||
|
rm -rf deps/lmdb
|
||||||
|
mv lmdb-LMDB_$(LMDB_VER)/libraries/liblmdb deps/lmdb
|
||||||
|
rm -rf lmdb-LMDB_$(LMDB_VER)
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
deps/secp256k1/.git: deps/.dir
|
||||||
|
@devtools/refresh-submodules.sh $(SUBMODULES)
|
||||||
|
|
||||||
|
deps/secp256k1/include/secp256k1.h: deps/secp256k1/.git
|
||||||
|
|
||||||
|
deps/secp256k1/configure: deps/secp256k1/.git
|
||||||
|
cd deps/secp256k1; \
|
||||||
|
./autogen.sh
|
||||||
|
|
||||||
|
deps/secp256k1/.libs/libsecp256k1.a: deps/secp256k1/config.log
|
||||||
|
cd deps/secp256k1; \
|
||||||
|
make -j libsecp256k1.la
|
||||||
|
|
||||||
|
deps/secp256k1/config.log: deps/secp256k1/configure
|
||||||
|
cd deps/secp256k1; \
|
||||||
|
./configure --disable-shared --enable-module-ecdh --enable-module-schnorrsig --enable-module-extrakeys
|
||||||
|
|
||||||
|
deps/lmdb/liblmdb.a: deps/lmdb/lmdb.h
|
||||||
|
$(MAKE) -C deps/lmdb liblmdb.a
|
||||||
|
|
||||||
|
bench: bench.c $(DEPS)
|
||||||
|
$(CC) $(CFLAGS) bench.c $(LDS) -o $@
|
||||||
|
|
||||||
|
testdata/db/ndb-v0.tar.zst:
|
||||||
|
curl https://cdn.jb55.com/s/ndb-v0.tar.zst -o $@
|
||||||
|
|
||||||
|
testdata/db/ndb-v0.tar: testdata/db/ndb-v0.tar.zst
|
||||||
|
zstd -d < $< > $@
|
||||||
|
|
||||||
|
testdata/db/v0/data.mdb: testdata/db/ndb-v0.tar
|
||||||
|
tar xf $<
|
||||||
|
rm -rf testdata/db/v0
|
||||||
|
mv v0 testdata/db
|
||||||
|
|
||||||
|
testdata/many-events.json.zst:
|
||||||
|
curl https://cdn.jb55.com/s/many-events.json.zst -o $@
|
||||||
|
|
||||||
|
testdata/many-events.json: testdata/many-events.json.zst
|
||||||
|
zstd -d $<
|
||||||
|
|
||||||
|
bench-ingest-many: bench-ingest-many.c $(DEPS) testdata/many-events.json
|
||||||
|
$(CC) $(CFLAGS) $< $(LDS) -o $@
|
||||||
|
|
||||||
|
testdata/db/.dir:
|
||||||
|
@mkdir -p testdata/db
|
||||||
|
touch testdata/db/.dir
|
||||||
|
|
||||||
|
test: test.c $(DEPS) testdata/db/.dir
|
||||||
|
$(CC) $(CFLAGS) test.c $(LDS) -o $@
|
||||||
|
|
||||||
|
.PHONY: tags clean
|
||||||
75
nostrdb/bench-ingest-many.c
Normal file
75
nostrdb/bench-ingest-many.c
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "io.h"
|
||||||
|
#include "nostrdb.h"
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
int map_file(const char *filename, unsigned char **p, size_t *flen)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
int des;
|
||||||
|
stat(filename, &st);
|
||||||
|
*flen = st.st_size;
|
||||||
|
|
||||||
|
des = open(filename, O_RDONLY);
|
||||||
|
|
||||||
|
*p = mmap(NULL, *flen, PROT_READ, MAP_PRIVATE, des, 0);
|
||||||
|
close(des);
|
||||||
|
|
||||||
|
return *p != MAP_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bench_parser()
|
||||||
|
{
|
||||||
|
long nanos, ms;
|
||||||
|
size_t written;
|
||||||
|
struct ndb *ndb;
|
||||||
|
struct timespec t1, t2;
|
||||||
|
char *json;
|
||||||
|
int times = 1;
|
||||||
|
struct ndb_config config;
|
||||||
|
ndb_default_config(&config);
|
||||||
|
|
||||||
|
ndb_config_set_mapsize(&config, 1024ULL * 1024ULL * 400ULL * 10ULL);
|
||||||
|
ndb_config_set_ingest_threads(&config, 8);
|
||||||
|
ndb_config_set_flags(&config, NDB_FLAG_SKIP_NOTE_VERIFY);
|
||||||
|
|
||||||
|
assert(ndb_init(&ndb, "testdata/db", &config));
|
||||||
|
const char *filename = "testdata/many-events.json";
|
||||||
|
if (!map_file(filename, (unsigned char**)&json, &written)) {
|
||||||
|
printf("mapping testdata/many-events.json failed\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("mapped %ld bytes in %s\n", written, filename);
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &t1);
|
||||||
|
|
||||||
|
ndb_process_events(ndb, json, written);
|
||||||
|
|
||||||
|
ndb_destroy(ndb);
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &t2);
|
||||||
|
|
||||||
|
nanos = (t2.tv_sec - t1.tv_sec) * (long)1e9 + (t2.tv_nsec - t1.tv_nsec);
|
||||||
|
ms = nanos / 1e6;
|
||||||
|
printf("ns/run\t%ld\nms/run\t%f\nns\t%ld\nms\t%ld\n",
|
||||||
|
nanos/times, (double)ms/(double)times, nanos, ms);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[], char **env)
|
||||||
|
{
|
||||||
|
if (!bench_parser())
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
51
nostrdb/bench.c
Normal file
51
nostrdb/bench.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
#include "io.h"
|
||||||
|
#include "nostrdb.h"
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static int bench_parser(int times, const char *json, int len)
|
||||||
|
{
|
||||||
|
static unsigned char buf[2<<18];
|
||||||
|
|
||||||
|
struct timespec t1, t2;
|
||||||
|
int i;
|
||||||
|
long nanos, ms;
|
||||||
|
struct ndb_note *note;
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &t1);
|
||||||
|
for (i = 0; i < times; i++) {
|
||||||
|
if (!ndb_note_from_json(json, len, ¬e, buf, sizeof(buf))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &t2);
|
||||||
|
|
||||||
|
nanos = (t2.tv_sec - t1.tv_sec) * (long)1e9 + (t2.tv_nsec - t1.tv_nsec);
|
||||||
|
ms = nanos / 1e6;
|
||||||
|
printf("ns/run\t%ld\nms/run\t%f\nns\t%ld\nms\t%ld\n",
|
||||||
|
nanos/times, (double)ms/(double)times, nanos, ms);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[], char **env)
|
||||||
|
{
|
||||||
|
static const int alloc_size = 2 << 18;
|
||||||
|
int times = 10000, len = 0;
|
||||||
|
unsigned char buf[alloc_size];
|
||||||
|
|
||||||
|
if (!read_file("testdata/contacts.json", buf, alloc_size, &len))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (argc >= 2)
|
||||||
|
times = atoi(argv[1]);
|
||||||
|
|
||||||
|
fprintf(stderr, "benching parser %d times\n", times);
|
||||||
|
if (!bench_parser(times, (const char*)&buf[0], len))
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
/* Common FlatBuffers build functionality for C. */
|
/* Common FlatBuffers build functionality for C. */
|
||||||
|
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
#ifndef FLATBUILDER_H
|
#ifndef FLATBUILDER_H
|
||||||
#include "flatcc_builder.h"
|
#include "flatcc/flatcc_builder.h"
|
||||||
#endif
|
#endif
|
||||||
typedef flatcc_builder_t flatbuffers_builder_t;
|
typedef flatcc_builder_t flatbuffers_builder_t;
|
||||||
typedef flatcc_builder_ref_t flatbuffers_ref_t;
|
typedef flatcc_builder_ref_t flatbuffers_ref_t;
|
||||||
@@ -681,5 +681,5 @@ __flatbuffers_build_scalar(flatbuffers_, flatbuffers_double, double)
|
|||||||
__flatbuffers_build_string(flatbuffers_)
|
__flatbuffers_build_string(flatbuffers_)
|
||||||
|
|
||||||
__flatbuffers_build_buffer(flatbuffers_)
|
__flatbuffers_build_buffer(flatbuffers_)
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* FLATBUFFERS_COMMON_BUILDER_H */
|
#endif /* FLATBUFFERS_COMMON_BUILDER_H */
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
/* Common FlatBuffers read functionality for C. */
|
/* Common FlatBuffers read functionality for C. */
|
||||||
|
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
#include "flatcc_flatbuffers.h"
|
#include "flatcc/flatcc_flatbuffers.h"
|
||||||
|
|
||||||
|
|
||||||
#define __flatbuffers_read_scalar_at_byteoffset(N, p, o) N ## _read_from_pe((uint8_t *)(p) + (o))
|
#define __flatbuffers_read_scalar_at_byteoffset(N, p, o) N ## _read_from_pe((uint8_t *)(p) + (o))
|
||||||
@@ -574,5 +574,5 @@ static inline N ## _ ## K ## t N ## _as_typed_root(const void *buffer__tmp)\
|
|||||||
#define __flatbuffers_struct_as_root(N) __flatbuffers_buffer_as_root(N, struct_)
|
#define __flatbuffers_struct_as_root(N) __flatbuffers_buffer_as_root(N, struct_)
|
||||||
#define __flatbuffers_table_as_root(N) __flatbuffers_buffer_as_root(N, table_)
|
#define __flatbuffers_table_as_root(N) __flatbuffers_buffer_as_root(N, table_)
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* FLATBUFFERS_COMMON_H */
|
#endif /* FLATBUFFERS_COMMON_H */
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#ifndef FLATBUFFERS_COMMON_BUILDER_H
|
#ifndef FLATBUFFERS_COMMON_BUILDER_H
|
||||||
#include "flatbuffers_common_builder.h"
|
#include "flatbuffers_common_builder.h"
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
#ifndef flatbuffers_identifier
|
#ifndef flatbuffers_identifier
|
||||||
#define flatbuffers_identifier 0
|
#define flatbuffers_identifier 0
|
||||||
#endif
|
#endif
|
||||||
@@ -65,5 +65,5 @@ static NdbEventMeta_ref_t NdbEventMeta_clone(flatbuffers_builder_t *B, NdbEventM
|
|||||||
__flatbuffers_memoize_end(B, t, NdbEventMeta_end(B));
|
__flatbuffers_memoize_end(B, t, NdbEventMeta_end(B));
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* META_BUILDER_H */
|
#endif /* META_BUILDER_H */
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */
|
/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */
|
||||||
|
|
||||||
#include "flatcc_json_parser.h"
|
#include "flatcc/flatcc_json_parser.h"
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parses the default root table or struct of the schema and constructs a FlatBuffer.
|
* Parses the default root table or struct of the schema and constructs a FlatBuffer.
|
||||||
@@ -246,5 +246,5 @@ static int meta_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* META_JSON_PARSER_H */
|
#endif /* META_JSON_PARSER_H */
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
#ifndef FLATBUFFERS_COMMON_READER_H
|
#ifndef FLATBUFFERS_COMMON_READER_H
|
||||||
#include "flatbuffers_common_reader.h"
|
#include "flatbuffers_common_reader.h"
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_flatbuffers.h"
|
#include "flatcc/flatcc_flatbuffers.h"
|
||||||
#ifndef __alignas_is_defined
|
#ifndef __alignas_is_defined
|
||||||
#include <stdalign.h>
|
#include <stdalign.h>
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
#ifndef flatbuffers_identifier
|
#ifndef flatbuffers_identifier
|
||||||
#define flatbuffers_identifier 0
|
#define flatbuffers_identifier 0
|
||||||
#endif
|
#endif
|
||||||
@@ -54,5 +54,5 @@ __flatbuffers_define_scalar_field(4, NdbEventMeta, zaps, flatbuffers_int32, int3
|
|||||||
__flatbuffers_define_scalar_field(5, NdbEventMeta, zap_total, flatbuffers_int64, int64_t, INT64_C(0))
|
__flatbuffers_define_scalar_field(5, NdbEventMeta, zap_total, flatbuffers_int64, int64_t, INT64_C(0))
|
||||||
|
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* META_READER_H */
|
#endif /* META_READER_H */
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
#ifndef META_READER_H
|
#ifndef META_READER_H
|
||||||
#include "meta_reader.h"
|
#include "meta_reader.h"
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_verifier.h"
|
#include "flatcc/flatcc_verifier.h"
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
|
|
||||||
static int NdbEventMeta_verify_table(flatcc_table_verifier_descriptor_t *td);
|
static int NdbEventMeta_verify_table(flatcc_table_verifier_descriptor_t *td);
|
||||||
|
|
||||||
@@ -43,5 +43,5 @@ static inline int NdbEventMeta_verify_as_root_with_type_hash(const void *buf, si
|
|||||||
return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &NdbEventMeta_verify_table);
|
return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &NdbEventMeta_verify_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* META_VERIFIER_H */
|
#endif /* META_VERIFIER_H */
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#ifndef FLATBUFFERS_COMMON_BUILDER_H
|
#ifndef FLATBUFFERS_COMMON_BUILDER_H
|
||||||
#include "flatbuffers_common_builder.h"
|
#include "flatbuffers_common_builder.h"
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
#ifndef flatbuffers_identifier
|
#ifndef flatbuffers_identifier
|
||||||
#define flatbuffers_identifier 0
|
#define flatbuffers_identifier 0
|
||||||
#endif
|
#endif
|
||||||
@@ -127,5 +127,5 @@ static NdbProfileRecord_ref_t NdbProfileRecord_clone(flatbuffers_builder_t *B, N
|
|||||||
__flatbuffers_memoize_end(B, t, NdbProfileRecord_end(B));
|
__flatbuffers_memoize_end(B, t, NdbProfileRecord_end(B));
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* PROFILE_BUILDER_H */
|
#endif /* PROFILE_BUILDER_H */
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */
|
/* Generated by flatcc 0.6.1 FlatBuffers schema compiler for C by dvide.com */
|
||||||
|
|
||||||
#include "flatcc_json_parser.h"
|
#include "flatcc/flatcc_json_parser.h"
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parses the default root table or struct of the schema and constructs a FlatBuffer.
|
* Parses the default root table or struct of the schema and constructs a FlatBuffer.
|
||||||
@@ -408,5 +408,5 @@ static int profile_parse_json(flatcc_builder_t *B, flatcc_json_parser_t *ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* PROFILE_JSON_PARSER_H */
|
#endif /* PROFILE_JSON_PARSER_H */
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
#ifndef FLATBUFFERS_COMMON_READER_H
|
#ifndef FLATBUFFERS_COMMON_READER_H
|
||||||
#include "flatbuffers_common_reader.h"
|
#include "flatbuffers_common_reader.h"
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_flatbuffers.h"
|
#include "flatcc/flatcc_flatbuffers.h"
|
||||||
#ifndef __alignas_is_defined
|
#ifndef __alignas_is_defined
|
||||||
#include <stdalign.h>
|
#include <stdalign.h>
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
#ifndef flatbuffers_identifier
|
#ifndef flatbuffers_identifier
|
||||||
#define flatbuffers_identifier 0
|
#define flatbuffers_identifier 0
|
||||||
#endif
|
#endif
|
||||||
@@ -89,5 +89,5 @@ __flatbuffers_define_scalar_field(2, NdbProfileRecord, note_key, flatbuffers_uin
|
|||||||
__flatbuffers_define_string_field(3, NdbProfileRecord, lnurl, 0)
|
__flatbuffers_define_string_field(3, NdbProfileRecord, lnurl, 0)
|
||||||
|
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* PROFILE_READER_H */
|
#endif /* PROFILE_READER_H */
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
#ifndef PROFILE_READER_H
|
#ifndef PROFILE_READER_H
|
||||||
#include "profile_reader.h"
|
#include "profile_reader.h"
|
||||||
#endif
|
#endif
|
||||||
#include "flatcc_verifier.h"
|
#include "flatcc/flatcc_verifier.h"
|
||||||
#include "flatcc_prologue.h"
|
#include "flatcc/flatcc_prologue.h"
|
||||||
|
|
||||||
static int NdbProfile_verify_table(flatcc_table_verifier_descriptor_t *td);
|
static int NdbProfile_verify_table(flatcc_table_verifier_descriptor_t *td);
|
||||||
static int NdbProfileRecord_verify_table(flatcc_table_verifier_descriptor_t *td);
|
static int NdbProfileRecord_verify_table(flatcc_table_verifier_descriptor_t *td);
|
||||||
@@ -80,5 +80,5 @@ static inline int NdbProfileRecord_verify_as_root_with_type_hash(const void *buf
|
|||||||
return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &NdbProfileRecord_verify_table);
|
return flatcc_verify_table_as_typed_root(buf, bufsiz, thash, &NdbProfileRecord_verify_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "flatcc_epilogue.h"
|
#include "flatcc/flatcc_epilogue.h"
|
||||||
#endif /* PROFILE_VERIFIER_H */
|
#endif /* PROFILE_VERIFIER_H */
|
||||||
|
|||||||
0
nostrdb/bindings/rust/.dir
Normal file
0
nostrdb/bindings/rust/.dir
Normal file
264
nostrdb/bindings/rust/ndb_meta.rs
Normal file
264
nostrdb/bindings/rust/ndb_meta.rs
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
// @generated
|
||||||
|
|
||||||
|
use core::mem;
|
||||||
|
use core::cmp::Ordering;
|
||||||
|
|
||||||
|
extern crate flatbuffers;
|
||||||
|
use self::flatbuffers::{EndianScalar, Follow};
|
||||||
|
|
||||||
|
pub enum NdbEventMetaOffset {}
|
||||||
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
|
|
||||||
|
pub struct NdbEventMeta<'a> {
|
||||||
|
pub _tab: flatbuffers::Table<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> flatbuffers::Follow<'a> for NdbEventMeta<'a> {
|
||||||
|
type Inner = NdbEventMeta<'a>;
|
||||||
|
#[inline]
|
||||||
|
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||||
|
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NdbEventMeta<'a> {
|
||||||
|
pub const VT_RECEIVED_AT: flatbuffers::VOffsetT = 4;
|
||||||
|
pub const VT_REACTIONS: flatbuffers::VOffsetT = 6;
|
||||||
|
pub const VT_QUOTES: flatbuffers::VOffsetT = 8;
|
||||||
|
pub const VT_REPOSTS: flatbuffers::VOffsetT = 10;
|
||||||
|
pub const VT_ZAPS: flatbuffers::VOffsetT = 12;
|
||||||
|
pub const VT_ZAP_TOTAL: flatbuffers::VOffsetT = 14;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||||
|
NdbEventMeta { _tab: table }
|
||||||
|
}
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||||
|
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||||
|
args: &'args NdbEventMetaArgs
|
||||||
|
) -> flatbuffers::WIPOffset<NdbEventMeta<'bldr>> {
|
||||||
|
let mut builder = NdbEventMetaBuilder::new(_fbb);
|
||||||
|
builder.add_zap_total(args.zap_total);
|
||||||
|
builder.add_zaps(args.zaps);
|
||||||
|
builder.add_reposts(args.reposts);
|
||||||
|
builder.add_quotes(args.quotes);
|
||||||
|
builder.add_reactions(args.reactions);
|
||||||
|
builder.add_received_at(args.received_at);
|
||||||
|
builder.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn received_at(&self) -> i32 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i32>(NdbEventMeta::VT_RECEIVED_AT, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn reactions(&self) -> i32 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i32>(NdbEventMeta::VT_REACTIONS, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn quotes(&self) -> i32 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i32>(NdbEventMeta::VT_QUOTES, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn reposts(&self) -> i32 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i32>(NdbEventMeta::VT_REPOSTS, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn zaps(&self) -> i32 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i32>(NdbEventMeta::VT_ZAPS, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn zap_total(&self) -> i64 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i64>(NdbEventMeta::VT_ZAP_TOTAL, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl flatbuffers::Verifiable for NdbEventMeta<'_> {
|
||||||
|
#[inline]
|
||||||
|
fn run_verifier(
|
||||||
|
v: &mut flatbuffers::Verifier, pos: usize
|
||||||
|
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||||
|
use self::flatbuffers::Verifiable;
|
||||||
|
v.visit_table(pos)?
|
||||||
|
.visit_field::<i32>("received_at", Self::VT_RECEIVED_AT, false)?
|
||||||
|
.visit_field::<i32>("reactions", Self::VT_REACTIONS, false)?
|
||||||
|
.visit_field::<i32>("quotes", Self::VT_QUOTES, false)?
|
||||||
|
.visit_field::<i32>("reposts", Self::VT_REPOSTS, false)?
|
||||||
|
.visit_field::<i32>("zaps", Self::VT_ZAPS, false)?
|
||||||
|
.visit_field::<i64>("zap_total", Self::VT_ZAP_TOTAL, false)?
|
||||||
|
.finish();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct NdbEventMetaArgs {
|
||||||
|
pub received_at: i32,
|
||||||
|
pub reactions: i32,
|
||||||
|
pub quotes: i32,
|
||||||
|
pub reposts: i32,
|
||||||
|
pub zaps: i32,
|
||||||
|
pub zap_total: i64,
|
||||||
|
}
|
||||||
|
impl<'a> Default for NdbEventMetaArgs {
|
||||||
|
#[inline]
|
||||||
|
fn default() -> Self {
|
||||||
|
NdbEventMetaArgs {
|
||||||
|
received_at: 0,
|
||||||
|
reactions: 0,
|
||||||
|
quotes: 0,
|
||||||
|
reposts: 0,
|
||||||
|
zaps: 0,
|
||||||
|
zap_total: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NdbEventMetaBuilder<'a: 'b, 'b> {
|
||||||
|
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||||
|
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||||
|
}
|
||||||
|
impl<'a: 'b, 'b> NdbEventMetaBuilder<'a, 'b> {
|
||||||
|
#[inline]
|
||||||
|
pub fn add_received_at(&mut self, received_at: i32) {
|
||||||
|
self.fbb_.push_slot::<i32>(NdbEventMeta::VT_RECEIVED_AT, received_at, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_reactions(&mut self, reactions: i32) {
|
||||||
|
self.fbb_.push_slot::<i32>(NdbEventMeta::VT_REACTIONS, reactions, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_quotes(&mut self, quotes: i32) {
|
||||||
|
self.fbb_.push_slot::<i32>(NdbEventMeta::VT_QUOTES, quotes, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_reposts(&mut self, reposts: i32) {
|
||||||
|
self.fbb_.push_slot::<i32>(NdbEventMeta::VT_REPOSTS, reposts, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_zaps(&mut self, zaps: i32) {
|
||||||
|
self.fbb_.push_slot::<i32>(NdbEventMeta::VT_ZAPS, zaps, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_zap_total(&mut self, zap_total: i64) {
|
||||||
|
self.fbb_.push_slot::<i64>(NdbEventMeta::VT_ZAP_TOTAL, zap_total, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> NdbEventMetaBuilder<'a, 'b> {
|
||||||
|
let start = _fbb.start_table();
|
||||||
|
NdbEventMetaBuilder {
|
||||||
|
fbb_: _fbb,
|
||||||
|
start_: start,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn finish(self) -> flatbuffers::WIPOffset<NdbEventMeta<'a>> {
|
||||||
|
let o = self.fbb_.end_table(self.start_);
|
||||||
|
flatbuffers::WIPOffset::new(o.value())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for NdbEventMeta<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
let mut ds = f.debug_struct("NdbEventMeta");
|
||||||
|
ds.field("received_at", &self.received_at());
|
||||||
|
ds.field("reactions", &self.reactions());
|
||||||
|
ds.field("quotes", &self.quotes());
|
||||||
|
ds.field("reposts", &self.reposts());
|
||||||
|
ds.field("zaps", &self.zaps());
|
||||||
|
ds.field("zap_total", &self.zap_total());
|
||||||
|
ds.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies that a buffer of bytes contains a `NdbEventMeta`
|
||||||
|
/// and returns it.
|
||||||
|
/// Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `root_as_ndb_event_meta_unchecked`.
|
||||||
|
pub fn root_as_ndb_event_meta(buf: &[u8]) -> Result<NdbEventMeta, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::root::<NdbEventMeta>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies that a buffer of bytes contains a size prefixed
|
||||||
|
/// `NdbEventMeta` and returns it.
|
||||||
|
/// Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `size_prefixed_root_as_ndb_event_meta_unchecked`.
|
||||||
|
pub fn size_prefixed_root_as_ndb_event_meta(buf: &[u8]) -> Result<NdbEventMeta, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::size_prefixed_root::<NdbEventMeta>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies, with the given options, that a buffer of bytes
|
||||||
|
/// contains a `NdbEventMeta` and returns it.
|
||||||
|
/// Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `root_as_ndb_event_meta_unchecked`.
|
||||||
|
pub fn root_as_ndb_event_meta_with_opts<'b, 'o>(
|
||||||
|
opts: &'o flatbuffers::VerifierOptions,
|
||||||
|
buf: &'b [u8],
|
||||||
|
) -> Result<NdbEventMeta<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::root_with_opts::<NdbEventMeta<'b>>(opts, buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies, with the given verifier options, that a buffer of
|
||||||
|
/// bytes contains a size prefixed `NdbEventMeta` and returns
|
||||||
|
/// it. Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `root_as_ndb_event_meta_unchecked`.
|
||||||
|
pub fn size_prefixed_root_as_ndb_event_meta_with_opts<'b, 'o>(
|
||||||
|
opts: &'o flatbuffers::VerifierOptions,
|
||||||
|
buf: &'b [u8],
|
||||||
|
) -> Result<NdbEventMeta<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::size_prefixed_root_with_opts::<NdbEventMeta<'b>>(opts, buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Assumes, without verification, that a buffer of bytes contains a NdbEventMeta and returns it.
|
||||||
|
/// # Safety
|
||||||
|
/// Callers must trust the given bytes do indeed contain a valid `NdbEventMeta`.
|
||||||
|
pub unsafe fn root_as_ndb_event_meta_unchecked(buf: &[u8]) -> NdbEventMeta {
|
||||||
|
flatbuffers::root_unchecked::<NdbEventMeta>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Assumes, without verification, that a buffer of bytes contains a size prefixed NdbEventMeta and returns it.
|
||||||
|
/// # Safety
|
||||||
|
/// Callers must trust the given bytes do indeed contain a valid size prefixed `NdbEventMeta`.
|
||||||
|
pub unsafe fn size_prefixed_root_as_ndb_event_meta_unchecked(buf: &[u8]) -> NdbEventMeta {
|
||||||
|
flatbuffers::size_prefixed_root_unchecked::<NdbEventMeta>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn finish_ndb_event_meta_buffer<'a, 'b>(
|
||||||
|
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||||
|
root: flatbuffers::WIPOffset<NdbEventMeta<'a>>) {
|
||||||
|
fbb.finish(root, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn finish_size_prefixed_ndb_event_meta_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<NdbEventMeta<'a>>) {
|
||||||
|
fbb.finish_size_prefixed(root, None);
|
||||||
|
}
|
||||||
514
nostrdb/bindings/rust/ndb_profile.rs
Normal file
514
nostrdb/bindings/rust/ndb_profile.rs
Normal file
@@ -0,0 +1,514 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
// @generated
|
||||||
|
|
||||||
|
use core::mem;
|
||||||
|
use core::cmp::Ordering;
|
||||||
|
|
||||||
|
extern crate flatbuffers;
|
||||||
|
use self::flatbuffers::{EndianScalar, Follow};
|
||||||
|
|
||||||
|
pub enum NdbProfileOffset {}
|
||||||
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
|
|
||||||
|
pub struct NdbProfile<'a> {
|
||||||
|
pub _tab: flatbuffers::Table<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> flatbuffers::Follow<'a> for NdbProfile<'a> {
|
||||||
|
type Inner = NdbProfile<'a>;
|
||||||
|
#[inline]
|
||||||
|
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||||
|
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NdbProfile<'a> {
|
||||||
|
pub const VT_NAME: flatbuffers::VOffsetT = 4;
|
||||||
|
pub const VT_WEBSITE: flatbuffers::VOffsetT = 6;
|
||||||
|
pub const VT_ABOUT: flatbuffers::VOffsetT = 8;
|
||||||
|
pub const VT_LUD16: flatbuffers::VOffsetT = 10;
|
||||||
|
pub const VT_BANNER: flatbuffers::VOffsetT = 12;
|
||||||
|
pub const VT_DISPLAY_NAME: flatbuffers::VOffsetT = 14;
|
||||||
|
pub const VT_REACTIONS: flatbuffers::VOffsetT = 16;
|
||||||
|
pub const VT_PICTURE: flatbuffers::VOffsetT = 18;
|
||||||
|
pub const VT_NIP05: flatbuffers::VOffsetT = 20;
|
||||||
|
pub const VT_DAMUS_DONATION: flatbuffers::VOffsetT = 22;
|
||||||
|
pub const VT_DAMUS_DONATION_V2: flatbuffers::VOffsetT = 24;
|
||||||
|
pub const VT_LUD06: flatbuffers::VOffsetT = 26;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||||
|
NdbProfile { _tab: table }
|
||||||
|
}
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||||
|
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||||
|
args: &'args NdbProfileArgs<'args>
|
||||||
|
) -> flatbuffers::WIPOffset<NdbProfile<'bldr>> {
|
||||||
|
let mut builder = NdbProfileBuilder::new(_fbb);
|
||||||
|
if let Some(x) = args.lud06 { builder.add_lud06(x); }
|
||||||
|
builder.add_damus_donation_v2(args.damus_donation_v2);
|
||||||
|
builder.add_damus_donation(args.damus_donation);
|
||||||
|
if let Some(x) = args.nip05 { builder.add_nip05(x); }
|
||||||
|
if let Some(x) = args.picture { builder.add_picture(x); }
|
||||||
|
if let Some(x) = args.display_name { builder.add_display_name(x); }
|
||||||
|
if let Some(x) = args.banner { builder.add_banner(x); }
|
||||||
|
if let Some(x) = args.lud16 { builder.add_lud16(x); }
|
||||||
|
if let Some(x) = args.about { builder.add_about(x); }
|
||||||
|
if let Some(x) = args.website { builder.add_website(x); }
|
||||||
|
if let Some(x) = args.name { builder.add_name(x); }
|
||||||
|
builder.add_reactions(args.reactions);
|
||||||
|
builder.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn name(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_NAME, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn website(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_WEBSITE, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn about(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_ABOUT, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn lud16(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_LUD16, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn banner(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_BANNER, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn display_name(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_DISPLAY_NAME, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn reactions(&self) -> bool {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<bool>(NdbProfile::VT_REACTIONS, Some(true)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn picture(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_PICTURE, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn nip05(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_NIP05, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn damus_donation(&self) -> i32 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i32>(NdbProfile::VT_DAMUS_DONATION, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn damus_donation_v2(&self) -> i32 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<i32>(NdbProfile::VT_DAMUS_DONATION_V2, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn lud06(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfile::VT_LUD06, None)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl flatbuffers::Verifiable for NdbProfile<'_> {
|
||||||
|
#[inline]
|
||||||
|
fn run_verifier(
|
||||||
|
v: &mut flatbuffers::Verifier, pos: usize
|
||||||
|
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||||
|
use self::flatbuffers::Verifiable;
|
||||||
|
v.visit_table(pos)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("name", Self::VT_NAME, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("website", Self::VT_WEBSITE, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("about", Self::VT_ABOUT, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("lud16", Self::VT_LUD16, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("banner", Self::VT_BANNER, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("display_name", Self::VT_DISPLAY_NAME, false)?
|
||||||
|
.visit_field::<bool>("reactions", Self::VT_REACTIONS, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("picture", Self::VT_PICTURE, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("nip05", Self::VT_NIP05, false)?
|
||||||
|
.visit_field::<i32>("damus_donation", Self::VT_DAMUS_DONATION, false)?
|
||||||
|
.visit_field::<i32>("damus_donation_v2", Self::VT_DAMUS_DONATION_V2, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("lud06", Self::VT_LUD06, false)?
|
||||||
|
.finish();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct NdbProfileArgs<'a> {
|
||||||
|
pub name: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub website: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub about: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub lud16: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub banner: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub display_name: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub reactions: bool,
|
||||||
|
pub picture: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub nip05: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
pub damus_donation: i32,
|
||||||
|
pub damus_donation_v2: i32,
|
||||||
|
pub lud06: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
}
|
||||||
|
impl<'a> Default for NdbProfileArgs<'a> {
|
||||||
|
#[inline]
|
||||||
|
fn default() -> Self {
|
||||||
|
NdbProfileArgs {
|
||||||
|
name: None,
|
||||||
|
website: None,
|
||||||
|
about: None,
|
||||||
|
lud16: None,
|
||||||
|
banner: None,
|
||||||
|
display_name: None,
|
||||||
|
reactions: true,
|
||||||
|
picture: None,
|
||||||
|
nip05: None,
|
||||||
|
damus_donation: 0,
|
||||||
|
damus_donation_v2: 0,
|
||||||
|
lud06: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NdbProfileBuilder<'a: 'b, 'b> {
|
||||||
|
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||||
|
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||||
|
}
|
||||||
|
impl<'a: 'b, 'b> NdbProfileBuilder<'a, 'b> {
|
||||||
|
#[inline]
|
||||||
|
pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_NAME, name);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_website(&mut self, website: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_WEBSITE, website);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_about(&mut self, about: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_ABOUT, about);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_lud16(&mut self, lud16: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_LUD16, lud16);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_banner(&mut self, banner: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_BANNER, banner);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_display_name(&mut self, display_name: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_DISPLAY_NAME, display_name);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_reactions(&mut self, reactions: bool) {
|
||||||
|
self.fbb_.push_slot::<bool>(NdbProfile::VT_REACTIONS, reactions, true);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_picture(&mut self, picture: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_PICTURE, picture);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_nip05(&mut self, nip05: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_NIP05, nip05);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_damus_donation(&mut self, damus_donation: i32) {
|
||||||
|
self.fbb_.push_slot::<i32>(NdbProfile::VT_DAMUS_DONATION, damus_donation, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_damus_donation_v2(&mut self, damus_donation_v2: i32) {
|
||||||
|
self.fbb_.push_slot::<i32>(NdbProfile::VT_DAMUS_DONATION_V2, damus_donation_v2, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_lud06(&mut self, lud06: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfile::VT_LUD06, lud06);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> NdbProfileBuilder<'a, 'b> {
|
||||||
|
let start = _fbb.start_table();
|
||||||
|
NdbProfileBuilder {
|
||||||
|
fbb_: _fbb,
|
||||||
|
start_: start,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn finish(self) -> flatbuffers::WIPOffset<NdbProfile<'a>> {
|
||||||
|
let o = self.fbb_.end_table(self.start_);
|
||||||
|
flatbuffers::WIPOffset::new(o.value())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for NdbProfile<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
let mut ds = f.debug_struct("NdbProfile");
|
||||||
|
ds.field("name", &self.name());
|
||||||
|
ds.field("website", &self.website());
|
||||||
|
ds.field("about", &self.about());
|
||||||
|
ds.field("lud16", &self.lud16());
|
||||||
|
ds.field("banner", &self.banner());
|
||||||
|
ds.field("display_name", &self.display_name());
|
||||||
|
ds.field("reactions", &self.reactions());
|
||||||
|
ds.field("picture", &self.picture());
|
||||||
|
ds.field("nip05", &self.nip05());
|
||||||
|
ds.field("damus_donation", &self.damus_donation());
|
||||||
|
ds.field("damus_donation_v2", &self.damus_donation_v2());
|
||||||
|
ds.field("lud06", &self.lud06());
|
||||||
|
ds.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub enum NdbProfileRecordOffset {}
|
||||||
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
|
|
||||||
|
pub struct NdbProfileRecord<'a> {
|
||||||
|
pub _tab: flatbuffers::Table<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> flatbuffers::Follow<'a> for NdbProfileRecord<'a> {
|
||||||
|
type Inner = NdbProfileRecord<'a>;
|
||||||
|
#[inline]
|
||||||
|
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||||
|
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> NdbProfileRecord<'a> {
|
||||||
|
pub const VT_PROFILE: flatbuffers::VOffsetT = 4;
|
||||||
|
pub const VT_RECEIVED_AT: flatbuffers::VOffsetT = 6;
|
||||||
|
pub const VT_NOTE_KEY: flatbuffers::VOffsetT = 8;
|
||||||
|
pub const VT_LNURL: flatbuffers::VOffsetT = 10;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||||
|
NdbProfileRecord { _tab: table }
|
||||||
|
}
|
||||||
|
#[allow(unused_mut)]
|
||||||
|
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||||
|
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||||
|
args: &'args NdbProfileRecordArgs<'args>
|
||||||
|
) -> flatbuffers::WIPOffset<NdbProfileRecord<'bldr>> {
|
||||||
|
let mut builder = NdbProfileRecordBuilder::new(_fbb);
|
||||||
|
builder.add_note_key(args.note_key);
|
||||||
|
builder.add_received_at(args.received_at);
|
||||||
|
if let Some(x) = args.lnurl { builder.add_lnurl(x); }
|
||||||
|
if let Some(x) = args.profile { builder.add_profile(x); }
|
||||||
|
builder.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn profile(&self) -> Option<NdbProfile<'a>> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<NdbProfile>>(NdbProfileRecord::VT_PROFILE, None)}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn received_at(&self) -> u64 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<u64>(NdbProfileRecord::VT_RECEIVED_AT, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn note_key(&self) -> u64 {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<u64>(NdbProfileRecord::VT_NOTE_KEY, Some(0)).unwrap()}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn lnurl(&self) -> Option<&'a str> {
|
||||||
|
// Safety:
|
||||||
|
// Created from valid Table for this object
|
||||||
|
// which contains a valid value in this slot
|
||||||
|
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(NdbProfileRecord::VT_LNURL, None)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl flatbuffers::Verifiable for NdbProfileRecord<'_> {
|
||||||
|
#[inline]
|
||||||
|
fn run_verifier(
|
||||||
|
v: &mut flatbuffers::Verifier, pos: usize
|
||||||
|
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||||
|
use self::flatbuffers::Verifiable;
|
||||||
|
v.visit_table(pos)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<NdbProfile>>("profile", Self::VT_PROFILE, false)?
|
||||||
|
.visit_field::<u64>("received_at", Self::VT_RECEIVED_AT, false)?
|
||||||
|
.visit_field::<u64>("note_key", Self::VT_NOTE_KEY, false)?
|
||||||
|
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("lnurl", Self::VT_LNURL, false)?
|
||||||
|
.finish();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct NdbProfileRecordArgs<'a> {
|
||||||
|
pub profile: Option<flatbuffers::WIPOffset<NdbProfile<'a>>>,
|
||||||
|
pub received_at: u64,
|
||||||
|
pub note_key: u64,
|
||||||
|
pub lnurl: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||||
|
}
|
||||||
|
impl<'a> Default for NdbProfileRecordArgs<'a> {
|
||||||
|
#[inline]
|
||||||
|
fn default() -> Self {
|
||||||
|
NdbProfileRecordArgs {
|
||||||
|
profile: None,
|
||||||
|
received_at: 0,
|
||||||
|
note_key: 0,
|
||||||
|
lnurl: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NdbProfileRecordBuilder<'a: 'b, 'b> {
|
||||||
|
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||||
|
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||||
|
}
|
||||||
|
impl<'a: 'b, 'b> NdbProfileRecordBuilder<'a, 'b> {
|
||||||
|
#[inline]
|
||||||
|
pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset<NdbProfile<'b >>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<NdbProfile>>(NdbProfileRecord::VT_PROFILE, profile);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_received_at(&mut self, received_at: u64) {
|
||||||
|
self.fbb_.push_slot::<u64>(NdbProfileRecord::VT_RECEIVED_AT, received_at, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_note_key(&mut self, note_key: u64) {
|
||||||
|
self.fbb_.push_slot::<u64>(NdbProfileRecord::VT_NOTE_KEY, note_key, 0);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn add_lnurl(&mut self, lnurl: flatbuffers::WIPOffset<&'b str>) {
|
||||||
|
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(NdbProfileRecord::VT_LNURL, lnurl);
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> NdbProfileRecordBuilder<'a, 'b> {
|
||||||
|
let start = _fbb.start_table();
|
||||||
|
NdbProfileRecordBuilder {
|
||||||
|
fbb_: _fbb,
|
||||||
|
start_: start,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn finish(self) -> flatbuffers::WIPOffset<NdbProfileRecord<'a>> {
|
||||||
|
let o = self.fbb_.end_table(self.start_);
|
||||||
|
flatbuffers::WIPOffset::new(o.value())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for NdbProfileRecord<'_> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
let mut ds = f.debug_struct("NdbProfileRecord");
|
||||||
|
ds.field("profile", &self.profile());
|
||||||
|
ds.field("received_at", &self.received_at());
|
||||||
|
ds.field("note_key", &self.note_key());
|
||||||
|
ds.field("lnurl", &self.lnurl());
|
||||||
|
ds.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies that a buffer of bytes contains a `NdbProfileRecord`
|
||||||
|
/// and returns it.
|
||||||
|
/// Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `root_as_ndb_profile_record_unchecked`.
|
||||||
|
pub fn root_as_ndb_profile_record(buf: &[u8]) -> Result<NdbProfileRecord, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::root::<NdbProfileRecord>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies that a buffer of bytes contains a size prefixed
|
||||||
|
/// `NdbProfileRecord` and returns it.
|
||||||
|
/// Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `size_prefixed_root_as_ndb_profile_record_unchecked`.
|
||||||
|
pub fn size_prefixed_root_as_ndb_profile_record(buf: &[u8]) -> Result<NdbProfileRecord, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::size_prefixed_root::<NdbProfileRecord>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies, with the given options, that a buffer of bytes
|
||||||
|
/// contains a `NdbProfileRecord` and returns it.
|
||||||
|
/// Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `root_as_ndb_profile_record_unchecked`.
|
||||||
|
pub fn root_as_ndb_profile_record_with_opts<'b, 'o>(
|
||||||
|
opts: &'o flatbuffers::VerifierOptions,
|
||||||
|
buf: &'b [u8],
|
||||||
|
) -> Result<NdbProfileRecord<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::root_with_opts::<NdbProfileRecord<'b>>(opts, buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Verifies, with the given verifier options, that a buffer of
|
||||||
|
/// bytes contains a size prefixed `NdbProfileRecord` and returns
|
||||||
|
/// it. Note that verification is still experimental and may not
|
||||||
|
/// catch every error, or be maximally performant. For the
|
||||||
|
/// previous, unchecked, behavior use
|
||||||
|
/// `root_as_ndb_profile_record_unchecked`.
|
||||||
|
pub fn size_prefixed_root_as_ndb_profile_record_with_opts<'b, 'o>(
|
||||||
|
opts: &'o flatbuffers::VerifierOptions,
|
||||||
|
buf: &'b [u8],
|
||||||
|
) -> Result<NdbProfileRecord<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||||
|
flatbuffers::size_prefixed_root_with_opts::<NdbProfileRecord<'b>>(opts, buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Assumes, without verification, that a buffer of bytes contains a NdbProfileRecord and returns it.
|
||||||
|
/// # Safety
|
||||||
|
/// Callers must trust the given bytes do indeed contain a valid `NdbProfileRecord`.
|
||||||
|
pub unsafe fn root_as_ndb_profile_record_unchecked(buf: &[u8]) -> NdbProfileRecord {
|
||||||
|
flatbuffers::root_unchecked::<NdbProfileRecord>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Assumes, without verification, that a buffer of bytes contains a size prefixed NdbProfileRecord and returns it.
|
||||||
|
/// # Safety
|
||||||
|
/// Callers must trust the given bytes do indeed contain a valid size prefixed `NdbProfileRecord`.
|
||||||
|
pub unsafe fn size_prefixed_root_as_ndb_profile_record_unchecked(buf: &[u8]) -> NdbProfileRecord {
|
||||||
|
flatbuffers::size_prefixed_root_unchecked::<NdbProfileRecord>(buf)
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn finish_ndb_profile_record_buffer<'a, 'b>(
|
||||||
|
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||||
|
root: flatbuffers::WIPOffset<NdbProfileRecord<'a>>) {
|
||||||
|
fbb.finish(root, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn finish_size_prefixed_ndb_profile_record_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<NdbProfileRecord<'a>>) {
|
||||||
|
fbb.finish_size_prefixed(root, None);
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// swiftlint:disable all
|
// swiftlint:disable all
|
||||||
// swiftformat:disable all
|
// swiftformat:disable all
|
||||||
|
|
||||||
|
import FlatBuffers
|
||||||
|
|
||||||
public struct NdbProfile: FlatBufferObject, Verifiable {
|
public struct NdbProfile: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
|
|||||||
217
nostrdb/bolt11/bech32.c
Normal file
217
nostrdb/bolt11/bech32.c
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
/* Stolen from https://github.com/sipa/bech32/blob/master/ref/c/segwit_addr.c,
|
||||||
|
* with only the two ' > 90' checks hoisted, and more internals exposed */
|
||||||
|
|
||||||
|
/* Copyright (c) 2017, 2021 Pieter Wuille
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "../config.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include "bech32.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static uint32_t bech32_polymod_step(uint32_t pre) {
|
||||||
|
uint8_t b = pre >> 25;
|
||||||
|
return ((pre & 0x1FFFFFF) << 5) ^
|
||||||
|
(-((b >> 0) & 1) & 0x3b6a57b2UL) ^
|
||||||
|
(-((b >> 1) & 1) & 0x26508e6dUL) ^
|
||||||
|
(-((b >> 2) & 1) & 0x1ea119faUL) ^
|
||||||
|
(-((b >> 3) & 1) & 0x3d4233ddUL) ^
|
||||||
|
(-((b >> 4) & 1) & 0x2a1462b3UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t bech32_final_constant(bech32_encoding enc) {
|
||||||
|
if (enc == BECH32_ENCODING_BECH32) return 1;
|
||||||
|
if (enc == BECH32_ENCODING_BECH32M) return 0x2bc830a3;
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char bech32_charset[] = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
||||||
|
|
||||||
|
const int8_t bech32_charset_rev[128] = {
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
|
15, -1, 10, 17, 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1,
|
||||||
|
-1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1,
|
||||||
|
1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1,
|
||||||
|
-1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, 19, -1,
|
||||||
|
1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1
|
||||||
|
};
|
||||||
|
|
||||||
|
int bech32_encode(char *output, const char *hrp, const uint8_t *data, size_t data_len, size_t max_input_len, bech32_encoding enc) {
|
||||||
|
uint32_t chk = 1;
|
||||||
|
size_t i = 0;
|
||||||
|
while (hrp[i] != 0) {
|
||||||
|
int ch = hrp[i];
|
||||||
|
if (ch < 33 || ch > 126) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch >= 'A' && ch <= 'Z') return 0;
|
||||||
|
chk = bech32_polymod_step(chk) ^ (ch >> 5);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (i + 7 + data_len > max_input_len) return 0;
|
||||||
|
chk = bech32_polymod_step(chk);
|
||||||
|
while (*hrp != 0) {
|
||||||
|
chk = bech32_polymod_step(chk) ^ (*hrp & 0x1f);
|
||||||
|
*(output++) = *(hrp++);
|
||||||
|
}
|
||||||
|
*(output++) = '1';
|
||||||
|
for (i = 0; i < data_len; ++i) {
|
||||||
|
if (*data >> 5) return 0;
|
||||||
|
chk = bech32_polymod_step(chk) ^ (*data);
|
||||||
|
*(output++) = bech32_charset[*(data++)];
|
||||||
|
}
|
||||||
|
for (i = 0; i < 6; ++i) {
|
||||||
|
chk = bech32_polymod_step(chk);
|
||||||
|
}
|
||||||
|
chk ^= bech32_final_constant(enc);
|
||||||
|
for (i = 0; i < 6; ++i) {
|
||||||
|
*(output++) = bech32_charset[(chk >> ((5 - i) * 5)) & 0x1f];
|
||||||
|
}
|
||||||
|
*output = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bech32_encoding bech32_decode_len(char* hrp, uint8_t *data, size_t *data_len, const char *input, size_t input_len) {
|
||||||
|
uint32_t chk = 1;
|
||||||
|
size_t i;
|
||||||
|
size_t hrp_len;
|
||||||
|
int have_lower = 0, have_upper = 0;
|
||||||
|
if (input_len < 8) {
|
||||||
|
return BECH32_ENCODING_NONE;
|
||||||
|
}
|
||||||
|
*data_len = 0;
|
||||||
|
while (*data_len < input_len && input[(input_len - 1) - *data_len] != '1') {
|
||||||
|
++(*data_len);
|
||||||
|
}
|
||||||
|
hrp_len = input_len - (1 + *data_len);
|
||||||
|
if (1 + *data_len >= input_len || *data_len < 6) {
|
||||||
|
return BECH32_ENCODING_NONE;
|
||||||
|
}
|
||||||
|
*(data_len) -= 6;
|
||||||
|
for (i = 0; i < hrp_len; ++i) {
|
||||||
|
int ch = input[i];
|
||||||
|
if (ch < 33 || ch > 126) {
|
||||||
|
return BECH32_ENCODING_NONE;
|
||||||
|
}
|
||||||
|
if (ch >= 'a' && ch <= 'z') {
|
||||||
|
have_lower = 1;
|
||||||
|
} else if (ch >= 'A' && ch <= 'Z') {
|
||||||
|
have_upper = 1;
|
||||||
|
ch = (ch - 'A') + 'a';
|
||||||
|
}
|
||||||
|
hrp[i] = ch;
|
||||||
|
chk = bech32_polymod_step(chk) ^ (ch >> 5);
|
||||||
|
}
|
||||||
|
hrp[i] = 0;
|
||||||
|
chk = bech32_polymod_step(chk);
|
||||||
|
for (i = 0; i < hrp_len; ++i) {
|
||||||
|
chk = bech32_polymod_step(chk) ^ (input[i] & 0x1f);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
while (i < input_len) {
|
||||||
|
int v = (input[i] & 0x80) ? -1 : bech32_charset_rev[(int)input[i]];
|
||||||
|
if (input[i] >= 'a' && input[i] <= 'z') have_lower = 1;
|
||||||
|
if (input[i] >= 'A' && input[i] <= 'Z') have_upper = 1;
|
||||||
|
if (v == -1) {
|
||||||
|
return BECH32_ENCODING_NONE;
|
||||||
|
}
|
||||||
|
chk = bech32_polymod_step(chk) ^ v;
|
||||||
|
if (i + 6 < input_len) {
|
||||||
|
data[i - (1 + hrp_len)] = v;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (have_lower && have_upper) {
|
||||||
|
return BECH32_ENCODING_NONE;
|
||||||
|
}
|
||||||
|
if (chk == bech32_final_constant(BECH32_ENCODING_BECH32)) {
|
||||||
|
return BECH32_ENCODING_BECH32;
|
||||||
|
} else if (chk == bech32_final_constant(BECH32_ENCODING_BECH32M)) {
|
||||||
|
return BECH32_ENCODING_BECH32M;
|
||||||
|
} else {
|
||||||
|
return BECH32_ENCODING_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bech32_encoding bech32_decode(char* hrp, uint8_t *data, size_t *data_len, const char *input, size_t max_input_len) {
|
||||||
|
size_t len = strlen(input);
|
||||||
|
if (len > max_input_len) {
|
||||||
|
return BECH32_ENCODING_NONE;
|
||||||
|
}
|
||||||
|
return bech32_decode_len(hrp, data, data_len, input, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bech32_convert_bits(uint8_t* out, size_t* outlen, int outbits, const uint8_t* in, size_t inlen, int inbits, int pad) {
|
||||||
|
uint32_t val = 0;
|
||||||
|
int bits = 0;
|
||||||
|
uint32_t maxv = (((uint32_t)1) << outbits) - 1;
|
||||||
|
while (inlen--) {
|
||||||
|
val = (val << inbits) | *(in++);
|
||||||
|
bits += inbits;
|
||||||
|
while (bits >= outbits) {
|
||||||
|
bits -= outbits;
|
||||||
|
out[(*outlen)++] = (val >> bits) & maxv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pad) {
|
||||||
|
if (bits) {
|
||||||
|
out[(*outlen)++] = (val << (outbits - bits)) & maxv;
|
||||||
|
}
|
||||||
|
} else if (((val << (outbits - bits)) & maxv) || bits >= inbits) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int segwit_addr_encode(char *output, const char *hrp, int witver, const uint8_t *witprog, size_t witprog_len) {
|
||||||
|
uint8_t data[65];
|
||||||
|
size_t datalen = 0;
|
||||||
|
bech32_encoding enc = BECH32_ENCODING_BECH32;
|
||||||
|
if (witver > 16) return 0;
|
||||||
|
if (witver == 0 && witprog_len != 20 && witprog_len != 32) return 0;
|
||||||
|
if (witprog_len < 2 || witprog_len > 40) return 0;
|
||||||
|
if (witver > 0) enc = BECH32_ENCODING_BECH32M;
|
||||||
|
data[0] = witver;
|
||||||
|
bech32_convert_bits(data + 1, &datalen, 5, witprog, witprog_len, 8, 1);
|
||||||
|
++datalen;
|
||||||
|
return bech32_encode(output, hrp, data, datalen, 90, enc);
|
||||||
|
}
|
||||||
|
|
||||||
|
int segwit_addr_decode(int* witver, uint8_t* witdata, size_t* witdata_len, const char* hrp, const char* addr) {
|
||||||
|
uint8_t data[84];
|
||||||
|
char hrp_actual[84];
|
||||||
|
size_t data_len;
|
||||||
|
bech32_encoding enc = bech32_decode(hrp_actual, data, &data_len, addr, 90);
|
||||||
|
if (enc == BECH32_ENCODING_NONE) return 0;
|
||||||
|
if (data_len == 0 || data_len > 65) return 0;
|
||||||
|
if (strncmp(hrp, hrp_actual, 84) != 0) return 0;
|
||||||
|
if (data[0] > 16) return 0;
|
||||||
|
if (data[0] == 0 && enc != BECH32_ENCODING_BECH32) return 0;
|
||||||
|
if (data[0] > 0 && enc != BECH32_ENCODING_BECH32M) return 0;
|
||||||
|
*witdata_len = 0;
|
||||||
|
if (!bech32_convert_bits(witdata, witdata_len, 8, data + 1, data_len - 1, 5, 0)) return 0;
|
||||||
|
if (*witdata_len < 2 || *witdata_len > 40) return 0;
|
||||||
|
if (data[0] == 0 && *witdata_len != 20 && *witdata_len != 32) return 0;
|
||||||
|
*witver = data[0];
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
142
nostrdb/bolt11/bech32.h
Normal file
142
nostrdb/bolt11/bech32.h
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/* Stolen from https://github.com/sipa/bech32/blob/master/ref/c/segwit_addr.h,
|
||||||
|
* with only the two ' > 90' checks hoisted */
|
||||||
|
|
||||||
|
/* Copyright (c) 2017, 2021 Pieter Wuille
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIGHTNING_COMMON_BECH32_H
|
||||||
|
#define LIGHTNING_COMMON_BECH32_H
|
||||||
|
#include "../config.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/** Encode a SegWit address
|
||||||
|
*
|
||||||
|
* Out: output: Pointer to a buffer of size 73 + strlen(hrp) that will be
|
||||||
|
* updated to contain the null-terminated address.
|
||||||
|
* In: hrp: Pointer to the null-terminated human readable part to use
|
||||||
|
* (chain/network specific).
|
||||||
|
* ver: Version of the witness program (between 0 and 16 inclusive).
|
||||||
|
* prog: Data bytes for the witness program (between 2 and 40 bytes).
|
||||||
|
* prog_len: Number of data bytes in prog.
|
||||||
|
* Returns 1 if successful.
|
||||||
|
*/
|
||||||
|
int segwit_addr_encode(
|
||||||
|
char *output,
|
||||||
|
const char *hrp,
|
||||||
|
int ver,
|
||||||
|
const uint8_t *prog,
|
||||||
|
size_t prog_len
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Decode a SegWit address
|
||||||
|
*
|
||||||
|
* Out: ver: Pointer to an int that will be updated to contain the witness
|
||||||
|
* program version (between 0 and 16 inclusive).
|
||||||
|
* prog: Pointer to a buffer of size 40 that will be updated to
|
||||||
|
* contain the witness program bytes.
|
||||||
|
* prog_len: Pointer to a size_t that will be updated to contain the length
|
||||||
|
* of bytes in prog.
|
||||||
|
* hrp: Pointer to the null-terminated human readable part that is
|
||||||
|
* expected (chain/network specific).
|
||||||
|
* addr: Pointer to the null-terminated address.
|
||||||
|
* Returns 1 if successful.
|
||||||
|
*/
|
||||||
|
int segwit_addr_decode(
|
||||||
|
int* ver,
|
||||||
|
uint8_t* prog,
|
||||||
|
size_t* prog_len,
|
||||||
|
const char* hrp,
|
||||||
|
const char* addr
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Supported encodings. */
|
||||||
|
typedef enum {
|
||||||
|
BECH32_ENCODING_NONE,
|
||||||
|
BECH32_ENCODING_BECH32,
|
||||||
|
BECH32_ENCODING_BECH32M
|
||||||
|
} bech32_encoding;
|
||||||
|
|
||||||
|
/** Encode a Bech32 or Bech32m string
|
||||||
|
*
|
||||||
|
* Out: output: Pointer to a buffer of size strlen(hrp) + data_len + 8 that
|
||||||
|
* will be updated to contain the null-terminated Bech32 string.
|
||||||
|
* In: hrp : Pointer to the null-terminated human readable part.
|
||||||
|
* data : Pointer to an array of 5-bit values.
|
||||||
|
* data_len: Length of the data array.
|
||||||
|
* max_input_len: Maximum valid length of input (90 for segwit usage).
|
||||||
|
* enc: Which encoding to use (BECH32_ENCODING_BECH32{,M}).
|
||||||
|
* Returns 1 if successful.
|
||||||
|
*/
|
||||||
|
int bech32_encode(
|
||||||
|
char *output,
|
||||||
|
const char *hrp,
|
||||||
|
const uint8_t *data,
|
||||||
|
size_t data_len,
|
||||||
|
size_t max_input_len,
|
||||||
|
bech32_encoding enc
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Decode a Bech32 or Bech32m string
|
||||||
|
*
|
||||||
|
* Out: hrp: Pointer to a buffer of size strlen(input) - 6. Will be
|
||||||
|
* updated to contain the null-terminated human readable part.
|
||||||
|
* data: Pointer to a buffer of size strlen(input) - 8 that will
|
||||||
|
* hold the encoded 5-bit data values.
|
||||||
|
* data_len: Pointer to a size_t that will be updated to be the number
|
||||||
|
* of entries in data.
|
||||||
|
* In: input: Pointer to a null-terminated Bech32 string.
|
||||||
|
* max_input_len: Maximum valid length of input (90 for segwit usage).
|
||||||
|
* Returns BECH32_ENCODING_BECH32{,M} to indicate decoding was successful
|
||||||
|
* with the specified encoding standard. BECH32_ENCODING_NONE is returned if
|
||||||
|
* decoding failed.
|
||||||
|
*/
|
||||||
|
bech32_encoding bech32_decode(
|
||||||
|
char *hrp,
|
||||||
|
uint8_t *data,
|
||||||
|
size_t *data_len,
|
||||||
|
const char *input,
|
||||||
|
size_t max_input_len
|
||||||
|
);
|
||||||
|
|
||||||
|
bech32_encoding bech32_decode_len(
|
||||||
|
char *hrp,
|
||||||
|
uint8_t *data,
|
||||||
|
size_t *data_len,
|
||||||
|
const char *input,
|
||||||
|
size_t input_len
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Helper from bech32: translates inbits-bit bytes to outbits-bit bytes.
|
||||||
|
* @outlen is incremented as bytes are added.
|
||||||
|
* @pad is true if we're to pad, otherwise truncate last byte if necessary
|
||||||
|
*/
|
||||||
|
int bech32_convert_bits(uint8_t* out, size_t* outlen, int outbits,
|
||||||
|
const uint8_t* in, size_t inlen, int inbits,
|
||||||
|
int pad);
|
||||||
|
|
||||||
|
/* The charset, and reverse mapping */
|
||||||
|
extern const char bech32_charset[32];
|
||||||
|
extern const int8_t bech32_charset_rev[128];
|
||||||
|
|
||||||
|
#endif /* LIGHTNING_COMMON_BECH32_H */
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
#define HAVE_UNALIGNED_ACCESS 1
|
#define HAVE_UNALIGNED_ACCESS 1
|
||||||
#define HAVE_TYPEOF 1
|
#define HAVE_TYPEOF 1
|
||||||
#define HAVE_BIG_ENDIAN 0
|
#define HAVE_BIG_ENDIAN 0
|
||||||
#define HAVE_BYTESWAP_H 0
|
#define HAVE_BYTESWAP_H 1
|
||||||
#define HAVE_BSWAP_64 0
|
#define HAVE_BSWAP_64 1
|
||||||
#define HAVE_LITTLE_ENDIAN 1
|
#define HAVE_LITTLE_ENDIAN 1
|
||||||
#endif /* CCAN_CONFIG_H */
|
#endif /* CCAN_CONFIG_H */
|
||||||
|
|||||||
1110
nostrdb/configurator.c
Normal file
1110
nostrdb/configurator.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,10 @@
|
|||||||
/* CC0 (Public domain) - see LICENSE file for details */
|
/* CC0 (Public domain) */
|
||||||
#ifndef CCAN_ENDIAN_H
|
#ifndef CCAN_ENDIAN_H
|
||||||
#define CCAN_ENDIAN_H
|
#define CCAN_ENDIAN_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "cursor.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BSWAP_16 - reverse bytes in a constant uint16_t value.
|
* BSWAP_16 - reverse bytes in a constant uint16_t value.
|
||||||
@@ -344,8 +346,6 @@ static inline uint16_t be16_to_cpu(beint16_t be_val)
|
|||||||
return BE16_TO_CPU(be_val);
|
return BE16_TO_CPU(be_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Whichever they include first, they get these definitions. */
|
|
||||||
#ifdef CCAN_SHORT_TYPES_H
|
|
||||||
/**
|
/**
|
||||||
* be64/be32/be16 - 64/32/16 bit big-endian representation.
|
* be64/be32/be16 - 64/32/16 bit big-endian representation.
|
||||||
*/
|
*/
|
||||||
@@ -359,5 +359,7 @@ typedef beint16_t be16;
|
|||||||
typedef leint64_t le64;
|
typedef leint64_t le64;
|
||||||
typedef leint32_t le32;
|
typedef leint32_t le32;
|
||||||
typedef leint16_t le16;
|
typedef leint16_t le16;
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* CCAN_ENDIAN_H */
|
#endif /* CCAN_ENDIAN_H */
|
||||||
|
|
||||||
|
|||||||
114
nostrdb/hex.h
114
nostrdb/hex.h
@@ -1,76 +1,46 @@
|
|||||||
/* CC0 (Public domain) - see LICENSE file for details */
|
|
||||||
#ifndef CCAN_HEX_H
|
#ifndef HEX_H
|
||||||
#define CCAN_HEX_H
|
#define HEX_H
|
||||||
#include "config.h"
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/**
|
static const char hex_table[256] = {
|
||||||
* hex_decode - Unpack a hex string.
|
['0'] = 0, ['1'] = 1, ['2'] = 2, ['3'] = 3,
|
||||||
* @str: the hexadecimal string
|
['4'] = 4, ['5'] = 5, ['6'] = 6, ['7'] = 7,
|
||||||
* @slen: the length of @str
|
['8'] = 8, ['9'] = 9, ['a'] = 10, ['b'] = 11,
|
||||||
* @buf: the buffer to write the data into
|
['c'] = 12, ['d'] = 13, ['e'] = 14, ['f'] = 15,
|
||||||
* @bufsize: the length of
|
['A'] = 10, ['B'] = 11, ['C'] = 12, ['D'] = 13,
|
||||||
*
|
['E'] = 14, ['F'] = 15
|
||||||
* Returns false if there are any characters which aren't 0-9, a-f or A-F,
|
};
|
||||||
* of the string wasn't the right length for @bufsize.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* unsigned char data[20];
|
|
||||||
*
|
|
||||||
* if (!hex_decode(argv[1], strlen(argv[1]), data, 20))
|
|
||||||
* printf("String is malformed!\n");
|
|
||||||
*/
|
|
||||||
bool hex_decode(const char *str, size_t slen, void *buf, size_t bufsize);
|
|
||||||
|
|
||||||
/**
|
static inline int char_to_hex(unsigned char *val, unsigned char c)
|
||||||
* hex_encode - Create a nul-terminated hex string
|
|
||||||
* @buf: the buffer to read the data from
|
|
||||||
* @bufsize: the length of buf
|
|
||||||
* @dest: the string to fill
|
|
||||||
* @destsize: the max size of the string
|
|
||||||
*
|
|
||||||
* Returns true if the string, including terminator, fit in @destsize;
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* unsigned char buf[] = { 0x1F, 0x2F };
|
|
||||||
* char str[5];
|
|
||||||
*
|
|
||||||
* if (!hex_encode(buf, sizeof(buf), str, sizeof(str)))
|
|
||||||
* abort();
|
|
||||||
*/
|
|
||||||
bool hex_encode(const void *buf, size_t bufsize, char *dest, size_t destsize);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* hex_str_size - Calculate how big a nul-terminated hex string is
|
|
||||||
* @bytes: bytes of data to represent
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* unsigned char buf[] = { 0x1F, 0x2F };
|
|
||||||
* char str[hex_str_size(sizeof(buf))];
|
|
||||||
*
|
|
||||||
* hex_encode(buf, sizeof(buf), str, sizeof(str));
|
|
||||||
*/
|
|
||||||
static inline size_t hex_str_size(size_t bytes)
|
|
||||||
{
|
{
|
||||||
return 2 * bytes + 1;
|
if (hex_table[c] || c == '0') {
|
||||||
|
*val = hex_table[c];
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static inline int hex_decode(const char *str, size_t slen, void *buf, size_t bufsize)
|
||||||
* hex_data_size - Calculate how many bytes of data in a hex string
|
|
||||||
* @strlen: the length of the string (with or without NUL)
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* const char str[] = "1F2F";
|
|
||||||
* unsigned char buf[hex_data_size(sizeof(str))];
|
|
||||||
*
|
|
||||||
* hex_decode(str, strlen(str), buf, sizeof(buf));
|
|
||||||
*/
|
|
||||||
static inline size_t hex_data_size(size_t strlen)
|
|
||||||
{
|
{
|
||||||
return strlen / 2;
|
unsigned char v1, v2;
|
||||||
|
unsigned char *p = buf;
|
||||||
|
|
||||||
|
while (slen > 1) {
|
||||||
|
if (!char_to_hex(&v1, str[0]) || !char_to_hex(&v2, str[1]))
|
||||||
|
return 0;
|
||||||
|
if (!bufsize)
|
||||||
|
return 0;
|
||||||
|
*(p++) = (v1 << 4) | v2;
|
||||||
|
str += 2;
|
||||||
|
slen -= 2;
|
||||||
|
bufsize--;
|
||||||
|
}
|
||||||
|
return slen == 0 && bufsize == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline char hexchar(unsigned int val)
|
static inline char hexchar(unsigned int val)
|
||||||
{
|
{
|
||||||
if (val < 10)
|
if (val < 10)
|
||||||
@@ -80,5 +50,19 @@ static inline char hexchar(unsigned int val)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int hex_encode(const void *buf, size_t bufsize, char *dest)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
#endif /* CCAN_HEX_H */
|
for (i = 0; i < bufsize; i++) {
|
||||||
|
unsigned int c = ((const unsigned char *)buf)[i];
|
||||||
|
*(dest++) = hexchar(c >> 4);
|
||||||
|
*(dest++) = hexchar(c & 0xF);
|
||||||
|
}
|
||||||
|
*dest = '\0';
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
48
nostrdb/io.h
Normal file
48
nostrdb/io.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static int read_fd(FILE *fd, unsigned char *buf, int buflen, int *written)
|
||||||
|
{
|
||||||
|
unsigned char *p = buf;
|
||||||
|
int len = 0;
|
||||||
|
*written = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
len = fread(p, 1, 4096, fd);
|
||||||
|
*written += len;
|
||||||
|
p += len;
|
||||||
|
if (p > buf + buflen)
|
||||||
|
return 0;
|
||||||
|
} while (len == 4096);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int write_file(const char *filename, unsigned char *buf, int buflen)
|
||||||
|
{
|
||||||
|
FILE *file = NULL;
|
||||||
|
int ok;
|
||||||
|
|
||||||
|
file = fopen(filename, "w");
|
||||||
|
if (file == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ok = fwrite(buf, buflen, 1, file);
|
||||||
|
fclose(file);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_file(const char *filename, unsigned char *buf, int buflen, int *written)
|
||||||
|
{
|
||||||
|
FILE *file = NULL;
|
||||||
|
int ok;
|
||||||
|
|
||||||
|
file = fopen(filename, "r");
|
||||||
|
if (file == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
ok = read_fd(file, buf, buflen, written);
|
||||||
|
fclose(file);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
100
nostrdb/lmdb_util.h
Normal file
100
nostrdb/lmdb_util.h
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
|
||||||
|
// Define callback function type
|
||||||
|
typedef bool (*lmdb_callback_t)(const MDB_val*, const MDB_val*);
|
||||||
|
|
||||||
|
|
||||||
|
int lmdb_foreach(MDB_txn *txn, MDB_dbi dbi, MDB_val *start, MDB_val *start_dup, callback_t cb, bool reverse) {
|
||||||
|
int success = 0;
|
||||||
|
MDB_cursor *cursor;
|
||||||
|
|
||||||
|
// Open a cursor on the provided transaction and database
|
||||||
|
int rc = mdb_cursor_open(txn, dbi, &cursor);
|
||||||
|
|
||||||
|
if (rc != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
MDB_val k = *start, v = *start_dup;
|
||||||
|
MDB_cursor_op op = reverse ? MDB_PREV : MDB_NEXT;
|
||||||
|
|
||||||
|
// If we're scanning in reverse...
|
||||||
|
if (reverse) {
|
||||||
|
// Try to position the cursor at the first key-value pair where
|
||||||
|
// both the key and the value are greater than or equal to our
|
||||||
|
// starting point.
|
||||||
|
rc = mdb_cursor_get(cursor, &k, &v, MDB_GET_BOTH_RANGE);
|
||||||
|
if (rc == 0) {
|
||||||
|
if (v.mv_size != start_dup->mv_size ||
|
||||||
|
memcmp(v.mv_data, start_dup->mv_data, v.mv_size) != 0) {
|
||||||
|
// If the value doesn't match our starting
|
||||||
|
// point, step back to the previous record.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_PREV) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If we couldn't find a record that matches both our
|
||||||
|
// starting key and value, try to find a record that
|
||||||
|
// matches just our starting key.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_SET) == 0) {
|
||||||
|
// If we find a match, move to the last value
|
||||||
|
// for this key, since we're scanning in
|
||||||
|
// reverse.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_LAST_DUP) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
// If we can't find a record with our starting
|
||||||
|
// key, try to find the first record with a key
|
||||||
|
// greater than our starting key.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_SET_RANGE) == 0) {
|
||||||
|
// If we find such a record, step back
|
||||||
|
// to the previous record.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_PREV) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
// If we can't even find a record with
|
||||||
|
// a key greater than our starting key,
|
||||||
|
// fall back to starting from the last
|
||||||
|
// record in the database.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_LAST) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If we're not scanning in reverse...
|
||||||
|
else {
|
||||||
|
// Try to position the cursor at the first key-value
|
||||||
|
// pair where both the key and the value are greater
|
||||||
|
// than or equal to our starting point.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_SET) != 0) {
|
||||||
|
// If we couldn't find a record that matches
|
||||||
|
// both our starting key and value, try to find
|
||||||
|
// a record that matches just our starting key.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_SET_RANGE) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
// If we can't find a record with our starting
|
||||||
|
// key, try to find the first record with a key
|
||||||
|
// greater than our starting key.
|
||||||
|
if (mdb_cursor_get(cursor, &k, &v, MDB_FIRST_DUP) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whether we're scanning forward or backward, start the actual
|
||||||
|
// iteration, moving one step at a time in the appropriate direction
|
||||||
|
// and calling the provided callback for each record.
|
||||||
|
do {
|
||||||
|
if (!cb(&k, &v))
|
||||||
|
goto cleanup;
|
||||||
|
} while (mdb_cursor_get(cursor, &k, &v, op) == 0);
|
||||||
|
|
||||||
|
// If we make it through the entire iteration without the callback
|
||||||
|
// returning false, return true to signal success.
|
||||||
|
success = 1;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
mdb_cursor_close(cursor);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
185
nostrdb/ndb.c
Normal file
185
nostrdb/ndb.c
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "nostrdb.h"
|
||||||
|
#include "print_util.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
static int usage()
|
||||||
|
{
|
||||||
|
printf("usage: ndb [--skip-verification] [-d db_dir] <command>\n\n");
|
||||||
|
printf("commands\n\n");
|
||||||
|
printf(" stat\n");
|
||||||
|
printf(" search [--oldest-first] [--limit 42] <fulltext query>\n");
|
||||||
|
printf(" import <line-delimited json file>\n\n");
|
||||||
|
printf("settings\n\n");
|
||||||
|
printf(" --skip-verification skip signature validation\n");
|
||||||
|
printf(" -d <db_dir> set database directory\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int map_file(const char *filename, unsigned char **p, size_t *flen)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
int des;
|
||||||
|
stat(filename, &st);
|
||||||
|
*flen = st.st_size;
|
||||||
|
|
||||||
|
des = open(filename, O_RDONLY);
|
||||||
|
|
||||||
|
*p = mmap(NULL, *flen, PROT_READ, MAP_PRIVATE, des, 0);
|
||||||
|
close(des);
|
||||||
|
|
||||||
|
return *p != MAP_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void print_stat_counts(struct ndb_stat_counts *counts)
|
||||||
|
{
|
||||||
|
printf("%zu\t%zu\t%zu\t%zu\n",
|
||||||
|
counts->count,
|
||||||
|
counts->key_size,
|
||||||
|
counts->value_size,
|
||||||
|
counts->key_size + counts->value_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_stats(struct ndb_stat *stat)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
const char *name;
|
||||||
|
struct ndb_stat_counts *c;
|
||||||
|
|
||||||
|
struct ndb_stat_counts total;
|
||||||
|
ndb_stat_counts_init(&total);
|
||||||
|
|
||||||
|
printf("name\tcount\tkey_bytes\tvalue_bytes\ttotal_bytes\n");
|
||||||
|
printf("---\ndbs\n---\n");
|
||||||
|
for (i = 0; i < NDB_DBS; i++) {
|
||||||
|
name = ndb_db_name(i);
|
||||||
|
|
||||||
|
total.count += stat->dbs[i].count;
|
||||||
|
total.key_size += stat->dbs[i].key_size;
|
||||||
|
total.value_size += stat->dbs[i].value_size;
|
||||||
|
|
||||||
|
printf("%s\t", name);
|
||||||
|
print_stat_counts(&stat->dbs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("total\t");
|
||||||
|
print_stat_counts(&total);
|
||||||
|
|
||||||
|
printf("-----\nkinds\n-----\n");
|
||||||
|
for (i = 0; i < NDB_CKIND_COUNT; i++) {
|
||||||
|
c = &stat->common_kinds[i];
|
||||||
|
if (c->count == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
printf("%s\t", ndb_kind_name(i));
|
||||||
|
print_stat_counts(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stat->other_kinds.count != 0) {
|
||||||
|
printf("other\t");
|
||||||
|
print_stat_counts(&stat->other_kinds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ndb_print_search_keys(struct ndb_txn *txn);
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct ndb *ndb;
|
||||||
|
int i, flags, limit;
|
||||||
|
struct ndb_stat stat;
|
||||||
|
struct ndb_txn txn;
|
||||||
|
struct ndb_text_search_results results;
|
||||||
|
struct ndb_text_search_result *result;
|
||||||
|
const char *dir;
|
||||||
|
unsigned char *data;
|
||||||
|
size_t data_len;
|
||||||
|
struct ndb_config config;
|
||||||
|
struct ndb_text_search_config search_config;
|
||||||
|
ndb_default_config(&config);
|
||||||
|
ndb_default_text_search_config(&search_config);
|
||||||
|
ndb_config_set_mapsize(&config, 1024ULL * 1024ULL * 1024ULL * 1024ULL /* 1 TiB */);
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = ".";
|
||||||
|
flags = 0;
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
if (!strcmp(argv[1], "-d") && argv[2]) {
|
||||||
|
dir = argv[2];
|
||||||
|
argv += 2;
|
||||||
|
argc -= 2;
|
||||||
|
} else if (!strcmp(argv[1], "--skip-verification")) {
|
||||||
|
flags = NDB_FLAG_SKIP_NOTE_VERIFY;
|
||||||
|
argv += 1;
|
||||||
|
argc -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ndb_config_set_flags(&config, flags);
|
||||||
|
|
||||||
|
fprintf(stderr, "using db '%s'\n", dir);
|
||||||
|
|
||||||
|
if (!ndb_init(&ndb, dir, &config)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc >= 3 && !strcmp(argv[1], "search")) {
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
if (!strcmp(argv[2], "--oldest-first")) {
|
||||||
|
ndb_text_search_config_set_order(&search_config, NDB_ORDER_ASCENDING);
|
||||||
|
argv++;
|
||||||
|
argc--;
|
||||||
|
} else if (!strcmp(argv[2], "--limit")) {
|
||||||
|
limit = atoi(argv[3]);
|
||||||
|
ndb_text_search_config_set_limit(&search_config, limit);
|
||||||
|
argv += 2;
|
||||||
|
argc -= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ndb_begin_query(ndb, &txn);
|
||||||
|
ndb_text_search(&txn, argv[2], &results, &search_config);
|
||||||
|
|
||||||
|
// print results for now
|
||||||
|
for (i = 0; i < results.num_results; i++) {
|
||||||
|
result = &results.results[i];
|
||||||
|
printf("[%02d] ", i+1);
|
||||||
|
ndb_print_text_search_result(&txn, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
ndb_end_query(&txn);
|
||||||
|
} else if (argc == 2 && !strcmp(argv[1], "stat")) {
|
||||||
|
if (!ndb_stat(ndb, &stat)) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_stats(&stat);
|
||||||
|
} else if (argc == 3 && !strcmp(argv[1], "import")) {
|
||||||
|
if (!strcmp(argv[2], "-")) {
|
||||||
|
ndb_process_events_stream(ndb, stdin);
|
||||||
|
} else {
|
||||||
|
map_file(argv[2], &data, &data_len);
|
||||||
|
ndb_process_events(ndb, (const char *)data, data_len);
|
||||||
|
ndb_process_client_events(ndb, (const char *)data, data_len);
|
||||||
|
}
|
||||||
|
} else if (argc == 2 && !strcmp(argv[1], "print-search-keys")) {
|
||||||
|
ndb_begin_query(ndb, &txn);
|
||||||
|
ndb_print_search_keys(&txn);
|
||||||
|
ndb_end_query(&txn);
|
||||||
|
} else {
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
ndb_destroy(ndb);
|
||||||
|
}
|
||||||
@@ -7,10 +7,8 @@
|
|||||||
|
|
||||||
#include "nostr_bech32.h"
|
#include "nostr_bech32.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "endian.h"
|
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "bech32.h"
|
#include "bech32.h"
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#define MAX_TLVS 16
|
#define MAX_TLVS 16
|
||||||
|
|
||||||
@@ -147,11 +145,6 @@ static int tlvs_to_relays(struct nostr_tlvs *tlvs, struct relays *relays) {
|
|||||||
return 1;
|
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) {
|
static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *nevent) {
|
||||||
struct nostr_tlvs tlvs;
|
struct nostr_tlvs tlvs;
|
||||||
struct nostr_tlv *tlv;
|
struct nostr_tlv *tlv;
|
||||||
@@ -173,13 +166,6 @@ static int parse_nostr_bech32_nevent(struct cursor *cur, struct bech32_nevent *n
|
|||||||
nevent->pubkey = NULL;
|
nevent->pubkey = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(find_tlv(&tlvs, TLV_KIND, &tlv)) {
|
|
||||||
nevent->kind = decode_tlv_u32(tlv->value);
|
|
||||||
nevent->has_kind = true;
|
|
||||||
} else {
|
|
||||||
nevent->has_kind = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tlvs_to_relays(&tlvs, &nevent->relays);
|
return tlvs_to_relays(&tlvs, &nevent->relays);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,11 +187,6 @@ static int parse_nostr_bech32_naddr(struct cursor *cur, struct bech32_naddr *nad
|
|||||||
|
|
||||||
naddr->pubkey = tlv->value;
|
naddr->pubkey = tlv->value;
|
||||||
|
|
||||||
if(!find_tlv(&tlvs, TLV_KIND, &tlv)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
naddr->kind = decode_tlv_u32(tlv->value);
|
|
||||||
|
|
||||||
return tlvs_to_relays(&tlvs, &naddr->relays);
|
return tlvs_to_relays(&tlvs, &naddr->relays);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "str_block.h"
|
#include "str_block.h"
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
#define MAX_RELAYS 10
|
#define MAX_RELAYS 10
|
||||||
|
|
||||||
@@ -47,8 +45,6 @@ struct bech32_nevent {
|
|||||||
struct relays relays;
|
struct relays relays;
|
||||||
const u8 *event_id;
|
const u8 *event_id;
|
||||||
const u8 *pubkey; // optional
|
const u8 *pubkey; // optional
|
||||||
uint32_t kind;
|
|
||||||
bool has_kind;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bech32_nprofile {
|
struct bech32_nprofile {
|
||||||
@@ -60,7 +56,6 @@ struct bech32_naddr {
|
|||||||
struct relays relays;
|
struct relays relays;
|
||||||
struct str_block identifier;
|
struct str_block identifier;
|
||||||
const u8 *pubkey;
|
const u8 *pubkey;
|
||||||
uint32_t kind;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bech32_nrelay {
|
struct bech32_nrelay {
|
||||||
|
|||||||
@@ -2163,15 +2163,6 @@ static int ndb_write_note_kind_index(struct ndb_txn *txn, struct ndb_note *note,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void consume_whitespace_or_punctuation(struct cursor *cur)
|
|
||||||
{
|
|
||||||
while (cur->p < cur->end) {
|
|
||||||
if (!is_right_boundary(*cur->p))
|
|
||||||
return;
|
|
||||||
cur->p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ndb_write_word_to_index(struct ndb_txn *txn, const char *word,
|
static int ndb_write_word_to_index(struct ndb_txn *txn, const char *word,
|
||||||
int word_len, int word_index,
|
int word_len, int word_index,
|
||||||
uint64_t timestamp, uint64_t note_id)
|
uint64_t timestamp, uint64_t note_id)
|
||||||
@@ -3570,7 +3561,7 @@ static int ndb_event_commitment(struct ndb_note *ev, unsigned char *buf, int buf
|
|||||||
struct cursor cur;
|
struct cursor cur;
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
if (!hex_encode(ev->pubkey, sizeof(ev->pubkey), pubkey, sizeof(pubkey)))
|
if (!hex_encode(ev->pubkey, sizeof(ev->pubkey), pubkey))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
make_cursor(buf, buf + buflen, &cur);
|
make_cursor(buf, buf + buflen, &cur);
|
||||||
@@ -4111,17 +4102,6 @@ int ndb_ws_event_from_json(const char *json, int len, struct ndb_tce *tce,
|
|||||||
tce->command_result.msg = json + tok->start;
|
tce->command_result.msg = json + tok->start;
|
||||||
tce->command_result.msglen = toksize(tok);
|
tce->command_result.msglen = toksize(tok);
|
||||||
|
|
||||||
return 1;
|
|
||||||
} else if (tok_len == 4 && !memcmp("AUTH", json + tok->start, 4)) {
|
|
||||||
tce->evtype = NDB_TCE_AUTH;
|
|
||||||
|
|
||||||
tok = &parser.toks[parser.i++];
|
|
||||||
if (tok->type != JSMN_STRING)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
tce->subid = json + tok->start;
|
|
||||||
tce->subid_len = toksize(tok);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ enum tce_type {
|
|||||||
NDB_TCE_OK = 0x2,
|
NDB_TCE_OK = 0x2,
|
||||||
NDB_TCE_NOTICE = 0x3,
|
NDB_TCE_NOTICE = 0x3,
|
||||||
NDB_TCE_EOSE = 0x4,
|
NDB_TCE_EOSE = 0x4,
|
||||||
NDB_TCE_AUTH = 0x5,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ndb_ingest_filter_action {
|
enum ndb_ingest_filter_action {
|
||||||
|
|||||||
36
nostrdb/print_util.h
Normal file
36
nostrdb/print_util.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
static void ndb_print_text_search_key(struct ndb_text_search_key *key)
|
||||||
|
{
|
||||||
|
printf("K<'%.*s' %d %" PRIu64 " note_id:%" PRIu64 ">", key->str_len, key->str,
|
||||||
|
key->word_index,
|
||||||
|
key->timestamp,
|
||||||
|
key->note_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_hex(unsigned char* data, size_t size) {
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
printf("%02x", data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ndb_print_text_search_result(struct ndb_txn *txn,
|
||||||
|
struct ndb_text_search_result *r)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
struct ndb_note *note;
|
||||||
|
|
||||||
|
ndb_print_text_search_key(&r->key);
|
||||||
|
|
||||||
|
if (!(note = ndb_get_note_by_key(txn, r->key.note_id, &len))) {
|
||||||
|
printf(": note not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" ");
|
||||||
|
print_hex(ndb_note_id(note), 32);
|
||||||
|
|
||||||
|
printf("\n%s\n\n---\n", ndb_note_content(note));
|
||||||
|
}
|
||||||
|
|
||||||
@@ -21,8 +21,7 @@
|
|||||||
#include <ntstatus.h>
|
#include <ntstatus.h>
|
||||||
#include <bcrypt.h>
|
#include <bcrypt.h>
|
||||||
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
|
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
|
||||||
//#include <sys/random.h>
|
#include <sys/random.h>
|
||||||
#include <Security/SecRandom.h>
|
|
||||||
#elif defined(__OpenBSD__)
|
#elif defined(__OpenBSD__)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
@@ -54,7 +53,7 @@ static int fill_random(unsigned char* data, size_t size) {
|
|||||||
#elif defined(__APPLE__) || defined(__OpenBSD__)
|
#elif defined(__APPLE__) || defined(__OpenBSD__)
|
||||||
/* If `getentropy(2)` is not available you should fallback to either
|
/* If `getentropy(2)` is not available you should fallback to either
|
||||||
* `SecRandomCopyBytes` or /dev/urandom */
|
* `SecRandomCopyBytes` or /dev/urandom */
|
||||||
int res = SecRandomCopyBytes(kSecRandomDefault, size, data);
|
int res = getentropy(data, size);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
* file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
*/
|
*/
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
#include "compiler.h"
|
|
||||||
#include "endian.h"
|
#include "endian.h"
|
||||||
|
#include "compiler.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -22,7 +22,7 @@ static void invalidate_sha256(struct sha256_ctx *ctx)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_sha256(struct sha256_ctx *ctx UNUSED)
|
static void check_sha256(struct sha256_ctx *ctx)
|
||||||
{
|
{
|
||||||
#ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
|
#ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
|
||||||
assert(ctx->c.md_len != 0);
|
assert(ctx->c.md_len != 0);
|
||||||
@@ -167,14 +167,6 @@ static void Transform(uint32_t *s, const uint32_t *chunk)
|
|||||||
s[7] += h;
|
s[7] += h;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool alignment_ok(const void *p UNUSED, size_t n UNUSED)
|
|
||||||
{
|
|
||||||
#if HAVE_UNALIGNED_ACCESS
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return ((size_t)p % n == 0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add(struct sha256_ctx *ctx, const void *p, size_t len)
|
static void add(struct sha256_ctx *ctx, const void *p, size_t len)
|
||||||
{
|
{
|
||||||
@@ -306,3 +298,5 @@ void sha256_be64(struct sha256_ctx *ctx, uint64_t v)
|
|||||||
beint64_t bev = cpu_to_be64(v);
|
beint64_t bev = cpu_to_be64(v);
|
||||||
sha256_update(ctx, &bev, sizeof(bev));
|
sha256_update(ctx, &bev, sizeof(bev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
|
|
||||||
#ifndef CCAN_CRYPTO_SHA256_H
|
#ifndef CCAN_CRYPTO_SHA256_H
|
||||||
#define CCAN_CRYPTO_SHA256_H
|
#define CCAN_CRYPTO_SHA256_H
|
||||||
|
|
||||||
|
|
||||||
|
/** Output length for `wally_sha256` */
|
||||||
|
#define SHA256_LEN 32
|
||||||
|
|
||||||
|
|
||||||
/* BSD-MIT - see LICENSE file for details */
|
/* BSD-MIT - see LICENSE file for details */
|
||||||
#include "config.h"
|
/* #include "config.h" */
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -30,7 +37,7 @@ struct sha256 {
|
|||||||
* sha256 - return sha256 of an object.
|
* sha256 - return sha256 of an object.
|
||||||
* @sha256: the sha256 to fill in
|
* @sha256: the sha256 to fill in
|
||||||
* @p: pointer to memory,
|
* @p: pointer to memory,
|
||||||
* @size: the number of bytes pointed to by
|
* @size: the number of bytes pointed to by @p
|
||||||
*
|
*
|
||||||
* The bytes pointed to by @p is SHA256 hashed into @sha256. This is
|
* The bytes pointed to by @p is SHA256 hashed into @sha256. This is
|
||||||
* equivalent to sha256_init(), sha256_update() then sha256_done().
|
* equivalent to sha256_init(), sha256_update() then sha256_done().
|
||||||
@@ -112,7 +119,7 @@ void sha256_init(struct sha256_ctx *ctx);
|
|||||||
* sha256_update - include some memory in the hash.
|
* sha256_update - include some memory in the hash.
|
||||||
* @ctx: the sha256_ctx to use
|
* @ctx: the sha256_ctx to use
|
||||||
* @p: pointer to memory,
|
* @p: pointer to memory,
|
||||||
* @size: the number of bytes pointed to by
|
* @size: the number of bytes pointed to by @p
|
||||||
*
|
*
|
||||||
* You can call this multiple times to hash more data, before calling
|
* You can call this multiple times to hash more data, before calling
|
||||||
* sha256_done().
|
* sha256_done().
|
||||||
@@ -144,4 +151,5 @@ void sha256_le64(struct sha256_ctx *ctx, uint64_t v);
|
|||||||
void sha256_be16(struct sha256_ctx *ctx, uint16_t v);
|
void sha256_be16(struct sha256_ctx *ctx, uint16_t v);
|
||||||
void sha256_be32(struct sha256_ctx *ctx, uint32_t v);
|
void sha256_be32(struct sha256_ctx *ctx, uint32_t v);
|
||||||
void sha256_be64(struct sha256_ctx *ctx, uint64_t v);
|
void sha256_be64(struct sha256_ctx *ctx, uint64_t v);
|
||||||
|
|
||||||
#endif /* CCAN_CRYPTO_SHA256_H */
|
#endif /* CCAN_CRYPTO_SHA256_H */
|
||||||
|
|||||||
1009
nostrdb/test.c
Normal file
1009
nostrdb/test.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -87,7 +87,7 @@ static inline void threadpool_destroy(struct threadpool *tp)
|
|||||||
{
|
{
|
||||||
struct thread *t;
|
struct thread *t;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < tp->num_threads; i++) {
|
for (int i = 0; i < tp->num_threads; i++) {
|
||||||
t = &tp->pool[i];
|
t = &tp->pool[i];
|
||||||
if (!prot_queue_push(&t->inbox, tp->quit_msg)) {
|
if (!prot_queue_push(&t->inbox, tp->quit_msg)) {
|
||||||
pthread_exit(&t->thread_id);
|
pthread_exit(&t->thread_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user