rework overhauled serialization methods to non-static

Thanks to Pieter Wuille for most of the work on this commit.
I did not fixup the overhaul commit, because a rebase conflicted
with "remove fields of ser_streamplaceholder".
I prefer not to risk making a mistake while resolving it.
This commit is contained in:
Kamil Domanski 2014-08-20 22:44:38 +02:00
parent 5d96b4ae01
commit 84881f8c47
13 changed files with 269 additions and 269 deletions

View File

@ -46,16 +46,16 @@ private:
public: public:
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
CAddress* pthis = (CAddress*)(thisPtr); CAddress* pthis = (CAddress*)(this);
READWRITE(*pthis); READWRITE(*pthis);
READWRITE(thisPtr->source); READWRITE(source);
READWRITE(thisPtr->nLastSuccess); READWRITE(nLastSuccess);
READWRITE(thisPtr->nAttempts); READWRITE(nAttempts);
return nSerSize; return nSerSize;
} }

View File

@ -46,26 +46,26 @@ public:
std::string strStatusBar; std::string strStatusBar;
std::string strReserved; std::string strReserved;
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->nVersion); READWRITE(this->nVersion);
nVersion = thisPtr->nVersion; nVersion = this->nVersion;
READWRITE(thisPtr->nRelayUntil); READWRITE(nRelayUntil);
READWRITE(thisPtr->nExpiration); READWRITE(nExpiration);
READWRITE(thisPtr->nID); READWRITE(nID);
READWRITE(thisPtr->nCancel); READWRITE(nCancel);
READWRITE(thisPtr->setCancel); READWRITE(setCancel);
READWRITE(thisPtr->nMinVer); READWRITE(nMinVer);
READWRITE(thisPtr->nMaxVer); READWRITE(nMaxVer);
READWRITE(thisPtr->setSubVer); READWRITE(setSubVer);
READWRITE(thisPtr->nPriority); READWRITE(nPriority);
READWRITE(LIMITED_STRING(thisPtr->strComment, 65536)); READWRITE(LIMITED_STRING(strComment, 65536));
READWRITE(LIMITED_STRING(thisPtr->strStatusBar, 256)); READWRITE(LIMITED_STRING(strStatusBar, 256));
READWRITE(LIMITED_STRING(thisPtr->strReserved, 256)); READWRITE(LIMITED_STRING(strReserved, 256));
return nSerSize; return nSerSize;
} }
@ -86,13 +86,13 @@ public:
SetNull(); SetNull();
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->vchMsg); READWRITE(vchMsg);
READWRITE(thisPtr->vchSig); READWRITE(vchSig);
return nSerSize; return nSerSize;
} }

View File

@ -62,15 +62,15 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->vData); READWRITE(vData);
READWRITE(thisPtr->nHashFuncs); READWRITE(nHashFuncs);
READWRITE(thisPtr->nTweak); READWRITE(nTweak);
READWRITE(thisPtr->nFlags); READWRITE(nFlags);
return nSerSize; return nSerSize;
} }

View File

