bitcoin: Add comparison between pubkeys

Some of the routing messages rely on a canonical ordering of pubkeys.
This commit is contained in:
Christian Decker 2016-12-12 13:12:58 +01:00 committed by Rusty Russell
parent db481d881a
commit 9f846925b3
2 changed files with 11 additions and 0 deletions

View File

@ -65,3 +65,11 @@ bool pubkey_eq(const struct pubkey *a, const struct pubkey *b)
{ {
return structeq(&a->pubkey, &b->pubkey); 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));
}

View File

@ -32,4 +32,7 @@ void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key);
/* Are these keys equal? */ /* Are these keys equal? */
bool pubkey_eq(const struct pubkey *a, const struct pubkey *b); 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 */ #endif /* LIGHTNING_PUBKEY_H */