commit 2c71e2315dbd5a1ce51147d85c04f12cf6f4d8aa
parent e36fdb233a5dc891b1bda86babcf596b83efc93d
Author: William Casarin <jb55@jb55.com>
Date: Fri, 11 Aug 2023 19:19:47 -0700
notes: change created_at to uint64
so we don't have to change this in a 100 years :P
Diffstat:
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/nostrdb.c b/nostrdb.c
@@ -943,7 +943,8 @@ static int ndb_event_commitment(struct ndb_note *ev, unsigned char *buf, int buf
make_cursor(buf, buf + buflen, &cur);
- snprintf(timebuf, sizeof(timebuf), "%d", ev->created_at);
+ // TODO: update in 2106 ...
+ snprintf(timebuf, sizeof(timebuf), "%d", (uint32_t)ev->created_at);
snprintf(kindbuf, sizeof(kindbuf), "%d", ev->kind);
ok =
@@ -1495,9 +1496,11 @@ int ndb_parse_json_note(struct ndb_json_parser *parser, struct ndb_note **note)
start = json + tok->start;
if (tok->type != JSMN_PRIMITIVE || tok_len <= 0)
return 0;
- if (!parse_unsigned_int(start, toksize(tok),
- &parser->builder.note->created_at))
+ // TODO: update to int64 in 2106 ... xD
+ unsigned int bigi;
+ if (!parse_unsigned_int(start, toksize(tok), &bigi))
return 0;
+ parser->builder.note->created_at = bigi;
parsed |= NDB_PARSED_CREATED_AT;
} else if (jsoneq(json, tok, tok_len, "content")) {
// content
@@ -1567,7 +1570,7 @@ void ndb_builder_set_kind(struct ndb_builder *builder, uint32_t kind)
builder->note->kind = kind;
}
-void ndb_builder_set_created_at(struct ndb_builder *builder, uint32_t created_at)
+void ndb_builder_set_created_at(struct ndb_builder *builder, uint64_t created_at)
{
builder->note->created_at = created_at;
}
diff --git a/nostrdb.h b/nostrdb.h
@@ -111,7 +111,7 @@ struct ndb_note {
unsigned char pubkey[32];
unsigned char sig[64];
- uint32_t created_at;
+ uint64_t created_at;
uint32_t kind;
uint32_t content_length;
union ndb_packed_str content;
@@ -160,7 +160,7 @@ int ndb_note_from_json(const char *json, int len, struct ndb_note **, unsigned c
int ndb_builder_init(struct ndb_builder *builder, unsigned char *buf, int bufsize);
int ndb_builder_finalize(struct ndb_builder *builder, struct ndb_note **note, struct ndb_keypair *privkey);
int ndb_builder_set_content(struct ndb_builder *builder, const char *content, int len);
-void ndb_builder_set_created_at(struct ndb_builder *builder, uint32_t created_at);
+void ndb_builder_set_created_at(struct ndb_builder *builder, uint64_t created_at);
void ndb_builder_set_sig(struct ndb_builder *builder, unsigned char *sig);
void ndb_builder_set_pubkey(struct ndb_builder *builder, unsigned char *pubkey);
void ndb_builder_set_id(struct ndb_builder *builder, unsigned char *id);
diff --git a/test.c b/test.c
@@ -154,7 +154,7 @@ static void test_parse_contact_list()
size = ndb_note_from_json((const char*)json, written, ¬e, buf, alloc_size);
printf("ndb_note_from_json size %d\n", size);
assert(size > 0);
- assert(size == 34322);
+ assert(size == 34344);
memcpy(id, note->id, 32);
memset(note->id, 0, 32);