diff options
| author | Jonas Schnelli <[email protected]> | 2015-06-01 16:35:19 +0200 |
|---|---|---|
| committer | Jonas Schnelli <[email protected]> | 2016-04-14 20:56:33 +0200 |
| commit | 90604f16af63ec066d6561337f476ccd8acec326 (patch) | |
| tree | 5cca6f0af2f22330bbf7d7a913b3e10cbcafe868 /src/pubkey.h | |
| parent | Merge #7874: Improve AlreadyHave (diff) | |
| download | discoin-90604f16af63ec066d6561337f476ccd8acec326.tar.xz discoin-90604f16af63ec066d6561337f476ccd8acec326.zip | |
add bip32 pubkey serialization
CExtPubKey should be serializable like CPubKey
Diffstat (limited to 'src/pubkey.h')
| -rw-r--r-- | src/pubkey.h | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/pubkey.h b/src/pubkey.h index e1a17b658..db5444ea9 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -23,6 +23,8 @@ * script supports up to 75 for single byte push */ +const unsigned int BIP32_EXTKEY_SIZE = 74; + /** A reference to a CKey: the Hash160 of its serialized public key */ class CKeyID : public uint160 { @@ -205,9 +207,33 @@ struct CExtPubKey { a.chaincode == b.chaincode && a.pubkey == b.pubkey; } - void Encode(unsigned char code[74]) const; - void Decode(const unsigned char code[74]); + void Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const; + void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]); bool Derive(CExtPubKey& out, unsigned int nChild) const; + + unsigned int GetSerializeSize(int nType, int nVersion) const + { + return BIP32_EXTKEY_SIZE+1; //add one byte for the size (compact int) + } + template <typename Stream> + void Serialize(Stream& s, int nType, int nVersion) const + { + unsigned int len = BIP32_EXTKEY_SIZE; + ::WriteCompactSize(s, len); + unsigned char code[BIP32_EXTKEY_SIZE]; + Encode(code); + s.write((const char *)&code[0], len); + } + template <typename Stream> + void Unserialize(Stream& s, int nType, int nVersion) + { + unsigned int len = ::ReadCompactSize(s); + unsigned char code[BIP32_EXTKEY_SIZE]; + if (len != BIP32_EXTKEY_SIZE) + throw std::runtime_error("Invalid extended key size\n"); + s.read((char *)&code[0], len); + Decode(code); + } }; /** Users of this module must hold an ECCVerifyHandle. The constructor and |