Skip to content

Commit

Permalink
Convert to new serialization (step 2). Focused on object's serializat…
Browse files Browse the repository at this point in the history
…ions that doesn't require an special treatment.
  • Loading branch information
furszy committed Jul 3, 2021
1 parent 0f15784 commit eccd473
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 210 deletions.
22 changes: 10 additions & 12 deletions src/budget/budgetproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,17 @@ class CBudgetProposal
}

// Serialization for local DB
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CBudgetProposal, obj)
{
READWRITE(LIMITED_STRING(strProposalName, 20));
READWRITE(LIMITED_STRING(strURL, 64));
READWRITE(nBlockStart);
READWRITE(nBlockEnd);
READWRITE(nAmount);
READWRITE(address);
READWRITE(nFeeTXHash);
READWRITE(nTime);
READWRITE(mapVotes);
READWRITE(LIMITED_STRING(obj.strProposalName, 20));
READWRITE(LIMITED_STRING(obj.strURL, 64));
READWRITE(obj.nBlockStart);
READWRITE(obj.nBlockEnd);
READWRITE(obj.nAmount);
READWRITE(obj.address);
READWRITE(obj.nFeeTXHash);
READWRITE(obj.nTime);
READWRITE(obj.mapVotes);
}

// Serialization for network messages.
Expand Down
30 changes: 10 additions & 20 deletions src/budget/finalizedbudget.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,16 @@ class CFinalizedBudget
}

// Serialization for local DB
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CFinalizedBudget, obj)
{
READWRITE(LIMITED_STRING(strBudgetName, 20));
READWRITE(nFeeTXHash);
READWRITE(nTime);
READWRITE(nBlockStart);
READWRITE(vecBudgetPayments);
READWRITE(fAutoChecked);
READWRITE(mapVotes);
READWRITE(strProposals);
READWRITE(LIMITED_STRING(obj.strBudgetName, 20));
READWRITE(obj.nFeeTXHash);
READWRITE(obj.nTime);
READWRITE(obj.nBlockStart);
READWRITE(obj.vecBudgetPayments);
READWRITE(obj.fAutoChecked);
READWRITE(obj.mapVotes);
READWRITE(obj.strProposals);
}

// Serialization for network messages.
Expand Down Expand Up @@ -155,16 +153,8 @@ class CTxBudgetPayment
nAmount(_nAmount)
{}

ADD_SERIALIZE_METHODS;

//for saving to the serialized db
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(payee);
READWRITE(nAmount);
READWRITE(nProposalHash);
}
SERIALIZE_METHODS(CTxBudgetPayment, obj) { READWRITE(obj.payee, obj.nAmount, obj.nProposalHash); }

// compare payments by proposal hash
inline bool operator>(const CTxBudgetPayment& other) const
Expand Down
12 changes: 1 addition & 11 deletions src/crypter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,7 @@ class CMasterKey
//! such as the various parameters to scrypt
std::vector<unsigned char> vchOtherDerivationParameters;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(vchCryptedKey);
READWRITE(vchSalt);
READWRITE(nDerivationMethod);
READWRITE(nDeriveIterations);
READWRITE(vchOtherDerivationParameters);
}
SERIALIZE_METHODS(CMasterKey, obj) { READWRITE(obj.vchCryptedKey, obj.vchSalt, obj.nDerivationMethod, obj.nDeriveIterations, obj.vchOtherDerivationParameters); }

CMasterKey()
{
Expand Down
38 changes: 16 additions & 22 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,24 @@ class CDeterministicMNState
scriptOperatorPayout = pl.scriptOperatorPayout;
}
template <typename Stream>
CDeterministicMNState(deserialize_type, Stream& s)
{
s >> *this;
}
CDeterministicMNState(deserialize_type, Stream& s) { s >> *this; }

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CDeterministicMNState, obj)
{
READWRITE(nRegisteredHeight);
READWRITE(nLastPaidHeight);
READWRITE(nPoSePenalty);
READWRITE(nPoSeRevivedHeight);
READWRITE(nPoSeBanHeight);
READWRITE(nRevocationReason);
READWRITE(confirmedHash);
READWRITE(confirmedHashWithProRegTxHash);
READWRITE(keyIDOwner);
READWRITE(keyIDOperator);
READWRITE(keyIDVoting);
READWRITE(addr);
READWRITE(scriptPayout);
READWRITE(scriptOperatorPayout);
READWRITE(obj.nRegisteredHeight);
READWRITE(obj.nLastPaidHeight);
READWRITE(obj.nPoSePenalty);
READWRITE(obj.nPoSeRevivedHeight);
READWRITE(obj.nPoSeBanHeight);
READWRITE(obj.nRevocationReason);
READWRITE(obj.confirmedHash);
READWRITE(obj.confirmedHashWithProRegTxHash);
READWRITE(obj.keyIDOwner);
READWRITE(obj.keyIDOperator);
READWRITE(obj.keyIDVoting);
READWRITE(obj.addr);
READWRITE(obj.scriptPayout);
READWRITE(obj.scriptOperatorPayout);
}

