mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
bitcoin: Add comparison between pubkeys
Some of the routing messages rely on a canonical ordering of pubkeys.
This commit is contained in:
parent
db481d881a
commit
9f846925b3
@ -65,3 +65,11 @@ bool pubkey_eq(const struct pubkey *a, const struct pubkey *b)
|
||||
{
|
||||
return structeq(&a->pubkey, &b->pubkey);
|
||||
}
|
||||
|
||||
int pubkey_cmp(const struct pubkey *a, const struct pubkey *b)
|
||||
{
|
||||
u8 keya[33], keyb[33];
|
||||
pubkey_to_der(keya, a);
|
||||
pubkey_to_der(keyb, b);
|
||||
return memcmp(keya, keyb, sizeof(keya));
|
||||
}
|
||||
|
@ -32,4 +32,7 @@ void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key);
|
||||
|
||||
/* Are these keys equal? */
|
||||
bool pubkey_eq(const struct pubkey *a, const struct pubkey *b);
|
||||
|
||||
/* Compare the keys `a` and `b`. Return <0 if `a`<`b`, 0 if equal and >0 otherwise */
|
||||
int pubkey_cmp(const struct pubkey *a, const struct pubkey *b);
|
||||
#endif /* LIGHTNING_PUBKEY_H */
|
||||
|
Loading…
Reference in New Issue
Block a user