Skip to content

Commit 42343c7

Browse files
committed
Split up and sanitize CAccountingEntry serialization
1 parent 029ecac commit 42343c7

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

src/wallet/wallet.h

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -602,48 +602,49 @@ class CAccountingEntry
602602
nEntryNo = 0;
603603
}
604604

605-
ADD_SERIALIZE_METHODS;
606-
607-
template <typename Stream, typename Operation>
608-
inline void SerializationOp(Stream& s, Operation ser_action) {
605+
template <typename Stream>
606+
void Serialize(Stream& s) const {
609607
int nVersion = s.GetVersion();
610-
if (!(s.GetType() & SER_GETHASH))
611-
READWRITE(nVersion);
608+
if (!(s.GetType() & SER_GETHASH)) {
609+
s << nVersion;
610+
}
612611
//! Note: strAccount is serialized as part of the key, not here.
613-
READWRITE(nCreditDebit);
614-
READWRITE(nTime);
615-
READWRITE(LIMITED_STRING(strOtherAccount, 65536));
612+
s << nCreditDebit << nTime << strOtherAccount;
616613

617-
if (!ser_action.ForRead())
618-
{
619-
WriteOrderPos(nOrderPos, mapValue);
620-
621-
if (!(mapValue.empty() && _ssExtra.empty()))
622-
{
623-
CDataStream ss(s.GetType(), s.GetVersion());
624-
ss.insert(ss.begin(), '\0');
625-
ss << mapValue;
626-
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
627-
strComment.append(ss.str());
628-
}
614+
mapValue_t mapValueCopy = mapValue;
615+
WriteOrderPos(nOrderPos, mapValueCopy);
616+
617+
std::string strCommentCopy = strComment;
618+
if (!mapValueCopy.empty() || !_ssExtra.empty()) {
619+
CDataStream ss(s.GetType(), s.GetVersion());
620+
ss.insert(ss.begin(), '\0');
621+
ss << mapValueCopy;
622+
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
623+
strCommentCopy.append(ss.str());
629624
}
625+
s << strCommentCopy;
626+
}
630627

631-
READWRITE(LIMITED_STRING(strComment, 65536));
628+
template <typename Stream>
629+
void Unserialize(Stream& s) {
630+
int nVersion = s.GetVersion();
631+
if (!(s.GetType() & SER_GETHASH)) {
632+
s >> nVersion;
633+
}
634+
//! Note: strAccount is serialized as part of the key, not here.
635+
s >> nCreditDebit >> nTime >> LIMITED_STRING(strOtherAccount, 65536) >> LIMITED_STRING(strComment, 65536);
632636

633637
size_t nSepPos = strComment.find("\0", 0, 1);
634-
if (ser_action.ForRead())
635-
{
636-
mapValue.clear();
637-
if (std::string::npos != nSepPos)
638-
{
639-
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
640-
ss >> mapValue;
641-
_ssExtra = std::vector<char>(ss.begin(), ss.end());
642-
}
643-
ReadOrderPos(nOrderPos, mapValue);
638+
mapValue.clear();
639+
if (std::string::npos != nSepPos) {
640+
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
641+
ss >> mapValue;
642+
_ssExtra = std::vector<char>(ss.begin(), ss.end());
644643
}
645-
if (std::string::npos != nSepPos)
644+
ReadOrderPos(nOrderPos, mapValue);
645+
if (std::string::npos != nSepPos) {
646646
strComment.erase(nSepPos);
647+
}
647648

648649
mapValue.erase("n");
649650
}

0 commit comments

Comments
 (0)