Merge pull request #4808

3f6540a Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODS (Pieter Wuille)
47eb765 Serializer simplifications after IMPLEMENT_SERIALIZE overhaul (Pieter Wuille)
This commit is contained in:
Pieter Wuille 2014-09-03 20:54:10 +02:00
commit 961c4a04c2
No known key found for this signature in database
GPG key ID: 8F653255C87992E0
13 changed files with 84 additions and 107 deletions

View file

@ -46,7 +46,7 @@ private:
public: public:
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -268,7 +268,7 @@ public:
// This format is more complex, but significantly smaller (at most 1.5 MiB), and supports // This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
// changes to the ADDRMAN_ parameters without breaking the on-disk structure. // changes to the ADDRMAN_ parameters without breaking the on-disk structure.
// //
// We don't use IMPLEMENT_SERIALIZE since the serialization and deserialization code has // We don't use ADD_SERIALIZE_METHODS since the serialization and deserialization code has
// very little in common. // very little in common.
template<typename Stream> template<typename Stream>
void Serialize(Stream &s, int nType, int nVersionDummy) const void Serialize(Stream &s, int nType, int nVersionDummy) const

View file

@ -46,7 +46,7 @@ public:
std::string strStatusBar; std::string strStatusBar;
std::string strReserved; std::string strReserved;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -84,7 +84,7 @@ public:
SetNull(); SetNull();
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

View file

@ -62,7 +62,7 @@ public:
CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak, unsigned char nFlagsIn); CBloomFilter(unsigned int nElements, double nFPRate, unsigned int nTweak, unsigned char nFlagsIn);
CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {} CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {}
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

View file

