Skip to content

Commit ef17c03

Browse files
committed
Convert wallet to new serialization
1 parent 65c589e commit ef17c03

File tree

4 files changed

+60
-76
lines changed

4 files changed

+60
-76
lines changed

src/wallet/crypter.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,9 @@ class CMasterKey
4343
//! such as the various parameters to scrypt
4444
std::vector<unsigned char> vchOtherDerivationParameters;
4545

46-
ADD_SERIALIZE_METHODS;
47-
48-
template <typename Stream, typename Operation>
49-
inline void SerializationOp(Stream& s, Operation ser_action) {
50-
READWRITE(vchCryptedKey);
51-
READWRITE(vchSalt);
52-
READWRITE(nDerivationMethod);
53-
READWRITE(nDeriveIterations);
54-
READWRITE(vchOtherDerivationParameters);
46+
SERIALIZE_METHODS(CMasterKey, obj)
47+
{
48+
READWRITE(obj.vchCryptedKey, obj.vchSalt, obj.nDerivationMethod, obj.nDeriveIterations, obj.vchOtherDerivationParameters);
5549
}
5650

5751
CMasterKey()

src/wallet/scriptpubkeyman.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,36 +110,37 @@ class CKeyPool
110110
CKeyPool();
111111
CKeyPool(const CPubKey& vchPubKeyIn, bool internalIn);
112112

113-
ADD_SERIALIZE_METHODS;
113+
template<typename Stream>
114+
void Serialize(Stream& s) const
115+
{
116+
int nVersion = s.GetVersion();
117+
if (!(s.GetType() & SER_GETHASH)) {
118+
s << nVersion;
119+
}
120+
s << nTime << vchPubKey << fInternal << m_pre_split;
121+
}
114122

115-
template <typename Stream, typename Operation>
116-
inline void SerializationOp(Stream& s, Operation ser_action) {
123+
template<typename Stream>
124+
void Unserialize(Stream& s)
125+
{
117126
int nVersion = s.GetVersion();
118-
if (!(s.GetType() & SER_GETHASH))
119-
READWRITE(nVersion);
120-
READWRITE(nTime);
121-
READWRITE(vchPubKey);
122-
if (ser_action.ForRead()) {
123-
try {
124-
READWRITE(fInternal);
125-
}
126-
catch (std::ios_base::failure&) {
127-
/* flag as external address if we can't read the internal boolean
128-
(this will be the case for any wallet before the HD chain split version) */
129-
fInternal = false;
130-
}
131-
try {
132-
READWRITE(m_pre_split);
133-
}
134-
catch (std::ios_base::failure&) {
135-
/* flag as postsplit address if we can't read the m_pre_split boolean
136-
(this will be the case for any wallet that upgrades to HD chain split)*/
137-
m_pre_split = false;
138-
}
127+
if (!(s.GetType() & SER_GETHASH)) {
128+
s >> nVersion;
129+
}
130+
s >> nTime >> vchPubKey;
131+
try {
132+
s >> fInternal;
133+
} catch (std::ios_base::failure&) {
134+
/* flag as external address if we can't read the internal boolean
135+
(this will be the case for any wallet before the HD chain split version) */
136+
fInternal = false;
139137
}
140-
else {
141-
READWRITE(fInternal);
142-
READWRITE(m_pre_split);
138+
try {
139+
s >> m_pre_split;
140+
} catch (std::ios_base::failure&) {
141+
/* flag as postsplit address if we can't read the m_pre_split boolean
142+
(this will be the case for any wallet that upgrades to HD chain split) */
143+
m_pre_split = false;
143144
}
144145
}
145146
};

src/wallet/walletdb.h

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ class CHDChain
9898
int nVersion;
9999

100100
CHDChain() { SetNull(); }
101-
ADD_SERIALIZE_METHODS;
102-
template <typename Stream, typename Operation>
103-
inline void SerializationOp(Stream& s, Operation ser_action)
101+
102+
SERIALIZE_METHODS(CHDChain, obj)
104103
{
105-
READWRITE(this->nVersion);
106-
READWRITE(nExternalChainCounter);
107-
READWRITE(seed_id);
108-
if (this->nVersion >= VERSION_HD_CHAIN_SPLIT)
109-
READWRITE(nInternalChainCounter);
104+
READWRITE(obj.nVersion, obj.nExternalChainCounter, obj.seed_id);
105+
if (obj.nVersion >= VERSION_HD_CHAIN_SPLIT) {
106+
READWRITE(obj.nInternalChainCounter);
107+
}
110108
}
111109

112110
void SetNull()
@@ -142,21 +140,16 @@ class CKeyMetadata
142140
nCreateTime = nCreateTime_;
143141
}
144142

145-
ADD_SERIALIZE_METHODS;
146-
147-
template <typename Stream, typename Operation>
148-
inline void SerializationOp(Stream& s, Operation ser_action) {
149-
READWRITE(this->nVersion);
150-
READWRITE(nCreateTime);
151-
if (this->nVersion >= VERSION_WITH_HDDATA)
152-
{
153-
READWRITE(hdKeypath);
154-
READWRITE(hd_seed_id);
143+
SERIALIZE_METHODS(CKeyMetadata, obj)
144+
{
145+
READWRITE(obj.nVersion, obj.nCreateTime);
146+
if (obj.nVersion >= VERSION_WITH_HDDATA) {
147+
READWRITE(obj.hdKeypath, obj.hd_seed_id);
155148
}
156-
if (this->nVersion >= VERSION_WITH_KEY_ORIGIN)
149+
if (obj.nVersion >= VERSION_WITH_KEY_ORIGIN)
157150
{
158-
READWRITE(key_origin);
159-
READWRITE(has_key_origin);
151+
READWRITE(obj.key_origin);
152+
READWRITE(obj.has_key_origin);
160153
}
161154
}
162155

src/wallet/walletutil.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,22 @@ class WalletDescriptor
9898
int32_t next_index = 0; // Position of the next item to generate
9999
DescriptorCache cache;
100100

101-
ADD_SERIALIZE_METHODS;
102-
103-
template <typename Stream, typename Operation>
104-
inline void SerializationOp(Stream& s, Operation ser_action) {
105-
if (ser_action.ForRead()) {
106-
std::string desc;
107-
std::string error;
108-
READWRITE(desc);
109-
FlatSigningProvider keys;
110-
descriptor = Parse(desc, keys, error, true);
111-
if (!descriptor) {
112-
throw std::ios_base::failure("Invalid descriptor: " + error);
113-
}
114-
} else {
115-
READWRITE(descriptor->ToString());
101+
void DeserializeDescriptor(const std::string& str)
102+
{
103+
std::string error;
104+
FlatSigningProvider keys;
105+
descriptor = Parse(str, keys, error, true);
106+
if (!descriptor) {
107+
throw std::ios_base::failure("Invalid descriptor: " + error);
116108
}
117-
READWRITE(creation_time);
118-
READWRITE(next_index);
119-
READWRITE(range_start);
120-
READWRITE(range_end);
109+
}
110+
111+
SERIALIZE_METHODS(WalletDescriptor, obj)
112+
{
113+
std::string descriptor_str;
114+
SER_WRITE(obj, descriptor_str = obj.descriptor->ToString());
115+
READWRITE(descriptor_str, obj.creation_time, obj.next_index, obj.range_start, obj.range_end);
116+
SER_READ(obj, obj.DeserializeDescriptor(descriptor_str));
121117
}
122118

123119
WalletDescriptor() {}

0 commit comments

Comments
 (0)