diff --git a/src/amount.h b/src/amount.h --- a/src/amount.h +++ b/src/amount.h @@ -140,12 +140,7 @@ std::string ToString() const; // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(amount); - } + SERIALIZE_METHODS(Amount, obj) { READWRITE(obj.amount); } }; static constexpr Amount SATOSHI = Amount::satoshi(); diff --git a/src/avalanche/delegation.h b/src/avalanche/delegation.h --- a/src/avalanche/delegation.h +++ b/src/avalanche/delegation.h @@ -27,13 +27,7 @@ CPubKey pubkey; std::array sig; - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(pubkey); - READWRITE(sig); - } + SERIALIZE_METHODS(Level, obj) { READWRITE(obj.pubkey, obj.sig); } }; std::vector levels; @@ -49,16 +43,9 @@ const DelegationId &getId() const { return dgid; } const ProofId &getProofId() const { return proofid; } - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(proofid); - READWRITE(levels); - - if (ser_action.ForRead()) { - dgid = computeDelegationId(); - } + SERIALIZE_METHODS(Delegation, obj) { + READWRITE(obj.proofid, obj.levels); + SER_READ(obj, obj.dgid = obj.computeDelegationId()); } bool verify(DelegationState &state, const Proof &proof, diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -263,12 +263,8 @@ } // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(response); - READWRITE(sig); + SERIALIZE_METHODS(TCPResponse, obj) { + READWRITE(obj.response, obj.sig); } }; } // namespace diff --git a/src/avalanche/proof.h b/src/avalanche/proof.h --- a/src/avalanche/proof.h +++ b/src/avalanche/proof.h @@ -35,14 +35,8 @@ : utxo(utxo_), amount(amount_), height(height_ << 1 | is_coinbase), pubkey(std::move(pubkey_)) {} - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(utxo); - READWRITE(amount); - READWRITE(height); - READWRITE(pubkey); + SERIALIZE_METHODS(Stake, obj) { + READWRITE(obj.utxo, obj.amount, obj.height, obj.pubkey); } const COutPoint &getUTXO() const { return utxo; } @@ -63,13 +57,7 @@ SignedStake(Stake stake_, std::array sig_) : stake(std::move(stake_)), sig(std::move(sig_)) {} - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(stake); - READWRITE(sig); - } + SERIALIZE_METHODS(SignedStake, obj) { READWRITE(obj.stake, obj.sig); } const Stake &getStake() const { return stake; } const std::array &getSignature() const { return sig; } @@ -94,18 +82,9 @@ master(std::move(master_)), stakes(std::move(stakes_)), proofid(computeProofId()) {} - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(sequence); - READWRITE(expirationTime); - READWRITE(master); - READWRITE(stakes); - - if (ser_action.ForRead()) { - proofid = computeProofId(); - } + SERIALIZE_METHODS(Proof, obj) { + READWRITE(obj.sequence, obj.expirationTime, obj.master, obj.stakes); + SER_READ(obj, obj.proofid = obj.computeProofId()); } uint64_t getSequence() const { return sequence; } diff --git a/src/avalanche/protocol.h b/src/avalanche/protocol.h --- a/src/avalanche/protocol.h +++ b/src/avalanche/protocol.h @@ -27,13 +27,7 @@ uint32_t GetError() const { return error; } // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(error); - READWRITE(hash); - } + SERIALIZE_METHODS(Vote, obj) { READWRITE(obj.error, obj.hash); } }; class Response { @@ -51,13 +45,8 @@ const std::vector &GetVotes() const { return votes; } // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(round); - READWRITE(cooldown); - READWRITE(votes); + SERIALIZE_METHODS(Response, obj) { + READWRITE(obj.round, obj.cooldown, obj.votes); } }; @@ -69,16 +58,11 @@ Poll(uint64_t roundIn, std::vector invsIn) : round(roundIn), invs(invsIn) {} + uint64_t GetRound() { return round; } const std::vector &GetInvs() const { return invs; } // serialization support - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(round); - READWRITE(invs); - } + SERIALIZE_METHODS(Poll, obj) { READWRITE(obj.round, obj.invs); } }; class Hello { @@ -89,14 +73,10 @@ Hello(Delegation delegationIn, std::array sigIn) : delegation(std::move(delegationIn)), sig(sigIn) {} - // serialization support - ADD_SERIALIZE_METHODS; + std::array GetSig() { return sig; } - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(delegation); - READWRITE(sig); - } + // serialization support + SERIALIZE_METHODS(Hello, obj) { READWRITE(obj.delegation, obj.sig); } }; } // namespace avalanche diff --git a/src/blockstatus.h b/src/blockstatus.h --- a/src/blockstatus.h +++ b/src/blockstatus.h @@ -109,12 +109,7 @@ return BlockStatus(status & ~PARKED_MASK); } - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(VARINT(status)); - } + SERIALIZE_METHODS(BlockStatus, obj) { READWRITE(VARINT(obj.status)); } friend constexpr bool operator==(const BlockStatus a, const BlockStatus b) { return a.status == b.status; diff --git a/src/feerate.h b/src/feerate.h --- a/src/feerate.h +++ b/src/feerate.h @@ -84,12 +84,7 @@ } std::string ToString() const; - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(nSatoshisPerK); - } + SERIALIZE_METHODS(CFeeRate, obj) { READWRITE(obj.nSatoshisPerK); } }; #endif // BITCOIN_FEERATE_H diff --git a/src/seeder/db.h b/src/seeder/db.h --- a/src/seeder/db.h +++ b/src/seeder/db.h @@ -53,13 +53,8 @@ weight = weight * f + (1.0 - f); } - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { - READWRITE(weight); - READWRITE(count); - READWRITE(reliability); + SERIALIZE_METHODS(CAddrStat, obj) { + READWRITE(obj.weight, obj.count, obj.reliability); } friend class SeederAddrInfo; @@ -207,43 +202,31 @@ friend class CAddrDb; - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream &s, Operation ser_action) { + SERIALIZE_METHODS(SeederAddrInfo, obj) { uint8_t version = 4; - READWRITE(version); - READWRITE(ip); - READWRITE(services); - READWRITE(lastTry); - uint8_t tried = ourLastTry != 0; + READWRITE(version, obj.ip, obj.services, obj.lastTry); + uint8_t tried = obj.ourLastTry != 0; READWRITE(tried); if (!tried) { return; } - READWRITE(ourLastTry); - READWRITE(ignoreTill); - READWRITE(stat2H); - READWRITE(stat8H); - READWRITE(stat1D); - READWRITE(stat1W); + READWRITE(obj.ourLastTry, obj.ignoreTill, obj.stat2H, obj.stat8H, + obj.stat1D, obj.stat1W); if (version >= 1) { - READWRITE(stat1M); - } else if (!ser_action.ForRead()) { - *((CAddrStat *)(&stat1M)) = stat1W; + READWRITE(obj.stat1M); + } else { + SER_WRITE(obj, *((CAddrStat *)(&obj.stat1M)) = obj.stat1W); } - READWRITE(total); - READWRITE(success); - READWRITE(clientVersion); + READWRITE(obj.total, obj.success, obj.clientVersion); if (version >= 2) { - READWRITE(clientSubVersion); + READWRITE(obj.clientSubVersion); } if (version >= 3) { - READWRITE(blocks); + READWRITE(obj.blocks); } if (version >= 4) { - READWRITE(ourLastSuccess); + READWRITE(obj.ourLastSuccess); } } };