mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
Convert everything except wallet/qt to new serialization
This commit is contained in:
parent
2b1f85e8c5
commit
4eb5643e35
17 changed files with 70 additions and 212 deletions
|
@ -20,9 +20,7 @@
|
|||
struct nontrivial_t {
|
||||
int x;
|
||||
nontrivial_t() :x(-1) {}
|
||||
ADD_SERIALIZE_METHODS
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {READWRITE(x);}
|
||||
SERIALIZE_METHODS(nontrivial_t, obj) { READWRITE(obj.x); }
|
||||
};
|
||||
static_assert(!IS_TRIVIALLY_CONSTRUCTIBLE<nontrivial_t>::value,
|
||||
"expected nontrivial_t to not be trivially constructible");
|
||||
|
|
10
src/bloom.h
10
src/bloom.h
|
@ -66,15 +66,7 @@ public:
|
|||
CBloomFilter(const unsigned int nElements, const double nFPRate, const unsigned int nTweak, unsigned char nFlagsIn);
|
||||
CBloomFilter() : isFull(true), isEmpty(false), nHashFuncs(0), nTweak(0), nFlags(0) {}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(vData);
|
||||
READWRITE(nHashFuncs);
|
||||
READWRITE(nTweak);
|
||||
READWRITE(nFlags);
|
||||
}
|
||||
SERIALIZE_METHODS(CBloomFilter, obj) { READWRITE(obj.vData, obj.nHashFuncs, obj.nTweak, obj.nFlags); }
|
||||
|
||||
void insert(const std::vector<unsigned char>& vKey);
|
||||
void insert(const COutPoint& outpoint);
|
||||
|
|
|
@ -16,13 +16,7 @@ struct FlatFilePos
|
|||
int nFile;
|
||||
unsigned int nPos;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(VARINT_MODE(nFile, VarIntMode::NONNEGATIVE_SIGNED));
|
||||
READWRITE(VARINT(nPos));
|
||||
}
|
||||
SERIALIZE_METHODS(FlatFilePos, obj) { READWRITE(VARINT_MODE(obj.nFile, VarIntMode::NONNEGATIVE_SIGNED), VARINT(obj.nPos)); }
|
||||
|
||||
FlatFilePos() : nFile(-1), nPos(0) {}
|
||||
|
||||
|
|
|
@ -39,14 +39,7 @@ struct DBVal {
|
|||
uint256 header;
|
||||
FlatFilePos pos;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(hash);
|
||||
READWRITE(header);
|
||||
READWRITE(pos);
|
||||
}
|
||||
SERIALIZE_METHODS(DBVal, obj) { READWRITE(obj.hash, obj.header, obj.pos); }
|
||||
};
|
||||
|
||||
struct DBHeightKey {
|
||||
|
@ -78,17 +71,14 @@ struct DBHashKey {
|
|||
|
||||
explicit DBHashKey(const uint256& hash_in) : hash(hash_in) {}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
SERIALIZE_METHODS(DBHashKey, obj) {
|
||||
char prefix = DB_BLOCK_HASH;
|
||||
READWRITE(prefix);
|
||||
if (prefix != DB_BLOCK_HASH) {
|
||||
throw std::ios_base::failure("Invalid format for block filter index DB hash key");
|
||||
}
|
||||
|
||||
READWRITE(hash);
|
||||
READWRITE(obj.hash);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -21,12 +21,10 @@ struct CDiskTxPos : public FlatFilePos
|
|||
{
|
||||
unsigned int nTxOffset; // after header
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITEAS(FlatFilePos, *this);
|
||||
READWRITE(VARINT(nTxOffset));
|
||||
SERIALIZE_METHODS(CDiskTxPos, obj)
|
||||
{
|
||||
READWRITEAS(FlatFilePos, obj);
|
||||
READWRITE(VARINT(obj.nTxOffset));
|
||||
}
|
||||
|
||||
CDiskTxPos(const FlatFilePos &blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
|
||||
|
|
|
@ -99,12 +99,7 @@ class CNetAddr
|
|||
friend bool operator!=(const CNetAddr& a, const CNetAddr& b) { return !(a == b); }
|
||||
friend bool operator<(const CNetAddr& a, const CNetAddr& b);
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(ip);
|
||||
}
|
||||
SERIALIZE_METHODS(CNetAddr, obj) { READWRITE(obj.ip); }
|
||||
|
||||
friend class CSubNet;
|
||||
};
|
||||
|
@ -136,14 +131,7 @@ class CSubNet
|
|||
friend bool operator!=(const CSubNet& a, const CSubNet& b) { return !(a == b); }
|
||||
friend bool operator<(const CSubNet& a, const CSubNet& b);
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(network);
|
||||
READWRITE(netmask);
|
||||
READWRITE(valid);
|
||||
}
|
||||
SERIALIZE_METHODS(CSubNet, obj) { READWRITE(obj.network, obj.netmask, obj.valid); }
|
||||
};
|
||||
|
||||
/** A combination of a network address (CNetAddr) and a (TCP) port */
|
||||
|
@ -171,13 +159,7 @@ class CService : public CNetAddr
|
|||
CService(const struct in6_addr& ipv6Addr, unsigned short port);
|
||||
explicit CService(const struct sockaddr_in6& addr);
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(ip);
|
||||
READWRITE(Using<BigEndianFormatter<2>>(port));
|
||||
}
|
||||
SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); }
|
||||
};
|
||||
|
||||
#endif // BITCOIN_NETADDRESS_H
|
||||
|
|
|
@ -35,16 +35,7 @@ public:
|
|||
m_coins_count(coins_count),
|
||||
m_nchaintx(nchaintx) { }
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
{
|
||||
READWRITE(m_base_blockhash);
|
||||
READWRITE(m_coins_count);
|
||||
READWRITE(m_nchaintx);
|
||||
}
|
||||
|
||||
SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count, obj.m_nchaintx); }
|
||||
};
|
||||
|
||||
#endif // BITCOIN_NODE_UTXO_SNAPSHOT_H
|
||||
|
|
|
@ -48,12 +48,7 @@ public:
|
|||
CFeeRate& operator+=(const CFeeRate& a) { nSatoshisPerK += a.nSatoshisPerK; return *this; }
|
||||
std::string ToString() const;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(nSatoshisPerK);
|
||||
}
|
||||
SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); }
|
||||
};
|
||||
|
||||
#endif // BITCOIN_POLICY_FEERATE_H
|
||||
|
|
|
@ -33,17 +33,7 @@ public:
|
|||
SetNull();
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(this->nVersion);
|
||||
READWRITE(hashPrevBlock);
|
||||
READWRITE(hashMerkleRoot);
|
||||
READWRITE(nTime);
|
||||
READWRITE(nBits);
|
||||
READWRITE(nNonce);
|
||||
}
|
||||
SERIALIZE_METHODS(CBlockHeader, obj) { READWRITE(obj.nVersion, obj.hashPrevBlock, obj.hashMerkleRoot, obj.nTime, obj.nBits, obj.nNonce); }
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
|
@ -89,12 +79,10 @@ public:
|
|||
*(static_cast<CBlockHeader*>(this)) = header;
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITEAS(CBlockHeader, *this);
|
||||
READWRITE(vtx);
|
||||
SERIALIZE_METHODS(CBlock, obj)
|
||||
{
|
||||
READWRITEAS(CBlockHeader, obj);
|
||||
READWRITE(obj.vtx);
|
||||
}
|
||||
|
||||
void SetNull()
|
||||
|
@ -131,14 +119,12 @@ struct CBlockLocator
|
|||
|
||||
explicit CBlockLocator(const std::vector<uint256>& vHaveIn) : vHave(vHaveIn) {}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
SERIALIZE_METHODS(CBlockLocator, obj)
|
||||
{
|
||||
int nVersion = s.GetVersion();
|
||||
if (!(s.GetType() & SER_GETHASH))
|
||||
READWRITE(nVersion);
|
||||
READWRITE(vHave);
|
||||
READWRITE(obj.vHave);
|
||||
}
|
||||
|
||||
void SetNull()
|
||||
|
|
|
@ -26,13 +26,7 @@ public:
|
|||
COutPoint(): n(NULL_INDEX) { }
|
||||
COutPoint(const uint256& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { }
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(hash);
|
||||
READWRITE(n);
|
||||
}
|
||||
SERIALIZE_METHODS(COutPoint, obj) { READWRITE(obj.hash, obj.n); }
|
||||
|
||||
void SetNull() { hash.SetNull(); n = NULL_INDEX; }
|
||||
bool IsNull() const { return (hash.IsNull() && n == NULL_INDEX); }
|
||||
|
@ -103,14 +97,7 @@ public:
|
|||
explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
|
||||
CTxIn(uint256 hashPrevTx, uint32_t nOut, CScript scriptSigIn=CScript(), uint32_t nSequenceIn=SEQUENCE_FINAL);
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(prevout);
|
||||
READWRITE(scriptSig);
|
||||
READWRITE(nSequence);
|
||||
}
|
||||
SERIALIZE_METHODS(CTxIn, obj) { READWRITE(obj.prevout, obj.scriptSig, obj.nSequence); }
|
||||
|
||||
friend bool operator==(const CTxIn& a, const CTxIn& b)
|
||||
{
|
||||
|
@ -143,13 +130,7 @@ public:
|
|||
|
||||
CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn);
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(nValue);
|
||||
READWRITE(scriptPubKey);
|
||||
}
|
||||
SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey); }
|
||||
|
||||
void SetNull()
|
||||
{
|
||||
|
|
|
@ -46,16 +46,7 @@ public:
|
|||
std::string GetCommand() const;
|
||||
bool IsValid(const MessageStartChars& messageStart) const;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
{
|
||||
READWRITE(pchMessageStart);
|
||||
READWRITE(pchCommand);
|
||||
READWRITE(nMessageSize);
|
||||
READWRITE(pchChecksum);
|
||||
}
|
||||
SERIALIZE_METHODS(CMessageHeader, obj) { READWRITE(obj.pchMessageStart, obj.pchCommand, obj.nMessageSize, obj.pchChecksum); }
|
||||
|
||||
char pchMessageStart[MESSAGE_START_SIZE];
|
||||
char pchCommand[COMMAND_SIZE];
|
||||
|
@ -327,23 +318,19 @@ public:
|
|||
|
||||
void Init();
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
SERIALIZE_METHODS(CAddress, obj)
|
||||
{
|
||||
if (ser_action.ForRead())
|
||||
Init();
|
||||
SER_READ(obj, obj.Init());
|
||||
int nVersion = s.GetVersion();
|
||||
if (s.GetType() & SER_DISK)
|
||||
if (s.GetType() & SER_DISK) {
|
||||
READWRITE(nVersion);
|
||||
}
|
||||
if ((s.GetType() & SER_DISK) ||
|
||||
(nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH)))
|
||||
READWRITE(nTime);
|
||||
uint64_t nServicesInt = nServices;
|
||||
READWRITE(nServicesInt);
|
||||
nServices = static_cast<ServiceFlags>(nServicesInt);
|
||||
READWRITEAS(CService, *this);
|
||||
(nVersion >= CADDR_TIME_VERSION && !(s.GetType() & SER_GETHASH))) {
|
||||
READWRITE(obj.nTime);
|
||||
}
|
||||
READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
|
||||
READWRITEAS(CService, obj);
|
||||
}
|
||||
|
||||
// TODO: make private (improves encapsulation)
|
||||
|
@ -382,14 +369,7 @@ public:
|
|||
CInv();
|
||||
CInv(int typeIn, const uint256& hashIn);
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
{
|
||||
READWRITE(type);
|
||||
READWRITE(hash);
|
||||
}
|
||||
SERIALIZE_METHODS(CInv, obj) { READWRITE(obj.type, obj.hash); }
|
||||
|
||||
friend bool operator<(const CInv& a, const CInv& b);
|
||||
|
||||
|
|
|
@ -49,18 +49,13 @@ struct CCoin {
|
|||
uint32_t nHeight;
|
||||
CTxOut out;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
CCoin() : nHeight(0) {}
|
||||
explicit CCoin(Coin&& in) : nHeight(in.nHeight), out(std::move(in.out)) {}
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
SERIALIZE_METHODS(CCoin, obj)
|
||||
{
|
||||
uint32_t nTxVerDummy = 0;
|
||||
READWRITE(nTxVerDummy);
|
||||
READWRITE(nHeight);
|
||||
READWRITE(out);
|
||||
READWRITE(nTxVerDummy, obj.nHeight, obj.out);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -18,13 +18,7 @@ struct KeyOriginInfo
|
|||
return std::equal(std::begin(a.fingerprint), std::end(a.fingerprint), std::begin(b.fingerprint)) && a.path == b.path;
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
{
|
||||
READWRITE(fingerprint);
|
||||
READWRITE(path);
|
||||
}
|
||||
SERIALIZE_METHODS(KeyOriginInfo, obj) { READWRITE(obj.fingerprint, obj.path); }
|
||||
|
||||
void clear()
|
||||
{
|
||||
|
|
|
@ -412,12 +412,7 @@ public:
|
|||
CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { }
|
||||
CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { }
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITEAS(CScriptBase, *this);
|
||||
}
|
||||
SERIALIZE_METHODS(CScript, obj) { READWRITEAS(CScriptBase, obj); }
|
||||
|
||||
CScript& operator+=(const CScript& b)
|
||||
{
|
||||
|
|
|
@ -331,24 +331,26 @@ struct StringContentsSerializer {
|
|||
}
|
||||
StringContentsSerializer& operator+=(const StringContentsSerializer& s) { return *this += s.str; }
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
template<typename Stream>
|
||||
void Serialize(Stream& s) const
|
||||
{
|
||||
for (size_t i = 0; i < str.size(); i++) {
|
||||
s << str[i];
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
if (ser_action.ForRead()) {
|
||||
str.clear();
|
||||
char c = 0;
|
||||
while (true) {
|
||||
try {
|
||||
READWRITE(c);
|
||||
str.push_back(c);
|
||||
} catch (const std::ios_base::failure&) {
|
||||
break;
|
||||
}
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s)
|
||||
{
|
||||
str.clear();
|
||||
char c = 0;
|
||||
while (true) {
|
||||
try {
|
||||
s >> c;
|
||||
str.push_back(c);
|
||||
} catch (const std::ios_base::failure&) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < str.size(); i++)
|
||||
READWRITE(str[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,15 +29,13 @@ public:
|
|||
memcpy(charstrval, charstrvalin, sizeof(charstrval));
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(intval);
|
||||
READWRITE(boolval);
|
||||
READWRITE(stringval);
|
||||
READWRITE(charstrval);
|
||||
READWRITE(txval);
|
||||
SERIALIZE_METHODS(CSerializeMethodsTestSingle, obj)
|
||||
{
|
||||
READWRITE(obj.intval);
|
||||
READWRITE(obj.boolval);
|
||||
READWRITE(obj.stringval);
|
||||
READWRITE(obj.charstrval);
|
||||
READWRITE(obj.txval);
|
||||
}
|
||||
|
||||
bool operator==(const CSerializeMethodsTestSingle& rhs)
|
||||
|
@ -54,11 +52,10 @@ class CSerializeMethodsTestMany : public CSerializeMethodsTestSingle
|
|||
{
|
||||
public:
|
||||
using CSerializeMethodsTestSingle::CSerializeMethodsTestSingle;
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action) {
|
||||
READWRITE(intval, boolval, stringval, charstrval, txval);
|
||||
SERIALIZE_METHODS(CSerializeMethodsTestMany, obj)
|
||||
{
|
||||
READWRITE(obj.intval, obj.boolval, obj.stringval, obj.charstrval, obj.txval);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
14
src/txdb.cpp
14
src/txdb.cpp
|
@ -36,19 +36,7 @@ struct CoinEntry {
|
|||
char key;
|
||||
explicit CoinEntry(const COutPoint* ptr) : outpoint(const_cast<COutPoint*>(ptr)), key(DB_COIN) {}
|
||||
|
||||
template<typename Stream>
|
||||
void Serialize(Stream &s) const {
|
||||
s << key;
|
||||
s << outpoint->hash;
|
||||
s << VARINT(outpoint->n);
|
||||
}
|
||||
|
||||
template<typename Stream>
|
||||
void Unserialize(Stream& s) {
|
||||
s >> key;
|
||||
s >> outpoint->hash;
|
||||
s >> VARINT(outpoint->n);
|
||||
}
|
||||
SERIALIZE_METHODS(CoinEntry, obj) { READWRITE(obj.key, obj.outpoint->hash, VARINT(obj.outpoint->n)); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue