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

@@ -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;
}
}
};