diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h --- a/src/wallet/crypter.h +++ b/src/wallet/crypter.h @@ -40,15 +40,9 @@ //! parameters to scrypt std::vector vchOtherDerivationParameters; - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(vchCryptedKey); - READWRITE(vchSalt); - READWRITE(nDerivationMethod); - READWRITE(nDeriveIterations); - READWRITE(vchOtherDerivationParameters); + SERIALIZE_METHODS(CMasterKey, obj) { + READWRITE(obj.vchCryptedKey, obj.vchSalt, obj.nDerivationMethod, + obj.nDeriveIterations, obj.vchOtherDerivationParameters); } CMasterKey() { diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -119,41 +119,39 @@ CKeyPool(); CKeyPool(const CPubKey &vchPubKeyIn, bool internalIn); - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { + template void Serialize(Stream &s) const { int nVersion = s.GetVersion(); if (!(s.GetType() & SER_GETHASH)) { - READWRITE(nVersion); + s << nVersion; } + s << nTime << vchPubKey << fInternal << m_pre_split; + } - READWRITE(nTime); - READWRITE(vchPubKey); - if (ser_action.ForRead()) { - try { - READWRITE(fInternal); - } catch (std::ios_base::failure &) { - /** - * flag as external address if we can't read the internal - * boolean (this will be the case for any wallet before the HD - * chain split version) - */ - fInternal = false; - } - try { - READWRITE(m_pre_split); - } catch (std::ios_base::failure &) { - /** - * flag as postsplit address if we can't read the m_pre_split - * boolean (this will be the case for any wallet that upgrades - * to HD chain split) - */ - m_pre_split = false; - } - } else { - READWRITE(fInternal); - READWRITE(m_pre_split); + template void Unserialize(Stream &s) { + int nVersion = s.GetVersion(); + if (!(s.GetType() & SER_GETHASH)) { + s >> nVersion; + } + s >> nTime >> vchPubKey; + try { + s >> fInternal; + } catch (std::ios_base::failure &) { + /** + * flag as external address if we can't read the internal + * boolean (this will be the case for any wallet before the HD + * chain split version) + */ + fInternal = false; + } + try { + s >> m_pre_split; + } catch (std::ios_base::failure &) { + /** + * flag as postsplit address if we can't read the m_pre_split + * boolean (this will be the case for any wallet that upgrades + * to HD chain split) + */ + m_pre_split = false; } } }; diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -101,14 +101,11 @@ int nVersion; CHDChain() { SetNull(); } - ADD_SERIALIZE_METHODS; - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(this->nVersion); - READWRITE(nExternalChainCounter); - READWRITE(seed_id); - if (this->nVersion >= VERSION_HD_CHAIN_SPLIT) { - READWRITE(nInternalChainCounter); + + SERIALIZE_METHODS(CHDChain, obj) { + READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id); + if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) { + READWRITE(obj.nInternalChainCounter); } } @@ -149,19 +146,14 @@ nCreateTime = nCreateTime_; } - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(this->nVersion); - READWRITE(nCreateTime); - if (this->nVersion >= VERSION_WITH_HDDATA) { - READWRITE(hdKeypath); - READWRITE(hd_seed_id); + SERIALIZE_METHODS(CKeyMetadata, obj) { + READWRITE(obj.nVersion, obj.nCreateTime); + if (obj.nVersion >= VERSION_WITH_HDDATA) { + READWRITE(obj.hdKeypath, obj.hd_seed_id); } - if (this->nVersion >= VERSION_WITH_KEY_ORIGIN) { - READWRITE(key_origin); - READWRITE(has_key_origin); + if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN) { + READWRITE(obj.key_origin); + READWRITE(obj.has_key_origin); } } diff --git a/src/wallet/walletutil.h b/src/wallet/walletutil.h --- a/src/wallet/walletutil.h +++ b/src/wallet/walletutil.h @@ -110,26 +110,21 @@ int32_t next_index = 0; DescriptorCache cache; - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - if (ser_action.ForRead()) { - std::string desc; - std::string error; - READWRITE(desc); - FlatSigningProvider keys; - descriptor = Parse(desc, keys, error, true); - if (!descriptor) { - throw std::ios_base::failure("Invalid descriptor: " + error); - } - } else { - READWRITE(descriptor->ToString()); + void DeserializeDescriptor(const std::string &str) { + std::string error; + FlatSigningProvider keys; + descriptor = Parse(str, keys, error, true); + if (!descriptor) { + throw std::ios_base::failure("Invalid descriptor: " + error); } - READWRITE(creation_time); - READWRITE(next_index); - READWRITE(range_start); - READWRITE(range_end); + } + + SERIALIZE_METHODS(WalletDescriptor, obj) { + std::string descriptor_str; + SER_WRITE(obj, descriptor_str = obj.descriptor->ToString()); + READWRITE(descriptor_str, obj.creation_time, obj.next_index, + obj.range_start, obj.range_end); + SER_READ(obj, obj.DeserializeDescriptor(descriptor_str)); } WalletDescriptor() {}