mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
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:
130
src/core.h
130
src/core.h
@@ -31,12 +31,12 @@ public:
|
||||
COutPoint() { SetNull(); }
|
||||
COutPoint(uint256 hashIn, uint32_t nIn) { hash = hashIn; n = nIn; }
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
READWRITE(FLATDATA(*thisPtr));
|
||||
READWRITE(FLATDATA(*this));
|
||||
return nSerSize;
|
||||
}
|
||||
|
||||
@@ -93,14 +93,14 @@ public:
|
||||
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());
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
READWRITE(thisPtr->prevout);
|
||||
READWRITE(thisPtr->scriptSig);
|
||||
READWRITE(thisPtr->nSequence);
|
||||
READWRITE(prevout);
|
||||
READWRITE(scriptSig);
|
||||
READWRITE(nSequence);
|
||||
return nSerSize;
|
||||
}
|
||||
|
||||
@@ -149,12 +149,12 @@ public:
|
||||
friend bool operator>=(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK >= b.nSatoshisPerK; }
|
||||
std::string ToString() const;
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
READWRITE(thisPtr->nSatoshisPerK);
|
||||
READWRITE(nSatoshisPerK);
|
||||
return nSerSize;
|
||||
}
|
||||
};
|
||||
@@ -176,13 +176,13 @@ public:
|
||||
|
||||
CTxOut(int64_t nValueIn, CScript scriptPubKeyIn);
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
READWRITE(thisPtr->nValue);
|
||||
READWRITE(thisPtr->scriptPubKey);
|
||||
READWRITE(nValue);
|
||||
READWRITE(scriptPubKey);
|
||||
return nSerSize;
|
||||
}
|
||||
|
||||
@@ -261,20 +261,20 @@ public:
|
||||
|
||||
CTransaction& operator=(const CTransaction& tx);
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
|
||||
|
||||
READWRITE(*const_cast<int32_t*>(&thisPtr->nVersion));
|
||||
nVersion = thisPtr->nVersion;
|
||||
READWRITE(*const_cast<std::vector<CTxIn>*>(&thisPtr->vin));
|
||||
READWRITE(*const_cast<std::vector<CTxOut>*>(&thisPtr->vout));
|
||||
READWRITE(*const_cast<uint32_t*>(&thisPtr->nLockTime));
|
||||
READWRITE(*const_cast<int32_t*>(&this->nVersion));
|
||||
nVersion = this->nVersion;
|
||||
READWRITE(*const_cast<std::vector<CTxIn>*>(&vin));
|
||||
READWRITE(*const_cast<std::vector<CTxOut>*>(&vout));
|
||||
READWRITE(*const_cast<uint32_t*>(&nLockTime));
|
||||
if (fRead)
|
||||
thisPtr->UpdateHash();
|
||||
UpdateHash();
|
||||
|
||||
return nSerSize;
|
||||
}
|
||||
@@ -324,17 +324,17 @@ struct CMutableTransaction
|
||||
CMutableTransaction();
|
||||
CMutableTransaction(const CTransaction& tx);
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
|
||||
READWRITE(thisPtr->nVersion);
|
||||
nVersion = thisPtr->nVersion;
|
||||
READWRITE(thisPtr->vin);
|
||||
READWRITE(thisPtr->vout);
|
||||
READWRITE(thisPtr->nLockTime);
|
||||
READWRITE(this->nVersion);
|
||||
nVersion = this->nVersion;
|
||||
READWRITE(vin);
|
||||
READWRITE(vout);
|
||||
READWRITE(nLockTime);
|
||||
|
||||
return nSerSize;
|
||||
}
|
||||
@@ -357,21 +357,21 @@ public:
|
||||
|
||||
CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
|
||||
size_t nSerSize = 0;
|
||||
if (!fRead) {
|
||||
uint64_t nVal = CompressAmount(thisPtr->txout.nValue);
|
||||
uint64_t nVal = CompressAmount(txout.nValue);
|
||||
READWRITE(VARINT(nVal));
|
||||
} else {
|
||||
uint64_t nVal = 0;
|
||||
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);
|
||||
return nSerSize;
|
||||
}
|
||||
@@ -427,12 +427,12 @@ public:
|
||||
// undo information for all txins
|
||||
std::vector<CTxInUndo> vprevout;
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
READWRITE(thisPtr->vprevout);
|
||||
READWRITE(vprevout);
|
||||
return nSerSize;
|
||||
}
|
||||
};
|
||||
@@ -462,19 +462,19 @@ public:
|
||||
SetNull();
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
|
||||
READWRITE(thisPtr->nVersion);
|
||||
nVersion = thisPtr->nVersion;
|
||||
READWRITE(thisPtr->hashPrevBlock);
|
||||
READWRITE(thisPtr->hashMerkleRoot);
|
||||
READWRITE(thisPtr->nTime);
|
||||
READWRITE(thisPtr->nBits);
|
||||
READWRITE(thisPtr->nNonce);
|
||||
READWRITE(this->nVersion);
|
||||
nVersion = this->nVersion;
|
||||
READWRITE(hashPrevBlock);
|
||||
READWRITE(hashMerkleRoot);
|
||||
READWRITE(nTime);
|
||||
READWRITE(nBits);
|
||||
READWRITE(nNonce);
|
||||
|
||||
return nSerSize;
|
||||
}
|
||||
@@ -523,14 +523,14 @@ public:
|
||||
*((CBlockHeader*)this) = header;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
|
||||
READWRITE(*(CBlockHeader*)thisPtr);
|
||||
READWRITE(thisPtr->vtx);
|
||||
READWRITE(*(CBlockHeader*)this);
|
||||
READWRITE(vtx);
|
||||
|
||||
return nSerSize;
|
||||
}
|
||||
@@ -577,15 +577,15 @@ struct CBlockLocator
|
||||
vHave = vHaveIn;
|
||||
}
|
||||
|
||||
IMPLEMENT_SERIALIZE
|
||||
IMPLEMENT_SERIALIZE;
|
||||
|
||||
template <typename T, typename Stream, typename Operation>
|
||||
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
template <typename Stream, typename Operation>
|
||||
inline size_t SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||
size_t nSerSize = 0;
|
||||
|
||||
if (!(nType & SER_GETHASH))
|
||||
READWRITE(nVersion);
|
||||
READWRITE(thisPtr->vHave);
|
||||
READWRITE(vHave);
|
||||
|
||||
return nSerSize;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user