@ -31,7 +31,7 @@ public:
COutPoint() { SetNull(); } COutPoint() { SetNull(); }
COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; } COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -91,7 +91,7 @@ public:
explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<unsigned int>::max()); explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<unsigned int>::max());
CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max()); CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=std::numeric_limits<uint32_t>::max());
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -145,7 +145,7 @@ public:
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; } friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
std::string ToString() const; std::string ToString() const;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -170,7 +170,7 @@ public:
CTxOut(int64_t nValueIn, CScript scriptPubKeyIn); CTxOut(int64_t nValueIn, CScript scriptPubKeyIn);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -253,18 +253,16 @@ public:
CTransaction& operator=(const CTransaction& tx); CTransaction& operator=(const CTransaction& tx);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead();
READWRITE(*const_cast<int32_t*>(&this->nVersion)); READWRITE(*const_cast<int32_t*>(&this->nVersion));
nVersion = this->nVersion; nVersion = this->nVersion;
READWRITE(*const_cast<std::vector<CTxIn>*>(&vin)); READWRITE(*const_cast<std::vector<CTxIn>*>(&vin));
READWRITE(*const_cast<std::vector<CTxOut>*>(&vout)); READWRITE(*const_cast<std::vector<CTxOut>*>(&vout));
READWRITE(*const_cast<uint32_t*>(&nLockTime)); READWRITE(*const_cast<uint32_t*>(&nLockTime));
if (fRead) if (ser_action.ForRead())
UpdateHash(); UpdateHash();
} }
@ -313,7 +311,7 @@ struct CMutableTransaction
CMutableTransaction(); CMutableTransaction();
CMutableTransaction(const CTransaction& tx); CMutableTransaction(const CTransaction& tx);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -342,12 +340,11 @@ public:
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { } CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead(); if (!ser_action.ForRead()) {
if (!fRead) {
uint64_t nVal = CompressAmount(txout.nValue); uint64_t nVal = CompressAmount(txout.nValue);
READWRITE(VARINT(nVal)); READWRITE(VARINT(nVal));
} else { } else {
@ -410,7 +407,7 @@ public:
// undo information for all txins // undo information for all txins
std::vector<CTxInUndo> vprevout; std::vector<CTxInUndo> vprevout;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -443,7 +440,7 @@ public:
SetNull(); SetNull();
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -500,7 +497,7 @@ public:
*((CBlockHeader*)this) = header; *((CBlockHeader*)this) = header;
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -550,7 +547,7 @@ struct CBlockLocator
vHave = vHaveIn; vHave = vHaveIn;
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

View file

@ -43,7 +43,7 @@ public:
// such as the various parameters to scrypt // such as the various parameters to scrypt
std::vector<unsigned char> vchOtherDerivationParameters; std::vector<unsigned char> vchOtherDerivationParameters;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

View file

@ -197,7 +197,7 @@ struct CDiskBlockPos
int nFile; int nFile;
unsigned int nPos; unsigned int nPos;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -230,7 +230,7 @@ struct CDiskTxPos : public CDiskBlockPos
{ {
unsigned int nTxOffset; // after header unsigned int nTxOffset; // after header
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -313,7 +313,7 @@ class CBlockUndo
public: public:
std::vector<CTxUndo> vtxundo; // for all but the coinbase std::vector<CTxUndo> vtxundo; // for all but the coinbase
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -420,16 +420,14 @@ protected:
public: public:
// serialization implementation // serialization implementation
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead();
READWRITE(nTransactions); READWRITE(nTransactions);
READWRITE(vHash); READWRITE(vHash);
std::vector<unsigned char> vBytes; std::vector<unsigned char> vBytes;
if (fRead) { if (ser_action.ForRead()) {
READWRITE(vBytes); READWRITE(vBytes);
CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(this)); CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(this));
us.vBits.resize(vBytes.size() * 8); us.vBits.resize(vBytes.size() * 8);
@ -498,7 +496,7 @@ public:
uint64_t nTimeFirst; // earliest time of block in file uint64_t nTimeFirst; // earliest time of block in file
uint64_t nTimeLast; // latest time of block in file uint64_t nTimeLast; // latest time of block in file
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -773,7 +771,7 @@ public:
hashPrev = (pprev ? pprev->GetBlockHash() : 0); hashPrev = (pprev ? pprev->GetBlockHash() : 0);
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -995,7 +993,7 @@ public:
// thus the filter will likely be modified. // thus the filter will likely be modified.
CMerkleBlock(const CBlock& block, CBloomFilter& filter); CMerkleBlock(const CBlock& block, CBloomFilter& filter);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

View file

@ -88,7 +88,7 @@ class CNetAddr
friend bool operator!=(const CNetAddr& a, const CNetAddr& b); friend bool operator!=(const CNetAddr& a, const CNetAddr& b);
friend bool operator<(const CNetAddr& a, const CNetAddr& b); friend bool operator<(const CNetAddr& a, const CNetAddr& b);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -150,15 +150,14 @@ class CService : public CNetAddr
CService(const struct in6_addr& ipv6Addr, unsigned short port); CService(const struct in6_addr& ipv6Addr, unsigned short port);
CService(const struct sockaddr_in6& addr); CService(const struct sockaddr_in6& addr);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead();
READWRITE(FLATDATA(ip)); READWRITE(FLATDATA(ip));
unsigned short portN = htons(port); unsigned short portN = htons(port);
READWRITE(portN); READWRITE(portN);
if (fRead) if (ser_action.ForRead())
port = ntohs(portN); port = ntohs(portN);
} }
}; };

View file

@ -35,7 +35,7 @@ class CMessageHeader
std::string GetCommand() const; std::string GetCommand() const;
bool IsValid() const; bool IsValid() const;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -85,20 +85,17 @@ class CAddress : public CService
void Init(); void Init();
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead(); if (ser_action.ForRead())
Init();
CAddress* pthis = const_cast<CAddress*>(this);
if (fRead)
pthis->Init();
if (nType & SER_DISK) if (nType & SER_DISK)
READWRITE(nVersion); READWRITE(nVersion);
if ((nType & SER_DISK) || if ((nType & SER_DISK) ||
(nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH))) (nVersion >= CADDR_TIME_VERSION && !(nType & SER_GETHASH)))
READWRITE(nTime); READWRITE(nTime);
READWRITE(nServices); READWRITE(nServices);
READWRITE(*(CService*)this); READWRITE(*(CService*)this);
} }
@ -122,7 +119,7 @@ class CInv
CInv(int typeIn, const uint256& hashIn); CInv(int typeIn, const uint256& hashIn);
CInv(const std::string& strType, const uint256& hashIn); CInv(const std::string& strType, const uint256& hashIn);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {

View file

@ -24,23 +24,19 @@ public:
QDateTime date; QDateTime date;
SendCoinsRecipient recipient; SendCoinsRecipient recipient;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead();
RecentRequestEntry* pthis = const_cast<RecentRequestEntry*>(this);
unsigned int nDate = date.toTime_t(); unsigned int nDate = date.toTime_t();
READWRITE(pthis->nVersion); READWRITE(this->nVersion);
nVersion = pthis->nVersion; nVersion = this->nVersion;
READWRITE(id); READWRITE(id);
READWRITE(nDate); READWRITE(nDate);
READWRITE(recipient); READWRITE(recipient);
if (fRead) if (ser_action.ForRead())
date = QDateTime::fromTime_t(nDate); date = QDateTime::fromTime_t(nDate);
} }
}; };

