From 8cf1485f3b7a976548128c0d3866747819cbea51 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 25 Jan 2014 20:05:00 +0100 Subject: Abstract chaincodes into CChainCode # Conflicts: # src/key.cpp # src/key.h --- src/pubkey.h | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/pubkey.h') diff --git a/src/pubkey.h b/src/pubkey.h index b0768d4f47..8924708835 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -31,6 +31,36 @@ public: CKeyID(const uint160& in) : uint160(in) {} }; +struct CChainCode +{ + unsigned char data[32]; + + void SetNull() + { + memset(data, 0, sizeof(data)); + } + + CChainCode() + { + SetNull(); + } + + bool IsNull() const + { + for (int i=0; i<32; i++) + if (data[i]) + return false; + return true; + } + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(FLATDATA(data)); + } +}; + /** An encapsulated public key. */ class CPubKey { @@ -189,13 +219,13 @@ struct CExtPubKey { unsigned char nDepth; unsigned char vchFingerprint[4]; unsigned int nChild; - unsigned char vchChainCode[32]; + CChainCode chaincode; CPubKey pubkey; - friend bool operator==(const CExtPubKey& a, const CExtPubKey& b) + friend bool operator==(const CExtPubKey &a, const CExtPubKey &b) { return a.nDepth == b.nDepth && memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], 4) == 0 && a.nChild == b.nChild && - memcmp(&a.vchChainCode[0], &b.vchChainCode[0], 32) == 0 && a.pubkey == b.pubkey; + memcmp(&a.chaincode.data[0], &b.chaincode.data[0], 32) == 0 && a.pubkey == b.pubkey; } void Encode(unsigned char code[74]) const; -- cgit v1.2.3 From a574899671d428682b339ff988363ecaf7dfcd07 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 21 Apr 2015 18:09:37 -0400 Subject: chaincodes: abstract away more chaincode behavior [squashme] replace struct CCainCode with a typedef uint256 ChainCode --- src/pubkey.h | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) (limited to 'src/pubkey.h') diff --git a/src/pubkey.h b/src/pubkey.h index 8924708835..cce9c826e5 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -31,35 +31,7 @@ public: CKeyID(const uint160& in) : uint160(in) {} }; -struct CChainCode -{ - unsigned char data[32]; - - void SetNull() - { - memset(data, 0, sizeof(data)); - } - - CChainCode() - { - SetNull(); - } - - bool IsNull() const - { - for (int i=0; i<32; i++) - if (data[i]) - return false; - return true; - } - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(FLATDATA(data)); - } -}; +typedef uint256 ChainCode; /** An encapsulated public key. */ class CPubKey @@ -212,20 +184,20 @@ public: bool Decompress(); //! Derive BIP32 child pubkey. - bool Derive(CPubKey& pubkeyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const; + bool Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChild, const ChainCode& cc) const; }; struct CExtPubKey { unsigned char nDepth; unsigned char vchFingerprint[4]; unsigned int nChild; - CChainCode chaincode; + ChainCode chaincode; CPubKey pubkey; friend bool operator==(const CExtPubKey &a, const CExtPubKey &b) { return a.nDepth == b.nDepth && memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], 4) == 0 && a.nChild == b.nChild && - memcmp(&a.chaincode.data[0], &b.chaincode.data[0], 32) == 0 && a.pubkey == b.pubkey; + a.chaincode == b.chaincode && a.pubkey == b.pubkey; } void Encode(unsigned char code[74]) const; -- cgit v1.2.3