void UpdateConfirmedHash(const uint256& _proTxHash, const uint256& _confirmedHash)
Expand Down
8 changes: 1 addition & 7 deletions src/libzerocoin/Coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ class PublicCoin
*/
bool validate() const;

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(value);
READWRITE(denomination);
}
SERIALIZE_METHODS(PublicCoin, obj) { READWRITE(obj.value, obj.denomination); }

private:
const ZerocoinParams* params;
Expand Down
8 changes: 1 addition & 7 deletions src/libzerocoin/CoinRandomnessSchnorrSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ class CoinRandomnessSchnorrSignature {
*/
bool Verify(const ZerocoinParams* zcparams, const CBigNum& S, const CBigNum& C, const uint256 msghash) const;

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(alpha);
READWRITE(beta);
}
SERIALIZE_METHODS(CoinRandomnessSchnorrSignature, obj) { READWRITE(obj.alpha, obj.beta); }

private:
// signature components
Expand Down
29 changes: 7 additions & 22 deletions src/libzerocoin/CoinSpend.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ namespace libzerocoin
class AccumulatorProofOfKnowledge {
public:
AccumulatorProofOfKnowledge() {};
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(C_e); READWRITE(C_u); READWRITE(C_r); READWRITE(st_1); READWRITE(st_2); READWRITE(st_3);
READWRITE(t_1); READWRITE(t_2); READWRITE(t_3); READWRITE(t_4); READWRITE(s_alpha); READWRITE(s_beta);
READWRITE(s_zeta); READWRITE(s_sigma); READWRITE(s_eta); READWRITE(s_epsilon);
READWRITE(s_delta); READWRITE(s_xi); READWRITE(s_phi); READWRITE(s_gamma); READWRITE(s_psi);
SERIALIZE_METHODS(AccumulatorProofOfKnowledge, obj) {
READWRITE(obj.C_e, obj.C_u, obj.C_r, obj.st_1, obj.st_2, obj.st_3);
READWRITE(obj.t_1, obj.t_2, obj.t_3, obj.t_4, obj.s_alpha, obj.s_beta);
READWRITE(obj.s_zeta, obj.s_sigma, obj.s_eta, obj.s_epsilon);
READWRITE(obj.s_delta, obj.s_xi, obj.s_phi, obj.s_gamma, obj.s_psi);
}
private:
CBigNum C_e, C_u, C_r;
Expand All @@ -55,14 +52,7 @@ class AccumulatorProofOfKnowledge {
class SerialNumberSignatureOfKnowledge {
public:
SerialNumberSignatureOfKnowledge(){};
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(s_notprime);
READWRITE(sprime);
READWRITE(hash);
}
SERIALIZE_METHODS(SerialNumberSignatureOfKnowledge, obj) { READWRITE(obj.s_notprime, obj.sprime, obj.hash); }
private:
uint256 hash;
std::vector<CBigNum> s_notprime;
Expand All @@ -74,12 +64,7 @@ class SerialNumberSignatureOfKnowledge {
class CommitmentProofOfKnowledge {
public:
CommitmentProofOfKnowledge() {};
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(S1); READWRITE(S2); READWRITE(S3); READWRITE(challenge);
}
SERIALIZE_METHODS(CommitmentProofOfKnowledge, obj) { READWRITE(obj.S1,obj.S2, obj.S3, obj.challenge); }
private:
CBigNum S1, S2, S3, challenge;
};
Expand Down
7 changes: 1 addition & 6 deletions src/libzerocoin/Commitment.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ class Commitment {
CBigNum randomness;
const CBigNum contents;

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(commitmentValue); READWRITE(randomness); READWRITE(contents);
}
SERIALIZE_METHODS(Commitment, obj) { READWRITE(obj.commitmentValue, obj.randomness, obj.contents); }
};
} /* namespace libzerocoin */
#endif /* COMMITMENT_H_ */
49 changes: 14 additions & 35 deletions src/libzerocoin/Params.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,7 @@ class IntegerGroupParams {
*/
CBigNum groupOrder;

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(initialized);
READWRITE(g);
READWRITE(h);
READWRITE(modulus);
READWRITE(groupOrder);
}
SERIALIZE_METHODS(IntegerGroupParams, obj) { READWRITE(obj.initialized, obj.g , obj.h, obj.modulus, obj.groupOrder); }
};