@ -31,12 +31,12 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(FLATDATA(*thisPtr)); READWRITE(FLATDATA(*this));
return nSerSize; return nSerSize;
} }
@ -93,14 +93,14 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->prevout); READWRITE(prevout);
READWRITE(thisPtr->scriptSig); READWRITE(scriptSig);
READWRITE(thisPtr->nSequence); READWRITE(nSequence);
return nSerSize; return nSerSize;
} }
@ -149,12 +149,12 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->nSatoshisPerK); READWRITE(nSatoshisPerK);
return nSerSize; return nSerSize;
} }
}; };
@ -176,13 +176,13 @@ public:
CTxOut(int64_t nValueIn, CScript scriptPubKeyIn); CTxOut(int64_t nValueIn, CScript scriptPubKeyIn);
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->nValue); READWRITE(nValue);
READWRITE(thisPtr->scriptPubKey); READWRITE(scriptPubKey);
return nSerSize; return nSerSize;
} }
@ -261,20 +261,20 @@ public:
CTransaction& operator=(const CTransaction& tx); CTransaction& operator=(const CTransaction& tx);
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
READWRITE(*const_cast<int32_t*>(&thisPtr->nVersion)); READWRITE(*const_cast<int32_t*>(&this->nVersion));
nVersion = thisPtr->nVersion; nVersion = this->nVersion;
READWRITE(*const_cast<std::vector<CTxIn>*>(&thisPtr->vin)); READWRITE(*const_cast<std::vector<CTxIn>*>(&vin));
READWRITE(*const_cast<std::vector<CTxOut>*>(&thisPtr->vout)); READWRITE(*const_cast<std::vector<CTxOut>*>(&vout));
READWRITE(*const_cast<uint32_t*>(&thisPtr->nLockTime)); READWRITE(*const_cast<uint32_t*>(&nLockTime));
if (fRead) if (fRead)
thisPtr->UpdateHash(); UpdateHash();
return nSerSize; return nSerSize;
} }
@ -324,17 +324,17 @@ struct CMutableTransaction
CMutableTransaction(); CMutableTransaction();
CMutableTransaction(const CTransaction& tx); CMutableTransaction(const CTransaction& tx);
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->nVersion); READWRITE(this->nVersion);
nVersion = thisPtr->nVersion; nVersion = this->nVersion;
READWRITE(thisPtr->vin); READWRITE(vin);
READWRITE(thisPtr->vout); READWRITE(vout);
READWRITE(thisPtr->nLockTime); READWRITE(nLockTime);
return nSerSize; return nSerSize;
} }
@ -357,21 +357,21 @@ public:
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { } CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
size_t nSerSize = 0; size_t nSerSize = 0;
if (!fRead) { if (!fRead) {
uint64_t nVal = CompressAmount(thisPtr->txout.nValue); uint64_t nVal = CompressAmount(txout.nValue);
READWRITE(VARINT(nVal)); READWRITE(VARINT(nVal));
} else { } else {
uint64_t nVal = 0; uint64_t nVal = 0;
READWRITE(VARINT(nVal)); READWRITE(VARINT(nVal));
thisPtr->txout.nValue = DecompressAmount(nVal); txout.nValue = DecompressAmount(nVal);
} }
CScriptCompressor cscript(REF(thisPtr->txout.scriptPubKey)); CScriptCompressor cscript(REF(txout.scriptPubKey));
READWRITE(cscript); READWRITE(cscript);
return nSerSize; return nSerSize;
} }
@ -427,12 +427,12 @@ public:
// undo information for all txins // undo information for all txins
std::vector<CTxInUndo> vprevout; std::vector<CTxInUndo> vprevout;
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->vprevout); READWRITE(vprevout);
return nSerSize; return nSerSize;
} }
}; };
@ -462,19 +462,19 @@ public:
SetNull(); SetNull();
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->nVersion); READWRITE(this->nVersion);
nVersion = thisPtr->nVersion; nVersion = this->nVersion;
READWRITE(thisPtr->hashPrevBlock); READWRITE(hashPrevBlock);
READWRITE(thisPtr->hashMerkleRoot); READWRITE(hashMerkleRoot);
READWRITE(thisPtr->nTime); READWRITE(nTime);
READWRITE(thisPtr->nBits); READWRITE(nBits);
READWRITE(thisPtr->nNonce); READWRITE(nNonce);
return nSerSize; return nSerSize;
} }
@ -523,14 +523,14 @@ public:
*((CBlockHeader*)this) = header; *((CBlockHeader*)this) = header;
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(*(CBlockHeader*)thisPtr); READWRITE(*(CBlockHeader*)this);
READWRITE(thisPtr->vtx); READWRITE(vtx);
return nSerSize; return nSerSize;
} }
@ -577,15 +577,15 @@ struct CBlockLocator
vHave = vHaveIn; vHave = vHaveIn;
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
if (!(nType & SER_GETHASH)) if (!(nType & SER_GETHASH))
READWRITE(nVersion); READWRITE(nVersion);
READWRITE(thisPtr->vHave); READWRITE(vHave);
return nSerSize; return nSerSize;
} }

