Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight budgets/rpc refactor #614

Merged
merged 1 commit into from
Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 54 additions & 35 deletions src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1265,18 +1265,6 @@ CBudgetProposal::CBudgetProposal()
fValid = true;
}

CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn)
{
strProposalName = strProposalNameIn;
strURL = strURLIn;
nBlockStart = nBlockStartIn;
nBlockEnd = nBlockEndIn;
address = addressIn;
nAmount = nAmountIn;
nFeeTXHash = nFeeTXHashIn;
fValid = true;
}

CBudgetProposal::CBudgetProposal(const CBudgetProposal& other)
{
strProposalName = other.strProposalName;
Expand All @@ -1291,6 +1279,23 @@ CBudgetProposal::CBudgetProposal(const CBudgetProposal& other)
fValid = true;
}

CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn)
{
strProposalName = strProposalNameIn;
strURL = strURLIn;

nBlockStart = nBlockStartIn;

int nPaymentsStart = nBlockStart - nBlockStart % GetBudgetPaymentCycleBlocks();
//calculate the end of the cycle for this vote, add half a cycle (vote will be deleted after that block)
nBlockEnd = nPaymentsStart + GetBudgetPaymentCycleBlocks() * nPaymentCount + GetBudgetPaymentCycleBlocks()/2;

address = addressIn;
nAmount = nAmountIn;

nFeeTXHash = nFeeTXHashIn;
}

bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral)
{
if(GetNays() - GetYeas() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){
Expand All @@ -1303,18 +1308,52 @@ bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral)
return false;
}

CBlockIndex* pindexPrev = chainActive.Tip();
if(pindexPrev == NULL) {strError = "Tip is NULL"; return true;}

if(nBlockStart % GetBudgetPaymentCycleBlocks() != 0){
int nNext = pindexPrev->nHeight - pindexPrev->nHeight % GetBudgetPaymentCycleBlocks() + GetBudgetPaymentCycleBlocks();
strError = strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nNext);
return false;
}

if(nBlockEnd % GetBudgetPaymentCycleBlocks() != GetBudgetPaymentCycleBlocks()/2){
strError = "Invalid block end";
return false;
}

if(nBlockEnd < nBlockStart) {
strError = "Invalid nBlockEnd";
strError = "Invalid block end - must be greater then block start.";
return false;
}

if(nAmount < 1*COIN) {
strError = "Invalid nAmount";
strError = "Invalid proposal amount";
return false;
}

if(strProposalName.size() > 20) {
strError = "Invalid proposal name, limit of 20 characters.";
return false;
}

if(strProposalName != SanitizeString(strProposalName)) {
strError = "Invalid proposal name, unsafe characters found.";
return false;
}

if(strURL.size() > 64) {
strError = "Invalid proposal url, limit of 64 characters.";
return false;
}

if(strURL != SanitizeString(strURL)) {
strError = "Invalid proposal url, unsafe characters found.";
return false;
}

if(address == CScript()) {
strError = "Invalid Payment Address";
strError = "Invalid proposal Payment Address";
return false;
}

Expand Down Expand Up @@ -1349,9 +1388,6 @@ bool CBudgetProposal::IsValid(std::string& strError, bool fCheckCollateral)
return false;
}

CBlockIndex* pindexPrev = chainActive.Tip();
if(pindexPrev == NULL) {strError = "Tip is NULL"; return true;}

if(GetBlockEnd() < pindexPrev->nHeight - GetBudgetPaymentCycleBlocks()/2 ) return false;


Expand Down Expand Up @@ -1493,23 +1529,6 @@ int CBudgetProposal::GetRemainingPaymentCount()
return (nPayments <= nTotal ? nPayments : nTotal);
}

CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn)
{
strProposalName = strProposalNameIn;
strURL = strURLIn;

nBlockStart = nBlockStartIn;

int nCycleStart = nBlockStart - nBlockStart % GetBudgetPaymentCycleBlocks();
//calculate the end of the cycle for this vote, add half a cycle (vote will be deleted after that block)
nBlockEnd = nCycleStart + GetBudgetPaymentCycleBlocks() * nPaymentCount + GetBudgetPaymentCycleBlocks()/2;

address = addressIn;
nAmount = nAmountIn;

nFeeTXHash = nFeeTXHashIn;
}

void CBudgetProposalBroadcast::Relay()
{
CInv inv(MSG_BUDGET_PROPOSAL, GetHash());
Expand Down
4 changes: 2 additions & 2 deletions src/masternode-budget.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ class CBudgetProposal

CBudgetProposal();
CBudgetProposal(const CBudgetProposal& other);
CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nBlockStartIn, int nBlockEndIn, CScript addressIn, CAmount nAmountIn, uint256 nFeeTXHashIn);
CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn);

void Calculate();
bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError);
Expand Down Expand Up @@ -492,7 +492,7 @@ class CBudgetProposalBroadcast : public CBudgetProposal
CBudgetProposalBroadcast() : CBudgetProposal(){}
CBudgetProposalBroadcast(const CBudgetProposal& other) : CBudgetProposal(other){}
CBudgetProposalBroadcast(const CBudgetProposalBroadcast& other) : CBudgetProposal(other){}
CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn);
CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) {}

void swap(CBudgetProposalBroadcast& first, CBudgetProposalBroadcast& second) // nothrow
{
Expand Down
Loading