View file

@ -59,24 +59,20 @@ public:
static const int CURRENT_VERSION = 1; static const int CURRENT_VERSION = 1;
int nVersion; int nVersion;
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead(); std::string sAddress = address.toStdString();
std::string sLabel = label.toStdString();
SendCoinsRecipient* pthis = const_cast<SendCoinsRecipient*>(this); std::string sMessage = message.toStdString();
std::string sAddress = pthis->address.toStdString();
std::string sLabel = pthis->label.toStdString();
std::string sMessage = pthis->message.toStdString();
std::string sPaymentRequest; std::string sPaymentRequest;
if (!fRead && pthis->paymentRequest.IsInitialized()) if (!ser_action.ForRead() && paymentRequest.IsInitialized())
pthis->paymentRequest.SerializeToString(&sPaymentRequest); paymentRequest.SerializeToString(&sPaymentRequest);
std::string sAuthenticatedMerchant = pthis->authenticatedMerchant.toStdString(); std::string sAuthenticatedMerchant = authenticatedMerchant.toStdString();
READWRITE(pthis->nVersion); READWRITE(this->nVersion);
nVersion = pthis->nVersion; nVersion = this->nVersion;
READWRITE(sAddress); READWRITE(sAddress);
READWRITE(sLabel); READWRITE(sLabel);
READWRITE(amount); READWRITE(amount);
@ -84,14 +80,14 @@ public:
READWRITE(sPaymentRequest); READWRITE(sPaymentRequest);
READWRITE(sAuthenticatedMerchant); READWRITE(sAuthenticatedMerchant);
if (fRead) if (ser_action.ForRead())
{ {
pthis->address = QString::fromStdString(sAddress); address = QString::fromStdString(sAddress);
pthis->label = QString::fromStdString(sLabel); label = QString::fromStdString(sLabel);
pthis->message = QString::fromStdString(sMessage); message = QString::fromStdString(sMessage);
if (!sPaymentRequest.empty()) if (!sPaymentRequest.empty())
pthis->paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size())); paymentRequest.parse(QByteArray::fromRawData(sPaymentRequest.data(), sPaymentRequest.size()));
pthis->authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant); authenticatedMerchant = QString::fromStdString(sAuthenticatedMerchant);
} }
} }
}; };

View file

