Skip to content

Commit 029ecac

Browse files
committed
Split up and sanitize CWalletTx serialization
1 parent 29fad97 commit 029ecac

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

src/wallet/wallet.h

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -390,42 +390,36 @@ class CWalletTx : public CMerkleTx
390390
nOrderPos = -1;
391391
}
392392

393-
ADD_SERIALIZE_METHODS;
394-
395-
template <typename Stream, typename Operation>
396-
inline void SerializationOp(Stream& s, Operation ser_action) {
397-
if (ser_action.ForRead())
398-
Init(nullptr);
393+
template<typename Stream>
394+
void Serialize(Stream& s) const
395+
{
399396
char fSpent = false;
397+
mapValue_t mapValueCopy = mapValue;
400398

401-
if (!ser_action.ForRead())
402-
{
403-
mapValue["fromaccount"] = strFromAccount;
404-
405-
WriteOrderPos(nOrderPos, mapValue);
406-
407-
if (nTimeSmart)
408-
mapValue["timesmart"] = strprintf("%u", nTimeSmart);
399+
mapValueCopy["fromaccount"] = strFromAccount;
400+
WriteOrderPos(nOrderPos, mapValueCopy);
401+
if (nTimeSmart) {
402+
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
409403
}
410404

411-
READWRITE(*static_cast<CMerkleTx*>(this));
405+
s << *static_cast<const CMerkleTx*>(this);
412406
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
413-
READWRITE(vUnused);
414-
READWRITE(mapValue);
415-
READWRITE(vOrderForm);
416-
READWRITE(fTimeReceivedIsTxTime);
417-
READWRITE(nTimeReceived);
418-
READWRITE(fFromMe);
419-
READWRITE(fSpent);
407+
s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << fFromMe << fSpent;
408+
}
420409

421-
if (ser_action.ForRead())
422-
{
423-
strFromAccount = mapValue["fromaccount"];
410+
template<typename Stream>
411+
void Unserialize(Stream& s)
412+
{
413+
Init(nullptr);
414+
char fSpent;
424415

425-
ReadOrderPos(nOrderPos, mapValue);
416+
s >> *static_cast<CMerkleTx*>(this);
417+
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
418+
s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> fSpent;
426419

427-
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
428-
}
420+
strFromAccount = std::move(mapValue["fromaccount"]);
421+
ReadOrderPos(nOrderPos, mapValue);
422+
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
429423

430424
mapValue.erase("fromaccount");
431425
mapValue.erase("spent");

0 commit comments

Comments
 (0)