View File

@ -43,16 +43,16 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->vchCryptedKey); READWRITE(vchCryptedKey);
READWRITE(thisPtr->vchSalt); READWRITE(vchSalt);
READWRITE(thisPtr->nDerivationMethod); READWRITE(nDerivationMethod);
READWRITE(thisPtr->nDeriveIterations); READWRITE(nDeriveIterations);
READWRITE(thisPtr->vchOtherDerivationParameters); READWRITE(vchOtherDerivationParameters);
return nSerSize; return nSerSize;
} }

View File

@ -197,13 +197,13 @@ struct CDiskBlockPos
int nFile; int nFile;
unsigned int nPos; unsigned int nPos;
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(VARINT(thisPtr->nFile)); READWRITE(VARINT(nFile));
READWRITE(VARINT(thisPtr->nPos)); READWRITE(VARINT(nPos));
return nSerSize; return nSerSize;
} }
@ -232,13 +232,13 @@ struct CDiskTxPos : public CDiskBlockPos
{ {
unsigned int nTxOffset; // after header unsigned int nTxOffset; // after header
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(*(CDiskBlockPos*)thisPtr); READWRITE(*(CDiskBlockPos*)this);
READWRITE(VARINT(thisPtr->nTxOffset)); READWRITE(VARINT(nTxOffset));
return nSerSize; return nSerSize;
} }
@ -317,12 +317,12 @@ class CBlockUndo
public: public:
std::vector<CTxUndo> vtxundo; // for all but the coinbase std::vector<CTxUndo> vtxundo; // for all but the coinbase
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->vtxundo); READWRITE(vtxundo);
return nSerSize; return nSerSize;
} }
@ -426,27 +426,27 @@ protected:
public: public:
// serialization implementation // serialization implementation
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
READWRITE(thisPtr->nTransactions); READWRITE(nTransactions);
READWRITE(thisPtr->vHash); READWRITE(vHash);
std::vector<unsigned char> vBytes; std::vector<unsigned char> vBytes;
if (fRead) { if (fRead) {
READWRITE(vBytes); READWRITE(vBytes);
CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(thisPtr)); CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(this));
us.vBits.resize(vBytes.size() * 8); us.vBits.resize(vBytes.size() * 8);
for (unsigned int p = 0; p < us.vBits.size(); p++) for (unsigned int p = 0; p < us.vBits.size(); p++)
us.vBits[p] = (vBytes[p / 8] & (1 << (p % 8))) != 0; us.vBits[p] = (vBytes[p / 8] & (1 << (p % 8))) != 0;
us.fBad = false; us.fBad = false;
} else { } else {
vBytes.resize((thisPtr->vBits.size()+7)/8); vBytes.resize((vBits.size()+7)/8);
for (unsigned int p = 0; p < thisPtr->vBits.size(); p++) for (unsigned int p = 0; p < vBits.size(); p++)
vBytes[p / 8] |= thisPtr->vBits[p] << (p % 8); vBytes[p / 8] |= vBits[p] << (p % 8);
READWRITE(vBytes); READWRITE(vBytes);
} }
@ -507,19 +507,19 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(VARINT(thisPtr->nBlocks)); READWRITE(VARINT(nBlocks));
READWRITE(VARINT(thisPtr->nSize)); READWRITE(VARINT(nSize));
READWRITE(VARINT(thisPtr->nUndoSize)); READWRITE(VARINT(nUndoSize));
READWRITE(VARINT(thisPtr->nHeightFirst)); READWRITE(VARINT(nHeightFirst));
READWRITE(VARINT(thisPtr->nHeightLast)); READWRITE(VARINT(nHeightLast));
READWRITE(VARINT(thisPtr->nTimeFirst)); READWRITE(VARINT(nTimeFirst));
READWRITE(VARINT(thisPtr->nTimeLast)); READWRITE(VARINT(nTimeLast));
return nSerSize; return nSerSize;
} }
@ -785,32 +785,32 @@ public:
hashPrev = (pprev ? pprev->GetBlockHash() : 0); hashPrev = (pprev ? pprev->GetBlockHash() : 0);
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
if (!(nType & SER_GETHASH)) if (!(nType & SER_GETHASH))
READWRITE(VARINT(nVersion)); READWRITE(VARINT(nVersion));
READWRITE(VARINT(thisPtr->nHeight)); READWRITE(VARINT(nHeight));
READWRITE(VARINT(thisPtr->nStatus)); READWRITE(VARINT(nStatus));
READWRITE(VARINT(thisPtr->nTx)); READWRITE(VARINT(nTx));
if (thisPtr->nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO)) if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO))
READWRITE(VARINT(thisPtr->nFile)); READWRITE(VARINT(nFile));
if (thisPtr->nStatus & BLOCK_HAVE_DATA) if (nStatus & BLOCK_HAVE_DATA)
READWRITE(VARINT(thisPtr->nDataPos)); READWRITE(VARINT(nDataPos));
if (thisPtr->nStatus & BLOCK_HAVE_UNDO) if (nStatus & BLOCK_HAVE_UNDO)
READWRITE(VARINT(thisPtr->nUndoPos)); READWRITE(VARINT(nUndoPos));
// block header // block header
READWRITE(thisPtr->nVersion); READWRITE(this->nVersion);
READWRITE(thisPtr->hashPrev); READWRITE(hashPrev);
READWRITE(thisPtr->hashMerkleRoot); READWRITE(hashMerkleRoot);
READWRITE(thisPtr->nTime); READWRITE(nTime);
READWRITE(thisPtr->nBits); READWRITE(nBits);
READWRITE(thisPtr->nNonce); READWRITE(nNonce);
return nSerSize; return nSerSize;
} }
@ -1011,13 +1011,13 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->header); READWRITE(header);
READWRITE(thisPtr->txn); READWRITE(txn);
return nSerSize; return nSerSize;
} }
}; };