@ -91,9 +91,9 @@ enum
/* Implement three methods for serializable objects. These are actually wrappers over /* Implement three methods for serializable objects. These are actually wrappers over
* "SerializationOp" template, which implements the body of each class' serialization * "SerializationOp" template, which implements the body of each class' serialization
* code. Adding "IMPLEMENT_SERIALIZE" in the body of the class causes these wrappers to be * code. Adding "ADD_SERIALIZE_METHODS" in the body of the class causes these wrappers to be
* added as members. */ * added as members. */
#define IMPLEMENT_SERIALIZE \ #define ADD_SERIALIZE_METHODS \
size_t GetSerializeSize(int nType, int nVersion) const { \ size_t GetSerializeSize(int nType, int nVersion) const { \
CSizeComputer s(nType, nVersion); \ CSizeComputer s(nType, nVersion); \
NCONST_PTR(this)->SerializationOp(s, CSerActionSerialize(), nType, nVersion);\ NCONST_PTR(this)->SerializationOp(s, CSerActionSerialize(), nType, nVersion);\
@ -807,7 +807,7 @@ void Unserialize(Stream& is, std::set<K, Pred, A>& m, int nType, int nVersion)
// //
// Support for IMPLEMENT_SERIALIZE and READWRITE macro // Support for ADD_SERIALIZE_METHODS and READWRITE macro
// //
struct CSerActionSerialize struct CSerActionSerialize
{ {

View file

@ -64,7 +64,7 @@ public:
CKeyPool(); CKeyPool();
CKeyPool(const CPubKey& vchPubKeyIn); CKeyPool(const CPubKey& vchPubKeyIn);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -492,7 +492,7 @@ public:
fMerkleVerified = false; fMerkleVerified = false;
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -605,25 +605,22 @@ public:
nOrderPos = -1; nOrderPos = -1;
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead(); if (ser_action.ForRead())
Init(NULL);
CWalletTx* pthis = const_cast<CWalletTx*>(this);
if (fRead)
pthis->Init(NULL);
char fSpent = false; char fSpent = false;
if (!fRead) if (!ser_action.ForRead())
{ {
pthis->mapValue["fromaccount"] = pthis->strFromAccount; mapValue["fromaccount"] = strFromAccount;
WriteOrderPos(pthis->nOrderPos, pthis->mapValue); WriteOrderPos(nOrderPos, mapValue);
if (nTimeSmart) if (nTimeSmart)
pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart); mapValue["timesmart"] = strprintf("%u", nTimeSmart);
} }
READWRITE(*(CMerkleTx*)this); READWRITE(*(CMerkleTx*)this);
@ -636,13 +633,13 @@ public:
READWRITE(fFromMe); READWRITE(fFromMe);
READWRITE(fSpent); READWRITE(fSpent);
if (fRead) if (ser_action.ForRead())
{ {
pthis->strFromAccount = pthis->mapValue["fromaccount"]; strFromAccount = mapValue["fromaccount"];
ReadOrderPos(pthis->nOrderPos, pthis->mapValue); ReadOrderPos(nOrderPos, mapValue);
pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0; nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(mapValue["timesmart"]) : 0;
} }
mapValue.erase("fromaccount"); mapValue.erase("fromaccount");
@ -896,7 +893,7 @@ public:
CWalletKey(int64_t nExpires=0); CWalletKey(int64_t nExpires=0);
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -932,7 +929,7 @@ public:
vchPubKey = CPubKey(); vchPubKey = CPubKey();
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
@ -975,13 +972,10 @@ public:
nEntryNo = 0; nEntryNo = 0;
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = ser_action.ForRead();
CAccountingEntry& me = *const_cast<CAccountingEntry*>(this);
if (!(nType & SER_GETHASH)) if (!(nType & SER_GETHASH))
READWRITE(nVersion); READWRITE(nVersion);
// Note: strAccount is serialized as part of the key, not here. // Note: strAccount is serialized as part of the key, not here.
@ -989,9 +983,9 @@ public:
READWRITE(nTime); READWRITE(nTime);
READWRITE(LIMITED_STRING(strOtherAccount, 65536)); READWRITE(LIMITED_STRING(strOtherAccount, 65536));
if (!fRead) if (!ser_action.ForRead())
{ {
WriteOrderPos(nOrderPos, me.mapValue); WriteOrderPos(nOrderPos, mapValue);
if (!(mapValue.empty() && _ssExtra.empty())) if (!(mapValue.empty() && _ssExtra.empty()))
{ {
@ -999,26 +993,26 @@ public:
ss.insert(ss.begin(), '\0'); ss.insert(ss.begin(), '\0');
ss << mapValue; ss << mapValue;
ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end()); ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
me.strComment.append(ss.str()); strComment.append(ss.str());
} }
} }
READWRITE(LIMITED_STRING(strComment, 65536)); READWRITE(LIMITED_STRING(strComment, 65536));
size_t nSepPos = strComment.find("\0", 0, 1); size_t nSepPos = strComment.find("\0", 0, 1);
if (fRead) if (ser_action.ForRead())
{ {
me.mapValue.clear(); mapValue.clear();
if (std::string::npos != nSepPos) if (std::string::npos != nSepPos)
{ {
CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion); CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
ss >> me.mapValue; ss >> mapValue;
me._ssExtra = std::vector<char>(ss.begin(), ss.end()); _ssExtra = std::vector<char>(ss.begin(), ss.end());
} }
ReadOrderPos(me.nOrderPos, me.mapValue); ReadOrderPos(nOrderPos, mapValue);
} }
if (std::string::npos != nSepPos) if (std::string::npos != nSepPos)
me.strComment.erase(nSepPos); strComment.erase(nSepPos);
mapValue.erase("n"); mapValue.erase("n");
} }

View file

@ -55,7 +55,7 @@ public:
nCreateTime = nCreateTime_; nCreateTime = nCreateTime_;
} }
IMPLEMENT_SERIALIZE; ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {