mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Implement operator< for KeyOriginInfo and CExtPubKey
This commit is contained in:
parent
4eabba9be7
commit
5b5c5efbbb
2 changed files with 27 additions and 0 deletions
|
|
@ -251,6 +251,14 @@ struct CExtPubKey {
|
|||
return !(a == b);
|
||||
}
|
||||
|
||||
friend bool operator<(const CExtPubKey &a, const CExtPubKey &b)
|
||||
{
|
||||
if (a.pubkey < b.pubkey) {
|
||||
return true;
|
||||
}
|
||||
return a.chaincode < b.chaincode;
|
||||
}
|
||||
|
||||
void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const;
|
||||
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
|
||||
void EncodeWithVersion(unsigned char code[BIP32_EXTKEY_WITH_VERSION_SIZE]) const;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,25 @@ struct KeyOriginInfo
|
|||
return std::equal(std::begin(a.fingerprint), std::end(a.fingerprint), std::begin(b.fingerprint)) && a.path == b.path;
|
||||
}
|
||||
|
||||
friend bool operator<(const KeyOriginInfo& a, const KeyOriginInfo& b)
|
||||
{
|
||||
// Compare the fingerprints lexicographically
|
||||
int fpr_cmp = memcmp(a.fingerprint, b.fingerprint, 4);
|
||||
if (fpr_cmp < 0) {
|
||||
return true;
|
||||
} else if (fpr_cmp > 0) {
|
||||
return false;
|
||||
}
|
||||
// Compare the sizes of the paths, shorter is "less than"
|
||||
if (a.path.size() < b.path.size()) {
|
||||
return true;
|
||||
} else if (a.path.size() > b.path.size()) {
|
||||
return false;
|
||||
}
|
||||
// Paths same length, compare them lexicographically
|
||||
return a.path < b.path;
|
||||
}
|
||||
|
||||
SERIALIZE_METHODS(KeyOriginInfo, obj) { READWRITE(obj.fingerprint, obj.path); }
|
||||
|
||||
void clear()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue