Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mf1803 travis depth1 #2

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split up and sanitize CAccountingEntry serialization
  • Loading branch information
sipa committed Mar 11, 2018
commit 42343c748c2bca8ba9b888d949088dbfd1f142b4
67 changes: 34 additions & 33 deletions src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,48 +602,49 @@ class CAccountingEntry
nEntryNo = 0;
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
template <typename Stream>
void Serialize(Stream& s) const {
int nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH))
READWRITE(nVersion);
if (!(s.GetType() & SER_GETHASH)) {
s << nVersion;
}
//! Note: strAccount is serialized as part of the key, not here.
READWRITE(nCreditDebit);
READWRITE(nTime);
READWRITE(LIMITED_STRING(strOtherAccount, 65536));
s << nCreditDebit << nTime << strOtherAccount;

if (!ser_action.ForRead())
{
WriteOrderPos(nOrderPos, mapValue);

if (!(mapValue.empty() && _ssExtra.empty()))
{
CDataStream ss(s.GetType(), s.GetVersion());
ss.insert(ss.begin(), '\0');
ss << mapValue;
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
strComment.append(ss.str());
}
mapValue_t mapValueCopy = mapValue;
WriteOrderPos(nOrderPos, mapValueCopy);

std::string strCommentCopy = strComment;
if (!mapValueCopy.empty() || !_ssExtra.empty()) {
CDataStream ss(s.GetType(), s.GetVersion());
ss.insert(ss.begin(), '\0');
ss << mapValueCopy;
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
strCommentCopy.append(ss.str());
}
s << strCommentCopy;
}

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

size_t nSepPos = strComment.find("\0", 0, 1);
if (ser_action.ForRead())
{
mapValue.clear();
if (std::string::npos != nSepPos)
{
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
ss >> mapValue;
_ssExtra = std::vector<char>(ss.begin(), ss.end());
}
ReadOrderPos(nOrderPos, mapValue);
mapValue.clear();
if (std::string::npos != nSepPos) {
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), s.GetType(), s.GetVersion());
ss >> mapValue;
_ssExtra = std::vector<char>(ss.begin(), ss.end());
}
if (std::string::npos != nSepPos)
ReadOrderPos(nOrderPos, mapValue);
if (std::string::npos != nSepPos) {
strComment.erase(nSepPos);
}

mapValue.erase("n");
}
Expand Down