Skip to content

Commit

Permalink
Convert to new serialization (step 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Jul 3, 2021
1 parent dc0fc95 commit cf06950
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 254 deletions.
25 changes: 9 additions & 16 deletions src/budget/budgetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,23 @@ class CBudgetManager
// Remove proposal/budget by FeeTx (called when a block is disconnected)
void RemoveByFeeTxId(const uint256& feeTxId);

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CBudgetManager, obj)
{
{
LOCK(cs_proposals);
READWRITE(mapProposals);
READWRITE(mapFeeTxToProposal);
LOCK(obj.cs_proposals);
READWRITE(obj.mapProposals, obj.mapFeeTxToProposal);
}
{
LOCK(cs_votes);
READWRITE(mapSeenProposalVotes);
READWRITE(mapOrphanProposalVotes);
LOCK(obj.cs_votes);
READWRITE(obj.mapSeenProposalVotes, obj.mapOrphanProposalVotes);
}
{
LOCK(cs_budgets);
READWRITE(mapFinalizedBudgets);
READWRITE(mapFeeTxToBudget);
READWRITE(mapUnconfirmedFeeTx);
LOCK(obj.cs_budgets);
READWRITE(obj.mapFinalizedBudgets, obj.mapFeeTxToBudget, obj.mapUnconfirmedFeeTx);
}
{
LOCK(cs_finalizedvotes);
READWRITE(mapSeenFinalizedBudgetVotes);
READWRITE(mapOrphanFinalizedBudgetVotes);
LOCK(obj.cs_finalizedvotes);
READWRITE(obj.mapSeenFinalizedBudgetVotes, obj.mapOrphanFinalizedBudgetVotes);
}
}
};
Expand Down
17 changes: 2 additions & 15 deletions src/budget/budgetvote.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class CBudgetVote : public CSignedMessage
{
public:
enum VoteDirection {
enum VoteDirection : uint32_t {
VOTE_ABSTAIN = 0,
VOTE_YES = 1,
VOTE_NO = 2
Expand Down Expand Up @@ -64,20 +64,7 @@ class CBudgetVote : public CSignedMessage
void SetTime(const int64_t& _nTime) { nTime = _nTime; }
void SetValid(bool _fValid) { fValid = _fValid; }

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vin);
READWRITE(nProposalHash);
int nVoteInt = (int) nVote;
READWRITE(nVoteInt);
if (ser_action.ForRead())
nVote = (VoteDirection) nVoteInt;
READWRITE(nTime);
READWRITE(vchSig);
READWRITE(nMessVersion);
}
SERIALIZE_METHODS(CBudgetVote, obj) { READWRITE(obj.vin, obj.nProposalHash, Using<CustomUintFormatter<4>>(obj.nVote), obj.nTime, obj.vchSig, obj.nMessVersion); }
};

#endif // BUDGET_VOTE_H
11 changes: 1 addition & 10 deletions src/budget/finalizedbudgetvote.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,7 @@ class CFinalizedBudgetVote : public CSignedMessage
void SetTime(const int64_t& _nTime) { nTime = _nTime; }
void SetValid(bool _fValid) { fValid = _fValid; }

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vin);
READWRITE(nBudgetHash);
READWRITE(nTime);
READWRITE(vchSig);
READWRITE(nMessVersion);
}
SERIALIZE_METHODS(CFinalizedBudgetVote, obj) { READWRITE(obj.vin, obj.nBudgetHash, obj.nTime, obj.vchSig, obj.nMessVersion); }
};

#endif // FINALIZED_BUDGET_VOTE_H
43 changes: 17 additions & 26 deletions src/evo/providertx.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,23 @@ class ProRegPL
std::vector<unsigned char> vchSig;

public:
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(ProRegPL, obj)
{
READWRITE(nVersion);
READWRITE(nType);
READWRITE(nMode);
READWRITE(collateralOutpoint);
READWRITE(addr);
READWRITE(keyIDOwner);
READWRITE(keyIDOperator);
READWRITE(keyIDVoting);
READWRITE(scriptPayout);
READWRITE(nOperatorReward);
READWRITE(scriptOperatorPayout);
READWRITE(inputsHash);
READWRITE(obj.nVersion);
READWRITE(obj.nType);
READWRITE(obj.nMode);
READWRITE(obj.collateralOutpoint);
READWRITE(obj.addr);
READWRITE(obj.keyIDOwner);
READWRITE(obj.keyIDOperator);
READWRITE(obj.keyIDVoting);
READWRITE(obj.scriptPayout);
READWRITE(obj.nOperatorReward);
READWRITE(obj.scriptOperatorPayout);
READWRITE(obj.inputsHash);
if (!(s.GetType() & SER_GETHASH)) {
READWRITE(vchSig);
READWRITE(obj.vchSig);
}
}