View File

@ -88,12 +88,12 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(FLATDATA(thisPtr->ip)); READWRITE(FLATDATA(ip));
return nSerSize; return nSerSize;
} }
}; };
@ -152,15 +152,15 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
size_t nSerSize = 0; size_t nSerSize = 0;
CService* pthis = const_cast<CService*>(thisPtr); CService* pthis = const_cast<CService*>(this);
READWRITE(FLATDATA(thisPtr->ip)); READWRITE(FLATDATA(ip));
unsigned short portN = htons(thisPtr->port); unsigned short portN = htons(port);
READWRITE(portN); READWRITE(portN);
if (fRead) if (fRead)
pthis->port = ntohs(portN); pthis->port = ntohs(portN);

View File

@ -35,15 +35,15 @@ class CMessageHeader
std::string GetCommand() const; std::string GetCommand() const;
bool IsValid() const; bool IsValid() const;
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(FLATDATA(thisPtr->pchMessageStart)); READWRITE(FLATDATA(pchMessageStart));
READWRITE(FLATDATA(thisPtr->pchCommand)); READWRITE(FLATDATA(pchCommand));
READWRITE(thisPtr->nMessageSize); READWRITE(nMessageSize);
READWRITE(thisPtr->nChecksum); READWRITE(nChecksum);
return nSerSize; return nSerSize;
} }
@ -87,14 +87,14 @@ class CAddress : public CService
void Init(); void Init();
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
CAddress* pthis = const_cast<CAddress*>(thisPtr); CAddress* pthis = const_cast<CAddress*>(this);
CService* pip = (CService*)pthis; CService* pip = (CService*)pthis;
if (fRead) if (fRead)
pthis->Init(); pthis->Init();
@ -102,8 +102,8 @@ class CAddress : public CService
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(thisPtr->nTime); READWRITE(nTime);
READWRITE(thisPtr->nServices); READWRITE(nServices);
READWRITE(*pip); READWRITE(*pip);
return nSerSize; return nSerSize;
@ -128,13 +128,13 @@ 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 IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->type); READWRITE(type);
READWRITE(thisPtr->hash); READWRITE(hash);
return nSerSize; return nSerSize;
} }

