diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index 79c80e9eafcc5..14e3e3e959f2b 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -143,13 +143,10 @@ class CDeterministicMNStateDiff #undef DMN_STATE_DIFF_LINE } - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) + SERIALIZE_METHODS(CDeterministicMNStateDiff, obj) { - READWRITE(VARINT(fields)); -#define DMN_STATE_DIFF_LINE(f) if (fields & Field_##f) READWRITE(state.f); + READWRITE(VARINT(obj.fields)); +#define DMN_STATE_DIFF_LINE(f) if (obj.fields & Field_##f) READWRITE(obj.state.f); DMN_STATE_DIFF_ALL_FIELDS #undef DMN_STATE_DIFF_LINE } @@ -193,22 +190,15 @@ class CDeterministicMN CDeterministicMNStateCPtr pdmnState; public: - template - inline void SerializationOp(Stream& s, Operation ser_action) + SERIALIZE_METHODS(CDeterministicMN, obj) { - READWRITE(proTxHash); - READWRITE(VARINT(internalId)); - READWRITE(collateralOutpoint); - READWRITE(nOperatorReward); - READWRITE(pdmnState); + READWRITE(obj.proTxHash); + READWRITE(VARINT(obj.internalId)); + READWRITE(obj.collateralOutpoint); + READWRITE(obj.nOperatorReward); + READWRITE(obj.pdmnState); } - template - void Serialize(Stream& s) const { NCONST_PTR(this)->SerializationOp(s, CSerActionSerialize()); } - - template - void Unserialize(Stream& s) { SerializationOp(s, CSerActionUnserialize()); } - uint64_t GetInternalId() const; std::string ToString() const; @@ -280,18 +270,12 @@ class CDeterministicMNList { } - template - inline void SerializationOpBase(Stream& s, Operation ser_action) - { - READWRITE(blockHash); - READWRITE(nHeight); - READWRITE(nTotalRegisteredCount); - } - template void Serialize(Stream& s) const { - NCONST_PTR(this)->SerializationOpBase(s, CSerActionSerialize()); + s << blockHash; + s << nHeight; + s << nTotalRegisteredCount; // Serialize the map as a vector WriteCompactSize(s, mnMap.size()); for (const auto& p : mnMap) { @@ -305,8 +289,9 @@ class CDeterministicMNList mnUniquePropertyMap = MnUniquePropertyMap(); mnInternalIdMap = MnInternalIdMap(); - SerializationOpBase(s, CSerActionUnserialize()); - + s >> blockHash; + s >> nHeight; + s >> nTotalRegisteredCount; size_t cnt = ReadCompactSize(s); for (size_t i = 0; i < cnt; i++) { AddMN(std::make_shared(deserialize, s), false); diff --git a/src/sapling/incrementalmerkletree.h b/src/sapling/incrementalmerkletree.h index 2b521b0a50325..b98c564f82a71 100644 --- a/src/sapling/incrementalmerkletree.h +++ b/src/sapling/incrementalmerkletree.h @@ -23,33 +23,35 @@ class MerklePath { std::vector> authentication_path; std::vector index; - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) + template + void Serialize(Stream &s) const { std::vector> pathBytes; uint64_t indexInt; - if (ser_action.ForRead()) { - READWRITE(pathBytes); - READWRITE(indexInt); - MerklePath &us = *(const_cast(this)); - for (size_t i = 0; i < pathBytes.size(); i++) { - us.authentication_path.push_back(convertBytesVectorToVector(pathBytes[i])); - us.index.push_back((indexInt >> ((pathBytes.size() - 1) - i)) & 1); - } - } else { - assert(authentication_path.size() == index.size()); - pathBytes.resize(authentication_path.size()); - for (size_t i = 0; i < authentication_path.size(); i++) { - pathBytes[i].resize((authentication_path[i].size()+7)/8); - for (unsigned int p = 0; p < authentication_path[i].size(); p++) { - pathBytes[i][p / 8] |= authentication_path[i][p] << (7-(p % 8)); - } + assert(authentication_path.size() == index.size()); + pathBytes.resize(authentication_path.size()); + for (size_t i = 0; i < authentication_path.size(); i++) { + pathBytes[i].resize((authentication_path[i].size()+7)/8); + for (unsigned int p = 0; p < authentication_path[i].size(); p++) { + pathBytes[i][p / 8] |= authentication_path[i][p] << (7-(p % 8)); } - indexInt = convertVectorToInt(index); - READWRITE(pathBytes); - READWRITE(indexInt); + } + indexInt = convertVectorToInt(index); + ::Serialize(s, pathBytes); + ::Serialize(s, indexInt); + } + + template + void Unserialize(Stream &s) + { + std::vector> pathBytes; + uint64_t indexInt; + ::Unserialize(s, pathBytes); + ::Unserialize(s, indexInt); + MerklePath &us = *(const_cast(this)); + for (size_t i = 0; i < pathBytes.size(); i++) { + us.authentication_path.push_back(convertBytesVectorToVector(pathBytes[i])); + us.index.push_back((indexInt >> ((pathBytes.size() - 1) - i)) & 1); } } @@ -110,16 +112,10 @@ friend class IncrementalWitness; return IncrementalWitness(*this); } - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) + SERIALIZE_METHODS(IncrementalMerkleTree, obj) { - READWRITE(left); - READWRITE(right); - READWRITE(parents); - - wfcheck(); + READWRITE(obj.left, obj.right, obj.parents); + obj.wfcheck(); } static Hash empty_root() { @@ -181,16 +177,10 @@ friend class IncrementalMerkleTree; void append(Hash obj); - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) + SERIALIZE_METHODS(IncrementalWitness, obj) { - READWRITE(tree); - READWRITE(filled); - READWRITE(cursor); - - cursor_depth = tree.next_depth(filled.size()); + READWRITE(obj.tree, obj.filled, obj.cursor); + SER_READ(obj, obj.cursor_depth = obj.tree.next_depth(obj.filled.size())); } template diff --git a/src/sapling/sapling_transaction.h b/src/sapling/sapling_transaction.h index 250d5e24d35c1..d19aabac2e402 100644 --- a/src/sapling/sapling_transaction.h +++ b/src/sapling/sapling_transaction.h @@ -117,16 +117,7 @@ class SaplingTxData std::vector vShieldedOutput; binding_sig_t bindingSig = {{0}}; - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action) - { - READWRITE(*const_cast(&valueBalance)); - READWRITE(*const_cast*>(&vShieldedSpend)); - READWRITE(*const_cast*>(&vShieldedOutput)); - READWRITE(*const_cast(&bindingSig)); - } + SERIALIZE_METHODS(SaplingTxData, obj) { READWRITE(obj.valueBalance, obj.vShieldedSpend, obj.vShieldedOutput, obj.bindingSig); } explicit SaplingTxData() : valueBalance(0), vShieldedSpend(), vShieldedOutput() { } explicit SaplingTxData(const SaplingTxData& from) : valueBalance(from.valueBalance), vShieldedSpend(from.vShieldedSpend), vShieldedOutput(from.vShieldedOutput), bindingSig(from.bindingSig) {}