Expand All @@ -82,18 +80,11 @@ class ProUpServPL
std::vector<unsigned char> vchSig;

public:
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(ProUpServPL, obj)
{
READWRITE(nVersion);
READWRITE(proTxHash);
READWRITE(addr);
READWRITE(scriptOperatorPayout);
READWRITE(inputsHash);
READWRITE(obj.nVersion, obj.proTxHash, obj.addr, obj.scriptOperatorPayout, obj.inputsHash);
if (!(s.GetType() & SER_GETHASH)) {
READWRITE(vchSig);
READWRITE(obj.vchSig);
}
}

Expand Down
24 changes: 6 additions & 18 deletions src/libzerocoin/CoinSpend.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,15 @@ class CoinSpend
CBigNum CalculateValidSerial(ZerocoinParams* params);
std::string ToString() const;

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CoinSpend, obj)
{
READWRITE(denomination);
READWRITE(ptxHash);
READWRITE(accChecksum);
READWRITE(accCommitmentToCoinValue);
READWRITE(serialCommitmentToCoinValue);
READWRITE(coinSerialNumber);
READWRITE(accumulatorPoK);
READWRITE(serialNumberSoK);
READWRITE(commitmentPoK);

READWRITE(obj.denomination, obj.ptxHash, obj.accChecksum, obj.accCommitmentToCoinValue);
READWRITE(obj.serialCommitmentToCoinValue, obj.coinSerialNumber, obj.accumulatorPoK);
READWRITE(obj.serialNumberSoK, obj.commitmentPoK);
try {
READWRITE(version);
READWRITE(pubkey);
READWRITE(vchSig);
READWRITE(spendType);
READWRITE(obj.version, obj.pubkey, obj.vchSig, obj.spendType);
} catch (...) {
version = 1;
SER_READ(obj, obj.version = 1);
}
}

Expand Down
12 changes: 1 addition & 11 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,7 @@ class CMasternodePaymentWinner : public CSignedMessage
payee = payeeIn;
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vinMasternode);
READWRITE(nBlockHeight);
READWRITE(payee);
READWRITE(vchSig);
READWRITE(nMessVersion);
}
SERIALIZE_METHODS(CMasternodePaymentWinner, obj) { READWRITE(obj.vinMasternode, obj.nBlockHeight, obj.payee, obj.vchSig, obj.nMessVersion); }

std::string ToString()
{
Expand Down
33 changes: 6 additions & 27 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,7 @@ class CMasternodePing : public CSignedMessage
CMasternodePing();
CMasternodePing(const CTxIn& newVin, const uint256& nBlockHash, uint64_t _sigTime);

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vin);
READWRITE(blockHash);
READWRITE(sigTime);
READWRITE(vchSig);
READWRITE(nMessVersion);
}
SERIALIZE_METHODS(CMasternodePing, obj) { READWRITE(obj.vin, obj.blockHash, obj.sigTime, obj.vchSig, obj.nMessVersion); }

uint256 GetHash() const;

Expand Down Expand Up @@ -153,23 +143,12 @@ class CMasternode : public CSignedMessage

arith_uint256 CalculateScore(const uint256& hash) const;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CMasternode, obj)
{
LOCK(cs);

READWRITE(vin);
READWRITE(addr);
READWRITE(pubKeyCollateralAddress);
READWRITE(pubKeyMasternode);
READWRITE(vchSig);
READWRITE(sigTime);
READWRITE(protocolVersion);
READWRITE(lastPing);
READWRITE(nScanningErrorCount);
READWRITE(nLastScanningErrorBlockHeight);
LOCK(obj.cs);
READWRITE(obj.vin, obj.addr, obj.pubKeyCollateralAddress);
READWRITE(obj.pubKeyMasternode, obj.vchSig, obj.sigTime, obj.protocolVersion);
READWRITE(obj.lastPing, obj.nScanningErrorCount, obj.nLastScanningErrorBlockHeight);
}

