c: move c files into nostrdb in prep for switchover

This commit is contained in:
William Casarin
2024-01-25 14:30:16 -08:00
committed by Daniel D’Aquino
parent cc75a8450a
commit 954f48b23d
60 changed files with 24 additions and 414 deletions

38
nostrdb/node_id.h Normal file
View File

@@ -0,0 +1,38 @@
/* Encapsulation for pubkeys used as node ids: more compact, more dangerous. */
#ifndef LIGHTNING_COMMON_NODE_ID_H
#define LIGHTNING_COMMON_NODE_ID_H
#include "config.h"
#include "short_types.h"
#include "tal.h"
struct node_id {
u8 k[33];
};
static inline bool node_id_eq(const struct node_id *a,
const struct node_id *b)
{
return memcmp(a->k, b->k, sizeof(a->k)) == 0;
}
/* Is this actually a valid pubkey? Relatively expensive. */
//bool node_id_valid(const struct node_id *id);
/* Convert to hex string of SEC1 encoding. */
char *node_id_to_hexstr(const tal_t *ctx, const struct node_id *id);
/* Convert from hex string of SEC1 encoding: checks validity! */
bool node_id_from_hexstr(const char *str, size_t slen, struct node_id *id);
/* Compare the keys `a` and `b`. Return <0 if `a`<`b`, 0 if equal and >0 otherwise */
int node_id_cmp(const struct node_id *a, const struct node_id *b);
/* If the two nodes[] are id1 and id2, which index would id1 be? */
static inline int node_id_idx(const struct node_id *id1,
const struct node_id *id2)
{
return node_id_cmp(id1, id2) > 0;
}
/* marshal/unmarshal functions */
#endif /* LIGHTNING_COMMON_NODE_ID_H */