Split up and sanitize CWalletTx serialization

This commit is contained in:
Pieter Wuille 2018-03-09 17:04:31 -08:00
parent 29fad97c32
commit 029ecac1bc
1 changed files with 22 additions and 28 deletions

View File

@ -390,42 +390,36 @@ public:
nOrderPos = -1;
}
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
if (ser_action.ForRead())
Init(nullptr);
template<typename Stream>
void Serialize(Stream& s) const
{
char fSpent = false;
mapValue_t mapValueCopy = mapValue;
if (!ser_action.ForRead())
{
mapValue["fromaccount"] = strFromAccount;
WriteOrderPos(nOrderPos, mapValue);
if (nTimeSmart)
mapValue["timesmart"] = strprintf("%u", nTimeSmart);
mapValueCopy["fromaccount"] = strFromAccount;
WriteOrderPos(nOrderPos, mapValueCopy);
if (nTimeSmart) {
mapValueCopy["timesmart"] = strprintf("%u", nTimeSmart);
}
READWRITE(*static_cast<CMerkleTx*>(this));
s << *static_cast<const CMerkleTx*>(this);
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
READWRITE(vUnused);
READWRITE(mapValue);
READWRITE(vOrderForm);
READWRITE(fTimeReceivedIsTxTime);
READWRITE(nTimeReceived);
READWRITE(fFromMe);
READWRITE(fSpent);
s << vUnused << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << fFromMe << fSpent;
}
if (ser_action.ForRead())
{
strFromAccount = mapValue["fromaccount"];
template<typename Stream>
void Unserialize(Stream& s)
{
Init(nullptr);
char fSpent;
ReadOrderPos(nOrderPos, mapValue);
s >> *static_cast<CMerkleTx*>(this);
std::vector<CMerkleTx> vUnused; //!< Used to be vtxPrev
s >> vUnused >> mapValue >> vOrderForm >> fTimeReceivedIsTxTime >> nTimeReceived >> fFromMe >> fSpent;
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
}
strFromAccount = std::move(mapValue["fromaccount"]);
ReadOrderPos(nOrderPos, mapValue);
nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
mapValue.erase("fromaccount");
mapValue.erase("spent");