template <typename Stream>
Expand Down
23 changes: 10 additions & 13 deletions src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,17 @@ class CMasternodeMan
// TODO: Remove this from serialization
int64_t nDsqCount;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CMasternodeMan, obj)
{
LOCK(cs);
READWRITE(mapMasternodes);
READWRITE(mAskedUsForMasternodeList);
READWRITE(mWeAskedForMasternodeList);
READWRITE(mWeAskedForMasternodeListEntry);
READWRITE(nDsqCount);

READWRITE(mapSeenMasternodeBroadcast);
READWRITE(mapSeenMasternodePing);
LOCK(obj.cs);
READWRITE(obj.mapMasternodes);
READWRITE(obj.mAskedUsForMasternodeList);
READWRITE(obj.mWeAskedForMasternodeList);
READWRITE(obj.mWeAskedForMasternodeListEntry);
READWRITE(obj.nDsqCount);

READWRITE(obj.mapSeenMasternodeBroadcast);
READWRITE(obj.mapSeenMasternodePing);
}

CMasternodeMan();
Expand Down
24 changes: 10 additions & 14 deletions src/sapling/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,19 @@ class SaplingNotePlaintext : public BaseNotePlaintext {

boost::optional<SaplingNote> note(const SaplingIncomingViewingKey& ivk) const;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
SERIALIZE_METHODS(SaplingNotePlaintext, obj)
{
unsigned char leadingByte = 0x01;
READWRITE(leadingByte);

if (leadingByte != 0x01) {
throw std::ios_base::failure("lead byte of SaplingNotePlaintext is not recognized");
}

READWRITE(d); // 11 bytes
READWRITE(value_); // 8 bytes
READWRITE(rcm); // 32 bytes
READWRITE(memo_); // 512 bytes
READWRITE(obj.d); // 11 bytes
READWRITE(obj.value_); // 8 bytes
READWRITE(obj.rcm); // 32 bytes
READWRITE(obj.memo_); // 512 bytes
}

boost::optional<SaplingNotePlaintextEncryptionResult> encrypt(const uint256& pk_d) const;
Expand All @@ -121,12 +119,10 @@ class SaplingOutgoingPlaintext
esk(_esk)
{}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(pk_d); // 8 bytes
READWRITE(esk); // 8 bytes
SERIALIZE_METHODS(SaplingOutgoingPlaintext, obj)
{
READWRITE(obj.pk_d); // 8 bytes
READWRITE(obj.esk); // 8 bytes
}

static boost::optional<SaplingOutgoingPlaintext> decrypt(
Expand Down
24 changes: 2 additions & 22 deletions src/sapling/sapling_transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ class SpendDescription

SpendDescription() {}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(cv);
READWRITE(anchor);
READWRITE(nullifier);
READWRITE(rk);
READWRITE(zkproof);
READWRITE(spendAuthSig);
}
SERIALIZE_METHODS(SpendDescription, obj) { READWRITE(obj.cv, obj.anchor, obj.nullifier, obj.rk, obj.zkproof, obj.spendAuthSig); }

friend bool operator==(const SpendDescription& a, const SpendDescription& b)
{
Expand Down Expand Up @@ -97,17 +87,7 @@ class OutputDescription

OutputDescription() {}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(cv);
READWRITE(cmu);
READWRITE(ephemeralKey);
READWRITE(encCiphertext);
READWRITE(outCiphertext);
READWRITE(zkproof);
}
SERIALIZE_METHODS(OutputDescription, obj) { READWRITE(obj.cv, obj.cmu, obj.ephemeralKey, obj.encCiphertext, obj.outCiphertext, obj.zkproof); }

friend bool operator==(const OutputDescription& a, const OutputDescription& b)
{
Expand Down
19 changes: 8 additions & 11 deletions src/sapling/saplingscriptpubkeyman.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,19 @@ class SaplingNoteData
*/
Optional<uint256> nullifier;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(SaplingNoteData, obj)
{
int nVersion = s.GetVersion();
if (!(s.GetType() & SER_GETHASH)) {
READWRITE(nVersion);
}
READWRITE(ivk);
READWRITE(nullifier);
READWRITE(witnesses);
READWRITE(witnessHeight);
READWRITE(amount);
READWRITE(address);
READWRITE(memo);
READWRITE(obj.ivk);
READWRITE(obj.nullifier);
READWRITE(obj.witnesses);
READWRITE(obj.witnessHeight);
READWRITE(obj.amount);
READWRITE(obj.address);
READWRITE(obj.memo);
}

friend bool operator==(const SaplingNoteData& a, const SaplingNoteData& b) {
Expand Down
Loading

0 comments on commit cf06950

Please sign in to comment.