Skip to content

Commit

Permalink
[Refactor] Refactor CBudgetProposal::IsEstablished()
Browse files Browse the repository at this point in the history
-Move IsEstablished function to cpp file
-Use GetAdjustedTime() instead of GetTime() to avoid lack of consensus
-Remove magic numbers and declare them in chainparams
  • Loading branch information
Warrows committed Apr 23, 2019
1 parent cfa3092 commit 3ec04f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class CMainParams : public CChainParams
nZerocoinRequiredStakeDepth = 200; //The required confirmations for a zpiv to be stakable

nBudget_Fee_Confirmations = 6; // Number of confirmations for the finalization fee
nProposalEstablishmentTime = 60 * 60 * 24; // Proposals must be at least a day old to make it into a budget
}

const Checkpoints::CCheckpointData& Checkpoints() const
Expand Down Expand Up @@ -335,6 +336,8 @@ class CTestNetParams : public CMainParams
nStartMasternodePayments = 1420837558; //Fri, 09 Jan 2015 21:05:58 GMT
nBudget_Fee_Confirmations = 3; // Number of confirmations for the finalization fee. We have to make this very short
// here because we only have a 8 block finalization window on testnet

nProposalEstablishmentTime = 60 * 5; // Proposals must be at least 5 mns old to make it into a test budget
}
const Checkpoints::CCheckpointData& Checkpoints() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class CChainParams
int PoolMaxTransactions() const { return nPoolMaxTransactions; }
/** Return the number of blocks in a budget cycle */
int GetBudgetCycleBlocks() const { return nBudgetCycleBlocks; }
int64_t GetProposalEstablishmentTime() const { return nProposalEstablishmentTime; }

/** Spork key and Masternode Handling **/
std::string SporkKey() const { return strSporkKey; }
Expand Down Expand Up @@ -190,6 +191,7 @@ class CChainParams
int nZerocoinStartHeight;
int nZerocoinStartTime;
int nZerocoinRequiredStakeDepth;
int64_t nProposalEstablishmentTime;

int nBlockEnforceSerialRange;
int nBlockRecalculateAccumulators;
Expand Down
5 changes: 5 additions & 0 deletions src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,11 @@ bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral)
return true;
}

bool CBudgetProposal::IsEstablished()
{
return nTime < GetAdjustedTime() - Params().GetProposalEstablishmentTime();
}

bool CBudgetProposal::AddOrUpdateVote(CBudgetVote& vote, std::string& strError)
{
std::string strAction = "New vote inserted:";
Expand Down
9 changes: 1 addition & 8 deletions src/masternode-budget.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,7 @@ class CBudgetProposal

bool IsValid(std::string& strError, bool fCheckCollateral = true);

bool IsEstablished()
{
// Proposals must be at least a day old to make it into a budget
if (Params().NetworkID() == CBaseChainParams::MAIN) return (nTime < GetTime() - (60 * 60 * 24));

// For testing purposes - 5 minutes
return (nTime < GetTime() - (60 * 5));
}
bool IsEstablished();

std::string GetName() { return strProposalName; }
std::string GetURL() { return strURL; }
Expand Down

0 comments on commit 3ec04f7

Please sign in to comment.