Skip to content

Commit

Permalink
Convert wallet to new serialization
Browse files Browse the repository at this point in the history
Adaptation of btc@ef17c03e074b6c3f185afa4eff572ba687c2a171
  • Loading branch information
furszy committed Jul 3, 2021
1 parent cf06950 commit 221bf49
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
48 changes: 28 additions & 20 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,37 @@ class CKeyPool
bool IsExternal() const { return type == HDChain::ChangeType::EXTERNAL; }
bool IsStaking() const { return type == HDChain::ChangeType::STAKING; }

ADD_SERIALIZE_METHODS;
template<typename Stream>
void Serialize(Stream& s) const
{
int nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH)) {
s << nVersion;
}
s << nTime << vchPubKey << Span<unsigned char>((unsigned char*)&type, 1) << m_pre_split;
}

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
template<typename Stream>
void Unserialize(Stream& s)
{
int nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH))
READWRITE(nVersion);
READWRITE(nTime);
READWRITE(vchPubKey);
if (ser_action.ForRead()) {
try {
READWRITE(Span<unsigned char>((unsigned char*)&type, 1));
READWRITE(m_pre_split);
} catch (std::ios_base::failure&) {
/* Set as external address if we can't read the type boolean
(this will be the case for any wallet before the HD chain) */
type = HDChain::ChangeType::EXTERNAL;
m_pre_split = true;
}
} else {
READWRITE(Span<unsigned char>((unsigned char*)&type, 1));
READWRITE(m_pre_split);
if (!(s.GetType() & SER_GETHASH)) {
s >> nVersion;
}
s >> nTime >> vchPubKey;
try {
s >> Span<unsigned char>((unsigned char*)&type, 1);
} 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) */
type = HDChain::ChangeType::EXTERNAL;
}
try {
s >> m_pre_split;
} catch (std::ios_base::failure&) {
/* flag as pre-split address if we can't read the m_pre_split boolean
(this will be the case for any wallet prior to the HD chain upgrade) */
m_pre_split = true;
}
}
};
Expand Down
13 changes: 4 additions & 9 deletions src/wallet/walletdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,11 @@ class CKeyMetadata
nCreateTime = nCreateTime_;
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CKeyMetadata, obj)
{
READWRITE(nVersion);
READWRITE(nCreateTime);
if (HasKeyOrigin()) {
READWRITE(hd_seed_id);
READWRITE(key_origin);
READWRITE(obj.nVersion, obj.nCreateTime);
if (obj.HasKeyOrigin()) {
READWRITE(obj.hd_seed_id, obj.key_origin);
}
}

Expand Down

0 comments on commit 221bf49

Please sign in to comment.