class AccumulatorAndProofParams {
Expand Down Expand Up @@ -134,23 +127,15 @@ class AccumulatorAndProofParams {
*/
uint32_t k_prime;

/**
* Security parameter.
* The statistical zero-knowledgeness of the accumulator proof.
*/
uint32_t k_dprime;
ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(initialized);
READWRITE(accumulatorModulus);
READWRITE(accumulatorBase);
READWRITE(accumulatorPoKCommitmentGroup);
READWRITE(accumulatorQRNCommitmentGroup);
READWRITE(minCoinValue);
READWRITE(maxCoinValue);
READWRITE(k_prime);
READWRITE(k_dprime);
}
/**
* Security parameter.
* The statistical zero-knowledgeness of the accumulator proof.
*/
uint32_t k_dprime;
SERIALIZE_METHODS(AccumulatorAndProofParams, obj) {
READWRITE(obj.initialized, obj.accumulatorModulus, obj.accumulatorBase, obj.accumulatorPoKCommitmentGroup);
READWRITE(obj.accumulatorQRNCommitmentGroup, obj.minCoinValue, obj.maxCoinValue, obj.k_prime, obj.k_dprime);
}
};

class ZerocoinParams {
Expand Down Expand Up @@ -203,16 +188,10 @@ class ZerocoinParams {
* proofs.
*/
uint32_t zkp_hash_len;

ADD_SERIALIZE_METHODS;
template <typename Stream, typename Operation> inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(initialized);
READWRITE(accumulatorParams);
READWRITE(coinCommitmentGroup);
READWRITE(serialNumberSoKCommitmentGroup);
READWRITE(zkp_iterations);
READWRITE(zkp_hash_len);
}

SERIALIZE_METHODS(ZerocoinParams, obj) {
READWRITE(obj.initialized, obj.accumulatorParams, obj.coinCommitmentGroup, obj.serialNumberSoKCommitmentGroup, obj.zkp_iterations, obj.zkp_hash_len);
}
};

} /* namespace libzerocoin */
Expand Down
27 changes: 3 additions & 24 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,7 @@ class CMasternodePayee
nVotes = nVotesIn;
}

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(scriptPubKey);
READWRITE(nVotes);
}
SERIALIZE_METHODS(CMasternodePayee, obj) { READWRITE(obj.scriptPubKey, obj.nVotes); }
};

// Keep track of votes for payees from masternodes
Expand Down Expand Up @@ -152,14 +145,7 @@ class CMasternodeBlockPayees
bool IsTransactionValid(const CTransaction& txNew);
std::string GetRequiredPaymentsString();

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(nBlockHeight);
READWRITE(vecPayments);
}
SERIALIZE_METHODS(CMasternodeBlockPayees, obj) { READWRITE(obj.nBlockHeight, obj.vecPayments); }
};

// for storing the winning payments
Expand Down Expand Up @@ -290,14 +276,7 @@ class CMasternodePayments
void FillBlockPayee(CMutableTransaction& txCoinbase, CMutableTransaction& txCoinstake, const CBlockIndex* pindexPrev, bool fProofOfStake) const;
std::string ToString() const;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(mapMasternodePayeeVotes);
READWRITE(mapMasternodeBlocks);
}
SERIALIZE_METHODS(CMasternodePayments, obj) { READWRITE(obj.mapMasternodePayeeVotes, obj.mapMasternodeBlocks); }
};


Expand Down
23 changes: 10 additions & 13 deletions src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,17 @@ class CMasternodeBroadcast : public CMasternode
bool Sign(const std::string strSignKey);
bool CheckSignature() const;

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
SERIALIZE_METHODS(CMasternodeBroadcast, obj)
{
READWRITE(vin);
READWRITE(addr);
READWRITE(pubKeyCollateralAddress);
READWRITE(pubKeyMasternode);
READWRITE(vchSig);
READWRITE(sigTime);
READWRITE(protocolVersion);
READWRITE(lastPing);
READWRITE(nMessVersion);
READWRITE(obj.vin);
READWRITE(obj.addr);
READWRITE(obj.pubKeyCollateralAddress);
READWRITE(obj.pubKeyMasternode);
READWRITE(obj.vchSig);
READWRITE(obj.sigTime);
READWRITE(obj.protocolVersion);
READWRITE(obj.lastPing);
READWRITE(obj.nMessVersion);
}

/// Create Masternode broadcast, needs to be relayed manually after that
Expand Down
Loading

0 comments on commit eccd473

Please sign in to comment.