Line data Source code
1 : // Copyright (c) 2019-2020 The Bitcoin Core developers 2 : // Distributed under the MIT software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #ifndef BITCOIN_SCRIPT_KEYORIGIN_H 6 : #define BITCOIN_SCRIPT_KEYORIGIN_H 7 : 8 : #include <serialize.h> 9 : #include <streams.h> 10 : #include <vector> 11 : 12 : struct KeyOriginInfo 13 : { 14 : unsigned char fingerprint[4]; //!< First 32 bits of the Hash160 of the public key at the root of the path 15 : std::vector<uint32_t> path; 16 : 17 674 : friend bool operator==(const KeyOriginInfo& a, const KeyOriginInfo& b) 18 : { 19 674 : return std::equal(std::begin(a.fingerprint), std::end(a.fingerprint), std::begin(b.fingerprint)) && a.path == b.path; 20 : } 21 : 22 16 : friend bool operator<(const KeyOriginInfo& a, const KeyOriginInfo& b) 23 : { 24 : // Compare the fingerprints lexicographically 25 16 : int fpr_cmp = memcmp(a.fingerprint, b.fingerprint, 4); 26 16 : if (fpr_cmp < 0) { 27 0 : return true; 28 16 : } else if (fpr_cmp > 0) { 29 0 : return false; 30 : } 31 : // Compare the sizes of the paths, shorter is "less than" 32 16 : if (a.path.size() < b.path.size()) { 33 0 : return true; 34 16 : } else if (a.path.size() > b.path.size()) { 35 0 : return false; 36 : } 37 : // Paths same length, compare them lexicographically 38 16 : return a.path < b.path; 39 16 : } 40 : 41 227913 : SERIALIZE_METHODS(KeyOriginInfo, obj) 42 : { 43 75971 : READWRITE(obj.fingerprint, obj.path); 44 75971 : } 45 : 46 792438 : void clear() 47 : { 48 792438 : memset(fingerprint, 0, 4); 49 792438 : path.clear(); 50 792438 : } 51 : }; 52 : 53 : #endif // BITCOIN_SCRIPT_KEYORIGIN_H