View File

@ -24,22 +24,22 @@ public:
QDateTime date; QDateTime date;
SendCoinsRecipient recipient; SendCoinsRecipient recipient;
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
RecentRequestEntry* pthis = const_cast<RecentRequestEntry*>(thisPtr); RecentRequestEntry* pthis = const_cast<RecentRequestEntry*>(this);
unsigned int nDate = thisPtr->date.toTime_t(); unsigned int nDate = date.toTime_t();
READWRITE(pthis->nVersion); READWRITE(pthis->nVersion);
nVersion = pthis->nVersion; nVersion = pthis->nVersion;
READWRITE(thisPtr->id); READWRITE(id);
READWRITE(nDate); READWRITE(nDate);
READWRITE(thisPtr->recipient); READWRITE(recipient);
if (fRead) if (fRead)
pthis->date = QDateTime::fromTime_t(nDate); pthis->date = QDateTime::fromTime_t(nDate);

View File

@ -59,14 +59,14 @@ public:
static const int CURRENT_VERSION = 1; static const int CURRENT_VERSION = 1;
int nVersion; int nVersion;
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
SendCoinsRecipient* pthis = const_cast<SendCoinsRecipient*>(thisPtr); SendCoinsRecipient* pthis = const_cast<SendCoinsRecipient*>(this);
std::string sAddress = pthis->address.toStdString(); std::string sAddress = pthis->address.toStdString();
std::string sLabel = pthis->label.toStdString(); std::string sLabel = pthis->label.toStdString();
@ -80,7 +80,7 @@ public:
nVersion = pthis->nVersion; nVersion = pthis->nVersion;
READWRITE(sAddress); READWRITE(sAddress);
READWRITE(sLabel); READWRITE(sLabel);
READWRITE(thisPtr->amount); READWRITE(amount);
READWRITE(sMessage); READWRITE(sMessage);
READWRITE(sPaymentRequest); READWRITE(sPaymentRequest);
READWRITE(sAuthenticatedMerchant); READWRITE(sAuthenticatedMerchant);

View File

