node_id.h (1211B)
1 /* Encapsulation for pubkeys used as node ids: more compact, more dangerous. */ 2 #ifndef LIGHTNING_COMMON_NODE_ID_H 3 #define LIGHTNING_COMMON_NODE_ID_H 4 #include "config.h" 5 #include "short_types.h" 6 #include "tal.h" 7 8 struct node_id { 9 u8 k[33]; 10 }; 11 12 static inline bool node_id_eq(const struct node_id *a, 13 const struct node_id *b) 14 { 15 return memcmp(a->k, b->k, sizeof(a->k)) == 0; 16 } 17 18 /* Is this actually a valid pubkey? Relatively expensive. */ 19 //bool node_id_valid(const struct node_id *id); 20 21 /* Convert to hex string of SEC1 encoding. */ 22 char *node_id_to_hexstr(const tal_t *ctx, const struct node_id *id); 23 24 /* Convert from hex string of SEC1 encoding: checks validity! */ 25 bool node_id_from_hexstr(const char *str, size_t slen, struct node_id *id); 26 27 /* Compare the keys `a` and `b`. Return <0 if `a`<`b`, 0 if equal and >0 otherwise */ 28 int node_id_cmp(const struct node_id *a, const struct node_id *b); 29 30 /* If the two nodes[] are id1 and id2, which index would id1 be? */ 31 static inline int node_id_idx(const struct node_id *id1, 32 const struct node_id *id2) 33 { 34 return node_id_cmp(id1, id2) > 0; 35 } 36 37 /* marshal/unmarshal functions */ 38 #endif /* LIGHTNING_COMMON_NODE_ID_H */