Convert wallet to new serialization

This commit is contained in:
Pieter Wuille 2020-05-24 10:34:52 -07:00
parent 65c589e45e
commit ef17c03e07
4 changed files with 61 additions and 77 deletions

View file

@ -43,15 +43,9 @@ public:
//! such as the various parameters to scrypt
std::vector<unsigned char> vchOtherDerivationParameters;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
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()

View file

@ -110,36 +110,37 @@ public:
CKeyPool();
CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn);
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
template<typename Stream>
void Serialize(Stream& s) const
{
int nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH))
READWRITE(nVersion);
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;
}
if (!(s.GetType() & SER_GETHASH)) {
s << nVersion;
}
else {
READWRITE(fInternal);
READWRITE(m_pre_split);
s << nTime << vchPubKey << fInternal << m_pre_split;
}
template<typename Stream>
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;
}
}
};

View file

@ -98,15 +98,13 @@ public:
int nVersion;
CHDChain() { SetNull(); }
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CHDChain, obj)
{
READWRITE(this->nVersion);
READWRITE(nExternalChainCounter);
READWRITE(seed_id);
if (this->nVersion >= VERSION_HD_CHAIN_SPLIT)
READWRITE(nInternalChainCounter);
READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) {
READWRITE(obj.nInternalChainCounter);
}
}
void SetNull()
@ -142,21 +140,16 @@ public:
nCreateTime = nCreateTime_;
}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
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)
if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN)
{
READWRITE(key_origin);
READWRITE(has_key_origin);
READWRITE(obj.key_origin);
READWRITE(obj.has_key_origin);
}
}

View file

@ -98,26 +98,22 @@ public:
int32_t next_index = 0; // Position of the next item to generate
DescriptorCache cache;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
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() {}