@ -38,12 +38,12 @@ inline T& REF(const T& val)
return const_cast<T&>(val); return const_cast<T&>(val);
} }
// Used to acquire a const pointer "this" and generate a const // Used to acquire a non-const pointer "this" to generate bodies
// serialization operation from a template // of const serialization operations from a template
template<typename T> template<typename T>
inline T MAKE_CONST(T val) inline T* NCONST_PTR(const T* val)
{ {
return const_cast<const T>(val); return const_cast<T*>(val);
} }
/** Get begin pointer of vector (non-const version). /** Get begin pointer of vector (non-const version).
@ -97,15 +97,15 @@ enum
#define IMPLEMENT_SERIALIZE \ #define IMPLEMENT_SERIALIZE \
size_t GetSerializeSize(int nType, int nVersion) const { \ size_t GetSerializeSize(int nType, int nVersion) const { \
ser_streamplaceholder s; \ ser_streamplaceholder s; \
return SerializationOp(MAKE_CONST(this), s, CSerActionGetSerializeSize(), nType, nVersion); \ return NCONST_PTR(this)->SerializationOp(s, CSerActionGetSerializeSize(), nType, nVersion); \
} \ } \
template<typename Stream> \ template<typename Stream> \
void Serialize(Stream& s, int nType, int nVersion) const { \ void Serialize(Stream& s, int nType, int nVersion) const { \
SerializationOp(MAKE_CONST(this), s, CSerActionSerialize(), nType, nVersion); \ NCONST_PTR(this)->SerializationOp(s, CSerActionSerialize(), nType, nVersion); \
} \ } \
template<typename Stream> \ template<typename Stream> \
void Unserialize(Stream& s, int nType, int nVersion) { \ void Unserialize(Stream& s, int nType, int nVersion) { \
SerializationOp(this, s, CSerActionUnserialize(), nType, nVersion); \ SerializationOp(s, CSerActionUnserialize(), nType, nVersion); \
} }

View File

@ -63,15 +63,15 @@ public:
CKeyPool(); CKeyPool();
CKeyPool(const CPubKey& vchPubKeyIn); CKeyPool(const CPubKey& vchPubKeyIn);
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
if (!(nType & SER_GETHASH)) if (!(nType & SER_GETHASH))
READWRITE(nVersion); READWRITE(nVersion);
READWRITE(thisPtr->nTime); READWRITE(nTime);
READWRITE(thisPtr->vchPubKey); READWRITE(vchPubKey);
return nSerSize; return nSerSize;
} }
}; };
@ -493,17 +493,17 @@ public:
fMerkleVerified = false; fMerkleVerified = false;
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
nSerSize += SerReadWrite(s, *(CTransaction*)thisPtr, nType, nVersion, ser_action); nSerSize += SerReadWrite(s, *(CTransaction*)this, nType, nVersion, ser_action);
nVersion = thisPtr->nVersion; nVersion = this->nVersion;
READWRITE(thisPtr->hashBlock); READWRITE(hashBlock);
READWRITE(thisPtr->vMerkleBranch); READWRITE(vMerkleBranch);
READWRITE(thisPtr->nIndex); READWRITE(nIndex);
return nSerSize; return nSerSize;
} }
@ -610,14 +610,14 @@ public:
nOrderPos = -1; nOrderPos = -1;
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
CWalletTx* pthis = const_cast<CWalletTx*>(thisPtr); CWalletTx* pthis = const_cast<CWalletTx*>(this);
if (fRead) if (fRead)
pthis->Init(NULL); pthis->Init(NULL);
char fSpent = false; char fSpent = false;
@ -628,18 +628,18 @@ public:
WriteOrderPos(pthis->nOrderPos, pthis->mapValue); WriteOrderPos(pthis->nOrderPos, pthis->mapValue);
if (thisPtr->nTimeSmart) if (nTimeSmart)
pthis->mapValue["timesmart"] = strprintf("%u", thisPtr->nTimeSmart); pthis->mapValue["timesmart"] = strprintf("%u", nTimeSmart);
} }
nSerSize += SerReadWrite(s, *(CMerkleTx*)thisPtr, nType, nVersion,ser_action); nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion,ser_action);
std::vector<CMerkleTx> vUnused; // Used to be vtxPrev std::vector<CMerkleTx> vUnused; // Used to be vtxPrev
READWRITE(vUnused); READWRITE(vUnused);
READWRITE(thisPtr->mapValue); READWRITE(mapValue);
READWRITE(thisPtr->vOrderForm); READWRITE(vOrderForm);
READWRITE(thisPtr->fTimeReceivedIsTxTime); READWRITE(fTimeReceivedIsTxTime);
READWRITE(thisPtr->nTimeReceived); READWRITE(nTimeReceived);
READWRITE(thisPtr->fFromMe); READWRITE(fFromMe);
READWRITE(fSpent); READWRITE(fSpent);
if (fRead) if (fRead)
@ -648,7 +648,7 @@ public:
ReadOrderPos(pthis->nOrderPos, pthis->mapValue); ReadOrderPos(pthis->nOrderPos, pthis->mapValue);
pthis->nTimeSmart = thisPtr->mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0; pthis->nTimeSmart = mapValue.count("timesmart") ? (unsigned int)atoi64(pthis->mapValue["timesmart"]) : 0;
} }
pthis->mapValue.erase("fromaccount"); pthis->mapValue.erase("fromaccount");
@ -904,17 +904,17 @@ public:
CWalletKey(int64_t nExpires=0); CWalletKey(int64_t nExpires=0);
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
if (!(nType & SER_GETHASH)) if (!(nType & SER_GETHASH))
READWRITE(nVersion); READWRITE(nVersion);
READWRITE(thisPtr->vchPrivKey); READWRITE(vchPrivKey);
READWRITE(thisPtr->nTimeCreated); READWRITE(nTimeCreated);
READWRITE(thisPtr->nTimeExpires); READWRITE(nTimeExpires);
READWRITE(LIMITED_STRING(thisPtr->strComment, 65536)); READWRITE(LIMITED_STRING(strComment, 65536));
return nSerSize; return nSerSize;
} }
}; };
@ -942,14 +942,14 @@ public:
vchPubKey = CPubKey(); vchPubKey = CPubKey();
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
if (!(nType & SER_GETHASH)) if (!(nType & SER_GETHASH))
READWRITE(nVersion); READWRITE(nVersion);
READWRITE(thisPtr->vchPubKey); READWRITE(vchPubKey);
return nSerSize; return nSerSize;
} }
}; };
@ -987,44 +987,44 @@ public:
nEntryNo = 0; nEntryNo = 0;
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
bool fRead = boost::is_same<Operation, CSerActionUnserialize>(); bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
CAccountingEntry& me = *const_cast<CAccountingEntry*>(thisPtr); 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.
READWRITE(thisPtr->nCreditDebit); READWRITE(nCreditDebit);
READWRITE(thisPtr->nTime); READWRITE(nTime);
READWRITE(LIMITED_STRING(thisPtr->strOtherAccount, 65536)); READWRITE(LIMITED_STRING(strOtherAccount, 65536));
if (!fRead) if (!fRead)
{ {
WriteOrderPos(thisPtr->nOrderPos, me.mapValue); WriteOrderPos(nOrderPos, me.mapValue);
if (!(thisPtr->mapValue.empty() && thisPtr->_ssExtra.empty())) if (!(mapValue.empty() && _ssExtra.empty()))
{ {
CDataStream ss(nType, nVersion); CDataStream ss(nType, nVersion);
ss.insert(ss.begin(), '\0'); ss.insert(ss.begin(), '\0');
ss << thisPtr->mapValue; ss << mapValue;
ss.insert(ss.end(), thisPtr->_ssExtra.begin(), thisPtr->_ssExtra.end()); ss.insert(ss.end(), _ssExtra.begin(), _ssExtra.end());
me.strComment.append(ss.str()); me.strComment.append(ss.str());
} }
} }
READWRITE(LIMITED_STRING(thisPtr->strComment, 65536)); READWRITE(LIMITED_STRING(strComment, 65536));
size_t nSepPos = thisPtr->strComment.find("\0", 0, 1); size_t nSepPos = strComment.find("\0", 0, 1);
if (fRead) if (fRead)
{ {
me.mapValue.clear(); me.mapValue.clear();
if (std::string::npos != nSepPos) if (std::string::npos != nSepPos)
{ {
CDataStream ss(std::vector<char>(thisPtr->strComment.begin() + nSepPos + 1, thisPtr->strComment.end()), nType, nVersion); CDataStream ss(std::vector<char>(strComment.begin() + nSepPos + 1, strComment.end()), nType, nVersion);
ss >> me.mapValue; ss >> me.mapValue;
me._ssExtra = std::vector<char>(ss.begin(), ss.end()); me._ssExtra = std::vector<char>(ss.begin(), ss.end());
} }

View File

@ -54,14 +54,14 @@ public:
nCreateTime = nCreateTime_; nCreateTime = nCreateTime_;
} }
IMPLEMENT_SERIALIZE IMPLEMENT_SERIALIZE;
template <typename T, typename Stream, typename Operation> template <typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) { inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0; size_t nSerSize = 0;
READWRITE(thisPtr->nVersion); READWRITE(this->nVersion);
nVersion = thisPtr->nVersion; nVersion = this->nVersion;
READWRITE(thisPtr->nCreateTime); READWRITE(nCreateTime);
return nSerSize; return nSerSize;
} }