diff --git a/doc/masternode-budget.md b/doc/masternode-budget.md index 153416588..432ff35be 100644 --- a/doc/masternode-budget.md +++ b/doc/masternode-budget.md @@ -1,3 +1,6 @@ +NOTE : 12.1 -- REWRITE + + Masternode Budget API ======================= diff --git a/src/drafted/governance-classes.cpp b/src/drafted/governance-classes.cpp index ff30235f0..e69de29bb 100644 --- a/src/drafted/governance-classes.cpp +++ b/src/drafted/governance-classes.cpp @@ -1 +0,0 @@ -} \ No newline at end of file diff --git a/src/drafted/governance-finalization.cpp b/src/drafted/governance-finalization.cpp index 91b7fe07e..69a56dab2 100644 --- a/src/drafted/governance-finalization.cpp +++ b/src/drafted/governance-finalization.cpp @@ -1,335 +1,257 @@ -#include "governance-finalization.h" +// #include "governance-finalization.h" -CFinalizedBudget::CFinalizedBudget() -{ - strBudgetName = ""; - nBlockStart = 0; - vecBudgetPayments.clear(); - mapVotes.clear(); - nFeeTXHash = 0; - nTime = 0; - fValid = true; - fAutoChecked = false; -} +// CFinalizedBudget::CFinalizedBudget() +// { +// strBudgetName = ""; +// nBlockStart = 0; +// vecBudgetPayments.clear(); +// mapVotes.clear(); +// nFeeTXHash = 0; +// nTime = 0; +// fValid = true; +// fAutoChecked = false; +// } -CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other) -{ - strBudgetName = other.strBudgetName; - nBlockStart = other.nBlockStart; - vecBudgetPayments = other.vecBudgetPayments; - mapVotes = other.mapVotes; - nFeeTXHash = other.nFeeTXHash; - nTime = other.nTime; - fValid = true; - fAutoChecked = false; -} +// CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other) +// { +// strBudgetName = other.strBudgetName; +// nBlockStart = other.nBlockStart; +// vecBudgetPayments = other.vecBudgetPayments; +// mapVotes = other.mapVotes; +// nFeeTXHash = other.nFeeTXHash; +// nTime = other.nTime; +// fValid = true; +// fAutoChecked = false; +// } -bool CFinalizedBudget::AddOrUpdateVote(CFinalizedBudgetVote& vote, std::string& strError) -{ - LOCK(cs); +// bool CFinalizedBudget::AddOrUpdateVote(CFinalizedBudgetVote& vote, std::string& strError) +// { +// LOCK(cs); - uint256 hash = vote.vin.prevout.GetHash(); - if(mapVotes.count(hash)){ - if(mapVotes[hash].nTime > vote.nTime){ - strError = strprintf("new vote older than existing vote - %s\n", vote.GetHash().ToString()); - LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); - return false; - } - if(vote.nTime - mapVotes[hash].nTime < BUDGET_VOTE_UPDATE_MIN){ - strError = strprintf("time between votes is too soon - %s - %lli\n", vote.GetHash().ToString(), vote.nTime - mapVotes[hash].nTime); - LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); - return false; - } - } +// uint256 hash = vote.vin.prevout.GetHash(); +// if(mapVotes.count(hash)){ +// if(mapVotes[hash].nTime > vote.nTime){ +// strError = strprintf("new vote older than existing vote - %s\n", vote.GetHash().ToString()); +// LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); +// return false; +// } +// if(vote.nTime - mapVotes[hash].nTime < BUDGET_VOTE_UPDATE_MIN){ +// strError = strprintf("time between votes is too soon - %s - %lli\n", vote.GetHash().ToString(), vote.nTime - mapVotes[hash].nTime); +// LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); +// return false; +// } +// } - if(vote.nTime > GetTime() + (60*60)){ - strError = strprintf("new vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", vote.GetHash().ToString(), vote.nTime, GetTime() + (60*60)); - LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); - return false; - } +// if(vote.nTime > GetTime() + (60*60)){ +// strError = strprintf("new vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", vote.GetHash().ToString(), vote.nTime, GetTime() + (60*60)); +// LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); +// return false; +// } - mapVotes[hash] = vote; - return true; -} +// mapVotes[hash] = vote; +// return true; +// } -//evaluate if we should vote for this. Masternode only -void CFinalizedBudget::AutoCheck() -{ - LOCK(cs); +// // If masternode voted for a proposal, but is now invalid -- remove the vote +// void CFinalizedBudget::CleanAndRemove(bool fSignatureCheck) +// { +// std::map::iterator it = mapVotes.begin(); - CBlockIndex* pindexPrev = chainActive.Tip(); - if(!pindexPrev) return; - - LogPrintf("CFinalizedBudget::AutoCheck - %lli - %d\n", pindexPrev->nHeight, fAutoChecked); - - if(!fMasterNode || fAutoChecked) return; - - //do this 1 in 4 blocks -- spread out the voting activity on mainnet - // -- this function is only called every sixth block, so this is really 1 in 24 blocks - if(Params().NetworkID() == CBaseChainParams::MAIN && rand() % 4 != 0) { - LogPrintf("CFinalizedBudget::AutoCheck - waiting\n"); - return; - } - - fAutoChecked = true; //we only need to check this once +// while(it != mapVotes.end()) { +// (*it).second.fValid = (*it).second.SignatureValid(fSignatureCheck); +// ++it; +// } +// } - if(strBudgetMode == "auto") //only vote for exact matches - { - std::vector vBudgetProposals = budget.GetBudget(); +// CAmount CFinalizedBudget::GetTotalPayout() +// { +// CAmount ret = 0; +// for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ +// ret += vecBudgetPayments[i].nAmount; +// } - for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ - LogPrintf("CFinalizedBudget::AutoCheck - nProp %d %s\n", i, vecBudgetPayments[i].nProposalHash.ToString()); - LogPrintf("CFinalizedBudget::AutoCheck - Payee %d %s\n", i, vecBudgetPayments[i].payee.ToString()); - LogPrintf("CFinalizedBudget::AutoCheck - nAmount %d %lli\n", i, vecBudgetPayments[i].nAmount); - } +// return ret; +// } - for(unsigned int i = 0; i < vBudgetProposals.size(); i++){ - LogPrintf("CFinalizedBudget::AutoCheck - nProp %d %s\n", i, vBudgetProposals[i]->GetHash().ToString()); - LogPrintf("CFinalizedBudget::AutoCheck - Payee %d %s\n", i, vBudgetProposals[i]->GetPayee().ToString()); - LogPrintf("CFinalizedBudget::AutoCheck - nAmount %d %lli\n", i, vBudgetProposals[i]->GetAmount()); - } +// std::string CFinalizedBudget::GetProposals() +// { +// LOCK(cs); +// std::string ret = ""; - if(vBudgetProposals.size() == 0) { - LogPrintf("CFinalizedBudget::AutoCheck - Can't get Budget, aborting\n"); - return; - } +// BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){ +// CBudgetProposal* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash); - if(vBudgetProposals.size() != vecBudgetPayments.size()) { - LogPrintf("CFinalizedBudget::AutoCheck - Budget length doesn't match\n"); - return; - } +// std::string token = budgetPayment.nProposalHash.ToString(); +// if(pbudgetProposal) token = pbudgetProposal->GetName(); +// if(ret == "") {ret = token;} +// else {ret += "," + token;} +// } +// return ret; +// } - for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ - if(i > vBudgetProposals.size() - 1) { - LogPrintf("CFinalizedBudget::AutoCheck - Vector size mismatch, aborting\n"); - return; - } +// std::string CFinalizedBudget::GetStatus() +// { +// std::string retBadHashes = ""; +// std::string retBadPayeeOrAmount = ""; - if(vecBudgetPayments[i].nProposalHash != vBudgetProposals[i]->GetHash()){ - LogPrintf("CFinalizedBudget::AutoCheck - item #%d doesn't match %s %s\n", i, vecBudgetPayments[i].nProposalHash.ToString(), vBudgetProposals[i]->GetHash().ToString()); - return; - } +// for(int nBlockHeight = GetBlockStart(); nBlockHeight <= GetBlockEnd(); nBlockHeight++) +// { +// CTxBudgetPayment budgetPayment; +// if(!GetBudgetPaymentByBlock(nBlockHeight, budgetPayment)){ +// LogPrintf("CFinalizedBudget::GetStatus - Couldn't find budget payment for block %lld\n", nBlockHeight); +// continue; +// } - // if(vecBudgetPayments[i].payee != vBudgetProposals[i]->GetPayee()){ -- triggered with false positive - if(vecBudgetPayments[i].payee.ToString() != vBudgetProposals[i]->GetPayee().ToString()){ - LogPrintf("CFinalizedBudget::AutoCheck - item #%d payee doesn't match %s %s\n", i, vecBudgetPayments[i].payee.ToString(), vBudgetProposals[i]->GetPayee().ToString()); - return; - } +// CBudgetProposal* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash); +// if(!pbudgetProposal){ +// if(retBadHashes == ""){ +// retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString(); +// } else { +// retBadHashes += "," + budgetPayment.nProposalHash.ToString(); +// } +// } else { +// if(pbudgetProposal->GetPayee() != budgetPayment.payee || pbudgetProposal->GetAmount() != budgetPayment.nAmount) +// { +// if(retBadPayeeOrAmount == ""){ +// retBadPayeeOrAmount = "Budget payee/nAmount doesn't match our proposal! " + budgetPayment.nProposalHash.ToString(); +// } else { +// retBadPayeeOrAmount += "," + budgetPayment.nProposalHash.ToString(); +// } +// } +// } +// } - if(vecBudgetPayments[i].nAmount != vBudgetProposals[i]->GetAmount()){ - LogPrintf("CFinalizedBudget::AutoCheck - item #%d payee doesn't match %lli %lli\n", i, vecBudgetPayments[i].nAmount, vBudgetProposals[i]->GetAmount()); - return; - } - } +// if(retBadHashes == "" && retBadPayeeOrAmount == "") return "OK"; - LogPrintf("CFinalizedBudget::AutoCheck - Finalized Budget Matches! Submitting Vote.\n"); - SubmitVote(); +// return retBadHashes + retBadPayeeOrAmount; +// } - } -} -// If masternode voted for a proposal, but is now invalid -- remove the vote -void CFinalizedBudget::CleanAndRemove(bool fSignatureCheck) -{ - std::map::iterator it = mapVotes.begin(); +// bool CFinalizedBudget::IsValid(std::string& strError, bool fCheckCollateral) +// { +// //must be the correct block for payment to happen (once a month) +// if(nBlockStart % GetBudgetPaymentCycleBlocks() != 0) {strError = "Invalid BlockStart"; return false;} +// if(GetBlockEnd() - nBlockStart > 100) {strError = "Invalid BlockEnd"; return false;} +// if((int)vecBudgetPayments.size() > 100) {strError = "Invalid budget payments count (too many)"; return false;} +// if(strBudgetName == "") {strError = "Invalid Budget Name"; return false;} +// if(nBlockStart == 0) {strError = "Invalid BlockStart == 0"; return false;} +// if(nFeeTXHash == 0) {strError = "Invalid FeeTx == 0"; return false;} - while(it != mapVotes.end()) { - (*it).second.fValid = (*it).second.SignatureValid(fSignatureCheck); - ++it; - } -} +// //can only pay out 10% of the possible coins (min value of coins) +// if(GetTotalPayout() > budget.GetTotalBudget(nBlockStart)) {strError = "Invalid Payout (more than max)"; return false;} +// std::string strError2 = ""; +// if(fCheckCollateral){ +// int nConf = 0; +// if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2, nTime, nConf)){ +// {strError = "Invalid Collateral : " + strError2; return false;} +// } +// } -CAmount CFinalizedBudget::GetTotalPayout() -{ - CAmount ret = 0; +// //TODO: if N cycles old, invalid, invalid - for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ - ret += vecBudgetPayments[i].nAmount; - } +// CBlockIndex* pindexPrev = chainActive.Tip(); +// if(pindexPrev == NULL) return true; - return ret; -} +// if(nBlockStart < pindexPrev->nHeight-100) {strError = "Older than current blockHeight"; return false;} -std::string CFinalizedBudget::GetProposals() -{ - LOCK(cs); - std::string ret = ""; +// return true; +// } - BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){ - CBudgetProposal* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash); +// bool CFinalizedBudget::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) +// { +// int nCurrentBudgetPayment = nBlockHeight - GetBlockStart(); +// if(nCurrentBudgetPayment < 0) { +// LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - height: %d start: %d\n", nBlockHeight, GetBlockStart()); +// return false; +// } - std::string token = budgetPayment.nProposalHash.ToString(); +// if(nCurrentBudgetPayment > (int)vecBudgetPayments.size() - 1) { +// LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - current budget payment: %d of %d\n", nCurrentBudgetPayment + 1, (int)vecBudgetPayments.size()); +// return false; +// } - if(pbudgetProposal) token = pbudgetProposal->GetName(); - if(ret == "") {ret = token;} - else {ret += "," + token;} - } - return ret; -} +// bool found = false; +// BOOST_FOREACH(CTxOut out, txNew.vout) +// { +// if(vecBudgetPayments[nCurrentBudgetPayment].payee == out.scriptPubKey && vecBudgetPayments[nCurrentBudgetPayment].nAmount == out.nValue) +// found = true; +// } +// if(!found) { +// CTxDestination address1; +// ExtractDestination(vecBudgetPayments[nCurrentBudgetPayment].payee, address1); +// CBitcoinAddress address2(address1); -std::string CFinalizedBudget::GetStatus() -{ - std::string retBadHashes = ""; - std::string retBadPayeeOrAmount = ""; - - for(int nBlockHeight = GetBlockStart(); nBlockHeight <= GetBlockEnd(); nBlockHeight++) - { - CTxBudgetPayment budgetPayment; - if(!GetBudgetPaymentByBlock(nBlockHeight, budgetPayment)){ - LogPrintf("CFinalizedBudget::GetStatus - Couldn't find budget payment for block %lld\n", nBlockHeight); - continue; - } - - CBudgetProposal* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash); - if(!pbudgetProposal){ - if(retBadHashes == ""){ - retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString(); - } else { - retBadHashes += "," + budgetPayment.nProposalHash.ToString(); - } - } else { - if(pbudgetProposal->GetPayee() != budgetPayment.payee || pbudgetProposal->GetAmount() != budgetPayment.nAmount) - { - if(retBadPayeeOrAmount == ""){ - retBadPayeeOrAmount = "Budget payee/nAmount doesn't match our proposal! " + budgetPayment.nProposalHash.ToString(); - } else { - retBadPayeeOrAmount += "," + budgetPayment.nProposalHash.ToString(); - } - } - } - } - - if(retBadHashes == "" && retBadPayeeOrAmount == "") return "OK"; - - return retBadHashes + retBadPayeeOrAmount; -} - -bool CFinalizedBudget::IsValid(std::string& strError, bool fCheckCollateral) -{ - //must be the correct block for payment to happen (once a month) - if(nBlockStart % GetBudgetPaymentCycleBlocks() != 0) {strError = "Invalid BlockStart"; return false;} - if(GetBlockEnd() - nBlockStart > 100) {strError = "Invalid BlockEnd"; return false;} - if((int)vecBudgetPayments.size() > 100) {strError = "Invalid budget payments count (too many)"; return false;} - if(strBudgetName == "") {strError = "Invalid Budget Name"; return false;} - if(nBlockStart == 0) {strError = "Invalid BlockStart == 0"; return false;} - if(nFeeTXHash == 0) {strError = "Invalid FeeTx == 0"; return false;} - - //can only pay out 10% of the possible coins (min value of coins) - if(GetTotalPayout() > budget.GetTotalBudget(nBlockStart)) {strError = "Invalid Payout (more than max)"; return false;} - - std::string strError2 = ""; - if(fCheckCollateral){ - int nConf = 0; - if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2, nTime, nConf)){ - {strError = "Invalid Collateral : " + strError2; return false;} - } - } - - //TODO: if N cycles old, invalid, invalid - - CBlockIndex* pindexPrev = chainActive.Tip(); - if(pindexPrev == NULL) return true; - - if(nBlockStart < pindexPrev->nHeight-100) {strError = "Older than current blockHeight"; return false;} - - return true; -} - -bool CFinalizedBudget::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) -{ - int nCurrentBudgetPayment = nBlockHeight - GetBlockStart(); - if(nCurrentBudgetPayment < 0) { - LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - height: %d start: %d\n", nBlockHeight, GetBlockStart()); - return false; - } - - if(nCurrentBudgetPayment > (int)vecBudgetPayments.size() - 1) { - LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - current budget payment: %d of %d\n", nCurrentBudgetPayment + 1, (int)vecBudgetPayments.size()); - return false; - } - - bool found = false; - BOOST_FOREACH(CTxOut out, txNew.vout) - { - if(vecBudgetPayments[nCurrentBudgetPayment].payee == out.scriptPubKey && vecBudgetPayments[nCurrentBudgetPayment].nAmount == out.nValue) - found = true; - } - if(!found) { - CTxDestination address1; - ExtractDestination(vecBudgetPayments[nCurrentBudgetPayment].payee, address1); - CBitcoinAddress address2(address1); - - LogPrintf("CFinalizedBudget::IsTransactionValid - Missing required payment - %s: %d\n", address2.ToString(), vecBudgetPayments[nCurrentBudgetPayment].nAmount); - } +// LogPrintf("CFinalizedBudget::IsTransactionValid - Missing required payment - %s: %d\n", address2.ToString(), vecBudgetPayments[nCurrentBudgetPayment].nAmount); +// } - return found; -} +// return found; +// } -void CFinalizedBudget::SubmitVote() -{ - CPubKey pubKeyMasternode; - CKey keyMasternode; - std::string errorMessage; +// void CFinalizedBudget::SubmitVote() +// { +// CPubKey pubKeyMasternode; +// CKey keyMasternode; +// std::string errorMessage; - if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)){ - LogPrintf("CFinalizedBudget::SubmitVote - Error upon calling SetKey\n"); - return; - } +// if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)){ +// LogPrintf("CFinalizedBudget::SubmitVote - Error upon calling SetKey\n"); +// return; +// } - CFinalizedBudgetVote vote(activeMasternode.vin, GetHash()); - if(!vote.Sign(keyMasternode, pubKeyMasternode)){ - LogPrintf("CFinalizedBudget::SubmitVote - Failure to sign."); - return; - } +// CFinalizedBudgetVote vote(activeMasternode.vin, GetHash()); +// if(!vote.Sign(keyMasternode, pubKeyMasternode)){ +// LogPrintf("CFinalizedBudget::SubmitVote - Failure to sign."); +// return; +// } - std::string strError = ""; - if(budget.UpdateFinalizedBudget(vote, NULL, strError)){ - LogPrintf("CFinalizedBudget::SubmitVote - new finalized budget vote - %s\n", vote.GetHash().ToString()); +// std::string strError = ""; +// if(budget.UpdateFinalizedBudget(vote, NULL, strError)){ +// LogPrintf("CFinalizedBudget::SubmitVote - new finalized budget vote - %s\n", vote.GetHash().ToString()); - budget.mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); - vote.Relay(); - } else { - LogPrintf("CFinalizedBudget::SubmitVote : Error submitting vote - %s\n", strError); - } -} +// budget.mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); +// vote.Relay(); +// } else { +// LogPrintf("CFinalizedBudget::SubmitVote : Error submitting vote - %s\n", strError); +// } +// } -CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast() -{ - strBudgetName = ""; - nBlockStart = 0; - vecBudgetPayments.clear(); - mapVotes.clear(); - vchSig.clear(); - nFeeTXHash = 0; -} +// CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast() +// { +// strBudgetName = ""; +// nBlockStart = 0; +// vecBudgetPayments.clear(); +// mapVotes.clear(); +// vchSig.clear(); +// nFeeTXHash = 0; +// } -CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(const CFinalizedBudget& other) -{ - strBudgetName = other.strBudgetName; - nBlockStart = other.nBlockStart; - BOOST_FOREACH(CTxBudgetPayment out, other.vecBudgetPayments) vecBudgetPayments.push_back(out); - mapVotes = other.mapVotes; - nFeeTXHash = other.nFeeTXHash; -} +// CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(const CFinalizedBudget& other) +// { +// strBudgetName = other.strBudgetName; +// nBlockStart = other.nBlockStart; +// BOOST_FOREACH(CTxBudgetPayment out, other.vecBudgetPayments) vecBudgetPayments.push_back(out); +// mapVotes = other.mapVotes; +// nFeeTXHash = other.nFeeTXHash; +// } -CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(std::string strBudgetNameIn, int nBlockStartIn, std::vector vecBudgetPaymentsIn, uint256 nFeeTXHashIn) -{ - strBudgetName = strBudgetNameIn; - nBlockStart = nBlockStartIn; - BOOST_FOREACH(CTxBudgetPayment out, vecBudgetPaymentsIn) vecBudgetPayments.push_back(out); - mapVotes.clear(); - nFeeTXHash = nFeeTXHashIn; -} +// CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(std::string strBudgetNameIn, int nBlockStartIn, std::vector vecBudgetPaymentsIn, uint256 nFeeTXHashIn) +// { +// strBudgetName = strBudgetNameIn; +// nBlockStart = nBlockStartIn; +// BOOST_FOREACH(CTxBudgetPayment out, vecBudgetPaymentsIn) vecBudgetPayments.push_back(out); +// mapVotes.clear(); +// nFeeTXHash = nFeeTXHashIn; +// } -void CFinalizedBudgetBroadcast::Relay() -{ - CInv inv(MSG_BUDGET_FINALIZED, GetHash()); - RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION); -} \ No newline at end of file +// void CFinalizedBudgetBroadcast::Relay() +// { +// CInv inv(MSG_BUDGET_FINALIZED, GetHash()); +// RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION); +// } \ No newline at end of file diff --git a/src/drafted/governance-finalization.h b/src/drafted/governance-finalization.h index 1aa9f2b76..daa126822 100644 --- a/src/drafted/governance-finalization.h +++ b/src/drafted/governance-finalization.h @@ -1,360 +1,360 @@ -// Copyright (c) 2014-2016 The Dash Core developers +// // Copyright (c) 2014-2016 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef GOVERNANCE_FINALIZE_H -#define GOVERNANCE_FINALIZE_H +// // Distributed under the MIT/X11 software license, see the accompanying +// // file COPYING or http://www.opensource.org/licenses/mit-license.php. +// #ifndef GOVERNANCE_FINALIZE_H +// #define GOVERNANCE_FINALIZE_H -//todo: which of these do we need? -//#include "main.h" -//#include "sync.h" -//#include "net.h" -//#include "key.h" -//#include "util.h" -//#include "base58.h" -//#include "masternode.h" -#include "governance.h" -#include "governance-types.h" -//#include -#include +// //todo: which of these do we need? +// //#include "main.h" +// //#include "sync.h" +// //#include "net.h" +// //#include "key.h" +// //#include "util.h" +// //#include "base58.h" +// //#include "masternode.h" +// #include "governance.h" +// #include "governance-types.h" +// //#include +// #include -using namespace std; +// using namespace std; -class CGovernanceManager; +// class CGovernanceManager; -class CTxBudgetPayment; -class CFinalizedBudgetBroadcast; -class CFinalizedBudget; +// class CTxBudgetPayment; +// class CFinalizedBudgetBroadcast; +// class CFinalizedBudget; -extern std::vector vecImmatureGovernanceNodes; +// extern std::vector vecImmatureGovernanceNodes; -//Check the collateral transaction for the budget proposal/finalized budget -bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime, int& nConf); -std::string PrimaryTypeToString(GovernanceObjectType type); +// //Check the collateral transaction for the budget proposal/finalized budget +// bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime, int& nConf); +// std::string PrimaryTypeToString(GovernanceObjectType type); -/* - GOVERNANCE CLASSES -*/ +// /* +// GOVERNANCE CLASSES +// */ -/** Save Budget Manager (budget.dat) - */ -class CBudgetDB -{ -private: - boost::filesystem::path pathDB; - std::string strMagicMessage; -public: - enum ReadResult { - Ok, - FileError, - HashReadError, - IncorrectHash, - IncorrectMagicMessage, - IncorrectMagicNumber, - IncorrectFormat - }; +// /** Save Budget Manager (budget.dat) +// */ +// class CBudgetDB +// { +// private: +// boost::filesystem::path pathDB; +// std::string strMagicMessage; +// public: +// enum ReadResult { +// Ok, +// FileError, +// HashReadError, +// IncorrectHash, +// IncorrectMagicMessage, +// IncorrectMagicNumber, +// IncorrectFormat +// }; - CBudgetDB(); - bool Write(const CGovernanceManager &objToSave); - ReadResult Read(CGovernanceManager& objToLoad, bool fDryRun = false); -}; +// CBudgetDB(); +// bool Write(const CGovernanceManager &objToSave); +// ReadResult Read(CGovernanceManager& objToLoad, bool fDryRun = false); +// }; -// -// Governance Manager : Contains all proposals for the budget -// -class CGovernanceManager -{ // **** Objects and memory **** +// // +// // Governance Manager : Contains all proposals for the budget +// // +// class CGovernanceManager +// { // **** Objects and memory **** -private: +// private: - //hold txes until they mature enough to use - map mapCollateral; - // Keep track of current block index - const CBlockIndex *pCurrentBlockIndex; +// //hold txes until they mature enough to use +// map mapCollateral; +// // Keep track of current block index +// const CBlockIndex *pCurrentBlockIndex; -public: - // critical section to protect the inner data structures - mutable CCriticalSection cs; +// public: +// // critical section to protect the inner data structures +// mutable CCriticalSection cs; - // hold governance objects (proposals, contracts, settings and switches) - std::map mapGovernanceObjects; - // finalized budgets are kept in their own object - // std::map mapFinalizedBudgets; +// // hold governance objects (proposals, contracts, settings and switches) +// std::map mapGovernanceObjects; +// // finalized budgets are kept in their own object +// // std::map mapFinalizedBudgets; - std::map mapSeenGovernanceObjects; - std::map mapSeenGovernanceVotes; - std::map mapOrphanGovernanceVotes; - //std::map mapSeenFinalizedBudgets; +// std::map mapSeenGovernanceObjects; +// std::map mapSeenGovernanceVotes; +// std::map mapOrphanGovernanceVotes; +// //std::map mapSeenFinalizedBudgets; - // VOTES > - std::map > mapVotes; +// // VOTES > +// std::map > mapVotes; - // **** Initialization **** +// // **** Initialization **** - CGovernanceManager() { - mapGovernanceObjects.clear(); - //mapFinalizedBudgets.clear(); - } +// CGovernanceManager() { +// mapGovernanceObjects.clear(); +// //mapFinalizedBudgets.clear(); +// } - void Clear(){ - LOCK(cs); +// void Clear(){ +// LOCK(cs); - LogPrintf("Governance object cleared\n"); - mapGovernanceObjects.clear(); - //mapFinalizedBudgets.clear(); - mapSeenGovernanceObjects.clear(); - mapSeenGovernanceVotes.clear(); - //mapSeenFinalizedBudgets.clear(); - mapOrphanGovernanceVotes.clear(); - } +// LogPrintf("Governance object cleared\n"); +// mapGovernanceObjects.clear(); +// //mapFinalizedBudgets.clear(); +// mapSeenGovernanceObjects.clear(); +// mapSeenGovernanceVotes.clear(); +// //mapSeenFinalizedBudgets.clear(); +// mapOrphanGovernanceVotes.clear(); +// } - void ClearSeen() { - mapSeenGovernanceObjects.clear(); - mapSeenGovernanceVotes.clear(); - //mapSeenFinalizedBudgets.clear(); - } +// void ClearSeen() { +// mapSeenGovernanceObjects.clear(); +// mapSeenGovernanceVotes.clear(); +// //mapSeenFinalizedBudgets.clear(); +// } - void Sync(CNode* node, uint256 nProp, bool fPartial=false); - void ResetSync(); - void MarkSynced(); +// void Sync(CNode* node, uint256 nProp, bool fPartial=false); +// void ResetSync(); +// void MarkSynced(); - // **** Search / Statistics / Information **** +// // **** Search / Statistics / Information **** - int CountProposalInventoryItems() { return mapSeenGovernanceObjects.size() + mapSeenGovernanceVotes.size(); } - //int CountFinalizedInventoryItems() { return mapSeenFinalizedBudgets.size(); } +// int CountProposalInventoryItems() { return mapSeenGovernanceObjects.size() + mapSeenGovernanceVotes.size(); } +// //int CountFinalizedInventoryItems() { return mapSeenFinalizedBudgets.size(); } - CGovernanceNode *FindGovernanceObject(const std::string &strName); - CGovernanceNode *FindGovernanceObject(uint256 nHash); - //CFinalizedBudget *FindFinalizedBudget(uint256 nHash); - GovernanceObjectType GetGovernanceTypeByHash(uint256 nHash); - std::vector GetBudget(); - CAmount GetTotalBudget(int nHeight); - bool HasNextFinalizedBudget(); // Do we have the next finalized budget? - bool IsBudgetPaymentBlock(int nBlockHeight); - bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); +// CGovernanceNode *FindGovernanceObject(const std::string &strName); +// CGovernanceNode *FindGovernanceObject(uint256 nHash); +// //CFinalizedBudget *FindFinalizedBudget(uint256 nHash); +// GovernanceObjectType GetGovernanceTypeByHash(uint256 nHash); +// std::vector GetBudget(); +// CAmount GetTotalBudget(int nHeight); +// bool HasNextFinalizedBudget(); // Do we have the next finalized budget? +// bool IsBudgetPaymentBlock(int nBlockHeight); +// bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); - std::vector FindMatchingGovernanceObjects(GovernanceObjectType type); - //std::vector GetFinalizedBudgets(); - std::string GetRequiredPaymentsString(int nBlockHeight); - std::string ToString() const; +// std::vector FindMatchingGovernanceObjects(GovernanceObjectType type); +// //std::vector GetFinalizedBudgets(); +// std::string GetRequiredPaymentsString(int nBlockHeight); +// std::string ToString() const; - // **** Update **** +// // **** Update **** - //bool AddFinalizedBudget(CFinalizedBudget& finalizedBudget); - bool AddGovernanceObject(CGovernanceNode& budgetProposal); - bool AddOrphanGovernanceVote(CGovernanceVote& vote, CNode* pfrom); - void CheckAndRemove(); - void CheckOrphanVotes(); - void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees); - void NewBlock(); - void SubmitFinalBudget(); - void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); - void UpdatedBlockTip(const CBlockIndex *pindex); - bool UpdateGovernanceObjectVotes(CGovernanceVote& vote, CNode* pfrom, std::string& strError); +// //bool AddFinalizedBudget(CFinalizedBudget& finalizedBudget); +// bool AddGovernanceObject(CGovernanceNode& budgetProposal); +// bool AddOrphanGovernanceVote(CGovernanceVote& vote, CNode* pfrom); +// void CheckAndRemove(); +// void CheckOrphanVotes(); +// void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees); +// void NewBlock(); +// void SubmitFinalBudget(); +// void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); +// void UpdatedBlockTip(const CBlockIndex *pindex); +// bool UpdateGovernanceObjectVotes(CGovernanceVote& vote, CNode* pfrom, std::string& strError); - // **** Serializer **** +// // **** Serializer **** - ADD_SERIALIZE_METHODS; +// ADD_SERIALIZE_METHODS; - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - // READWRITE(mapSeenGovernanceObjects); - // READWRITE(mapSeenGovernanceVotes); - // //READWRITE(mapSeenFinalizedBudgets); - // READWRITE(mapOrphanGovernanceVotes); +// template +// inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { +// // READWRITE(mapSeenGovernanceObjects); +// // READWRITE(mapSeenGovernanceVotes); +// // //READWRITE(mapSeenFinalizedBudgets); +// // READWRITE(mapOrphanGovernanceVotes); - // READWRITE(mapGovernanceObjects); - // //READWRITE(mapFinalizedBudgets); - } +// // READWRITE(mapGovernanceObjects); +// // //READWRITE(mapFinalizedBudgets); +// } -}; +// }; -// -// Finalized Budget : Contains the suggested proposals to pay on a given block -// +// // +// // Finalized Budget : Contains the suggested proposals to pay on a given block +// // -class CFinalizedBudget : public CGovernanceObject -{ // **** Objects and memory **** +// class CFinalizedBudget : public CGovernanceObject +// { // **** Objects and memory **** -private: - // critical section to protect the inner data structures - mutable CCriticalSection cs; - bool fAutoChecked; //If it matches what we see, we'll auto vote for it (masternode only) +// private: +// // critical section to protect the inner data structures +// mutable CCriticalSection cs; +// bool fAutoChecked; //If it matches what we see, we'll auto vote for it (masternode only) -public: - bool fValid; - std::string strBudgetName; - int nBlockStart; - std::vector vecBudgetPayments; - map mapVotes; - uint256 nFeeTXHash; - int64_t nTime; +// public: +// bool fValid; +// std::string strBudgetName; +// int nBlockStart; +// std::vector vecBudgetPayments; +// map mapVotes; +// uint256 nFeeTXHash; +// int64_t nTime; - // **** Initialization **** +// // **** Initialization **** - CFinalizedBudget(); - CFinalizedBudget(const CFinalizedBudget& other); +// CFinalizedBudget(); +// CFinalizedBudget(const CFinalizedBudget& other); - // **** Update **** +// // **** Update **** - bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError); - void AutoCheckSuperBlockVoting(); //check to see if we should vote on new superblock proposals - void CleanAndRemove(bool fSignatureCheck); - void SubmitVote(); //vote on this finalized budget as a masternode +// bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError); +// void AutoCheckSuperBlockVoting(); //check to see if we should vote on new superblock proposals +// void CleanAndRemove(bool fSignatureCheck); +// void SubmitVote(); //vote on this finalized budget as a masternode - // **** Statistics / Information **** - int GetBlockStart() {return nBlockStart;} - int GetBlockEnd() {return nBlockStart + (int)(vecBudgetPayments.size() - 1);} - bool GetBudgetPaymentByBlock(int64_t nBlockHeight, CTxBudgetPayment& payment) - { - LOCK(cs); +// // **** Statistics / Information **** +// int GetBlockStart() {return nBlockStart;} +// int GetBlockEnd() {return nBlockStart + (int)(vecBudgetPayments.size() - 1);} +// bool GetBudgetPaymentByBlock(int64_t nBlockHeight, CTxBudgetPayment& payment) +// { +// LOCK(cs); - int i = nBlockHeight - GetBlockStart(); - if(i < 0) return false; - if(i > (int)vecBudgetPayments.size() - 1) return false; - payment = vecBudgetPayments[i]; - return true; - } +// int i = nBlockHeight - GetBlockStart(); +// if(i < 0) return false; +// if(i > (int)vecBudgetPayments.size() - 1) return false; +// payment = vecBudgetPayments[i]; +// return true; +// } - uint256 GetHash(){ - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - ss << strBudgetName; - ss << nBlockStart; - ss << vecBudgetPayments; +// uint256 GetHash(){ +// CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); +// ss << strBudgetName; +// ss << nBlockStart; +// ss << vecBudgetPayments; - uint256 h1 = ss.GetHash(); - return h1; - } +// uint256 h1 = ss.GetHash(); +// return h1; +// } - std::string GetName() {return strBudgetName; } - bool GetPayeeAndAmount(int64_t nBlockHeight, CScript& payee, CAmount& nAmount) - { - LOCK(cs); +// std::string GetName() {return strBudgetName; } +// bool GetPayeeAndAmount(int64_t nBlockHeight, CScript& payee, CAmount& nAmount) +// { +// LOCK(cs); - int i = nBlockHeight - GetBlockStart(); - if(i < 0) return false; - if(i > (int)vecBudgetPayments.size() - 1) return false; - payee = vecBudgetPayments[i].payee; - nAmount = vecBudgetPayments[i].nAmount; - return true; - } - std::string GetProposals(); - double GetScore(); - string GetStatus(); - CAmount GetTotalPayout(); //total dash paid out by this budget - int64_t GetValidEndTimestamp() {return 0;} - int64_t GetValidStartTimestamp() {return 32503680000;} - int GetVoteCount() {return (int)mapVotes.size();} +// int i = nBlockHeight - GetBlockStart(); +// if(i < 0) return false; +// if(i > (int)vecBudgetPayments.size() - 1) return false; +// payee = vecBudgetPayments[i].payee; +// nAmount = vecBudgetPayments[i].nAmount; +// return true; +// } +// std::string GetProposals(); +// double GetScore(); +// string GetStatus(); +// CAmount GetTotalPayout(); //total dash paid out by this budget +// int64_t GetValidEndTimestamp() {return 0;} +// int64_t GetValidStartTimestamp() {return 32503680000;} +// int GetVoteCount() {return (int)mapVotes.size();} - bool HasMinimumRequiredSupport(); - bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); - bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); +// bool HasMinimumRequiredSupport(); +// bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); +// bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); - // **** Serializer **** +// // **** Serializer **** - ADD_SERIALIZE_METHODS; +// ADD_SERIALIZE_METHODS; - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - // TODO: Do we need names for these? I don't think so - READWRITE(LIMITED_STRING(strBudgetName, 20)); - READWRITE(nFeeTXHash); - READWRITE(nTime); - READWRITE(nBlockStart); - READWRITE(vecBudgetPayments); - READWRITE(fAutoChecked); +// template +// inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { +// // TODO: Do we need names for these? I don't think so +// READWRITE(LIMITED_STRING(strBudgetName, 20)); +// READWRITE(nFeeTXHash); +// READWRITE(nTime); +// READWRITE(nBlockStart); +// READWRITE(vecBudgetPayments); +// READWRITE(fAutoChecked); - READWRITE(mapVotes); - } -}; +// READWRITE(mapVotes); +// } +// }; -// FinalizedBudget are cast then sent to peers with this object, which leaves the votes out -class CFinalizedBudgetBroadcast : public CFinalizedBudget -{ -private: - std::vector vchSig; +// // FinalizedBudget are cast then sent to peers with this object, which leaves the votes out +// class CFinalizedBudgetBroadcast : public CFinalizedBudget +// { +// private: +// std::vector vchSig; -public: - CFinalizedBudgetBroadcast(); - CFinalizedBudgetBroadcast(const CFinalizedBudget& other); - CFinalizedBudgetBroadcast(std::string strBudgetNameIn, int nBlockStartIn, std::vector vecBudgetPaymentsIn, uint256 nFeeTXHashIn); +// public: +// CFinalizedBudgetBroadcast(); +// CFinalizedBudgetBroadcast(const CFinalizedBudget& other); +// CFinalizedBudgetBroadcast(std::string strBudgetNameIn, int nBlockStartIn, std::vector vecBudgetPaymentsIn, uint256 nFeeTXHashIn); - void swap(CFinalizedBudgetBroadcast& first, CFinalizedBudgetBroadcast& second) // nothrow - { - // enable ADL (not necessary in our case, but good practice) - using std::swap; +// void swap(CFinalizedBudgetBroadcast& first, CFinalizedBudgetBroadcast& second) // nothrow +// { +// // enable ADL (not necessary in our case, but good practice) +// using std::swap; - // by swapping the members of two classes, - // the two classes are effectively swapped - swap(first.strBudgetName, second.strBudgetName); - swap(first.nBlockStart, second.nBlockStart); - first.mapVotes.swap(second.mapVotes); - first.vecBudgetPayments.swap(second.vecBudgetPayments); - swap(first.nFeeTXHash, second.nFeeTXHash); - swap(first.nTime, second.nTime); - } +// // by swapping the members of two classes, +// // the two classes are effectively swapped +// swap(first.strBudgetName, second.strBudgetName); +// swap(first.nBlockStart, second.nBlockStart); +// first.mapVotes.swap(second.mapVotes); +// first.vecBudgetPayments.swap(second.vecBudgetPayments); +// swap(first.nFeeTXHash, second.nFeeTXHash); +// swap(first.nTime, second.nTime); +// } - CFinalizedBudgetBroadcast& operator=(CFinalizedBudgetBroadcast from) - { - swap(*this, from); - return *this; - } +// CFinalizedBudgetBroadcast& operator=(CFinalizedBudgetBroadcast from) +// { +// swap(*this, from); +// return *this; +// } - void Relay(); +// void Relay(); - ADD_SERIALIZE_METHODS; +// ADD_SERIALIZE_METHODS; - //for propagating messages - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - //for syncing with other clients - READWRITE(LIMITED_STRING(strBudgetName, 20)); - READWRITE(nBlockStart); - READWRITE(vecBudgetPayments); - READWRITE(nFeeTXHash); - } -}; +// //for propagating messages +// template +// inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { +// //for syncing with other clients +// READWRITE(LIMITED_STRING(strBudgetName, 20)); +// READWRITE(nBlockStart); +// READWRITE(vecBudgetPayments); +// READWRITE(nFeeTXHash); +// } +// }; -// -// CFinalizedBudgetVote - Allow a masternode node to vote and broadcast throughout the network -// +// // +// // CFinalizedBudgetVote - Allow a masternode node to vote and broadcast throughout the network +// // -class CFinalizedBudgetVote -{ -public: - bool fValid; //if the vote is currently valid / counted - bool fSynced; //if we've sent this to our peers - CTxIn vin; - uint256 nBudgetHash; - int64_t nTime; - std::vector vchSig; +// class CFinalizedBudgetVote +// { +// public: +// bool fValid; //if the vote is currently valid / counted +// bool fSynced; //if we've sent this to our peers +// CTxIn vin; +// uint256 nBudgetHash; +// int64_t nTime; +// std::vector vchSig; - CFinalizedBudgetVote(); - CFinalizedBudgetVote(CTxIn vinIn, uint256 nBudgetHashIn); +// CFinalizedBudgetVote(); +// CFinalizedBudgetVote(CTxIn vinIn, uint256 nBudgetHashIn); - bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); - bool SignatureValid(bool fSignatureCheck); - void Relay(); +// bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); +// bool SignatureValid(bool fSignatureCheck); +// void Relay(); - uint256 GetHash(){ - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - ss << vin; - ss << nBudgetHash; - ss << nTime; - return ss.GetHash(); - } +// uint256 GetHash(){ +// CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); +// ss << vin; +// ss << nBudgetHash; +// ss << nTime; +// return ss.GetHash(); +// } - ADD_SERIALIZE_METHODS; +// ADD_SERIALIZE_METHODS; - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(vin); - READWRITE(nBudgetHash); - READWRITE(nTime); - READWRITE(vchSig); - } +// template +// inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { +// READWRITE(vin); +// READWRITE(nBudgetHash); +// READWRITE(nTime); +// READWRITE(vchSig); +// } -}; +// }; diff --git a/src/drafted/governance-finalize.h b/src/drafted/governance-finalize.h index 0862750e9..9c99ac19e 100644 --- a/src/drafted/governance-finalize.h +++ b/src/drafted/governance-finalize.h @@ -1,120 +1,120 @@ -// Copyright (c) 2014-2016 The Dash Core developers +// // Copyright (c) 2014-2016 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef GOVERNANCE_FINALIZE_H -#define GOVERNANCE_FINALIZE_H +// // Distributed under the MIT/X11 software license, see the accompanying +// // file COPYING or http://www.opensource.org/licenses/mit-license.php. +// #ifndef GOVERNANCE_FINALIZE_H +// #define GOVERNANCE_FINALIZE_H -//todo: which of these do we need? -//#include "main.h" -//#include "sync.h" -//#include "net.h" -//#include "key.h" -//#include "util.h" -//#include "base58.h" -//#include "masternode.h" -#include "governance.h" -//#include "governance-types.h" -//#include -#include +// //todo: which of these do we need? +// //#include "main.h" +// //#include "sync.h" +// //#include "net.h" +// //#include "key.h" +// //#include "util.h" +// //#include "base58.h" +// //#include "masternode.h" +// #include "governance.h" +// //#include "governance-types.h" +// //#include +// #include -// -// Finalized Budget : Contains the suggested proposals to pay on a given block -// +// // +// // Finalized Budget : Contains the suggested proposals to pay on a given block +// // -class CFinalizedBudget : public CGovernanceObject -{ // **** Objects and memory **** +// class CFinalizedBudget : public CGovernanceObject +// { // **** Objects and memory **** -private: - // critical section to protect the inner data structures - mutable CCriticalSection cs; - bool fAutoChecked; //If it matches what we see, we'll auto vote for it (masternode only) +// private: +// // critical section to protect the inner data structures +// mutable CCriticalSection cs; +// bool fAutoChecked; //If it matches what we see, we'll auto vote for it (masternode only) -public: - bool fValid; - std::string strBudgetName; - int nBlockStart; - std::vector vecBudgetPayments; - map mapVotes; - uint256 nFeeTXHash; - int64_t nTime; +// public: +// bool fValid; +// std::string strBudgetName; +// int nBlockStart; +// std::vector vecBudgetPayments; +// map mapVotes; +// uint256 nFeeTXHash; +// int64_t nTime; - // **** Initialization **** +// // **** Initialization **** - CFinalizedBudget(); - CFinalizedBudget(const CFinalizedBudget& other); +// CFinalizedBudget(); +// CFinalizedBudget(const CFinalizedBudget& other); - // **** Update **** +// // **** Update **** - bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError); - void AutoCheckSuperBlockVoting(); //check to see if we should vote on new superblock proposals - void CleanAndRemove(bool fSignatureCheck); - void SubmitVote(); //vote on this finalized budget as a masternode +// bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError); +// void AutoCheckSuperBlockVoting(); //check to see if we should vote on new superblock proposals +// void CleanAndRemove(bool fSignatureCheck); +// void SubmitVote(); //vote on this finalized budget as a masternode - // **** Statistics / Information **** - int GetBlockStart() {return nBlockStart;} - int GetBlockEnd() {return nBlockStart + (int)(vecBudgetPayments.size() - 1);} - bool GetBudgetPaymentByBlock(int64_t nBlockHeight, CTxBudgetPayment& payment) - { - LOCK(cs); +// // **** Statistics / Information **** +// int GetBlockStart() {return nBlockStart;} +// int GetBlockEnd() {return nBlockStart + (int)(vecBudgetPayments.size() - 1);} +// bool GetBudgetPaymentByBlock(int64_t nBlockHeight, CTxBudgetPayment& payment) +// { +// LOCK(cs); - int i = nBlockHeight - GetBlockStart(); - if(i < 0) return false; - if(i > (int)vecBudgetPayments.size() - 1) return false; - payment = vecBudgetPayments[i]; - return true; - } +// int i = nBlockHeight - GetBlockStart(); +// if(i < 0) return false; +// if(i > (int)vecBudgetPayments.size() - 1) return false; +// payment = vecBudgetPayments[i]; +// return true; +// } - uint256 GetHash(){ - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - ss << strBudgetName; - ss << nBlockStart; - ss << vecBudgetPayments; +// uint256 GetHash(){ +// CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); +// ss << strBudgetName; +// ss << nBlockStart; +// ss << vecBudgetPayments; - uint256 h1 = ss.GetHash(); - return h1; - } +// uint256 h1 = ss.GetHash(); +// return h1; +// } - std::string GetName() {return strBudgetName; } - bool GetPayeeAndAmount(int64_t nBlockHeight, CScript& payee, CAmount& nAmount) - { - LOCK(cs); +// std::string GetName() {return strBudgetName; } +// bool GetPayeeAndAmount(int64_t nBlockHeight, CScript& payee, CAmount& nAmount) +// { +// LOCK(cs); - int i = nBlockHeight - GetBlockStart(); - if(i < 0) return false; - if(i > (int)vecBudgetPayments.size() - 1) return false; - payee = vecBudgetPayments[i].payee; - nAmount = vecBudgetPayments[i].nAmount; - return true; - } - std::string GetProposals(); - double GetScore(); - string GetStatus(); - CAmount GetTotalPayout(); //total dash paid out by this budget - int64_t GetValidEndTimestamp() {return 0;} - int64_t GetValidStartTimestamp() {return 32503680000;} - int GetVoteCount() {return (int)mapVotes.size();} +// int i = nBlockHeight - GetBlockStart(); +// if(i < 0) return false; +// if(i > (int)vecBudgetPayments.size() - 1) return false; +// payee = vecBudgetPayments[i].payee; +// nAmount = vecBudgetPayments[i].nAmount; +// return true; +// } +// std::string GetProposals(); +// double GetScore(); +// string GetStatus(); +// CAmount GetTotalPayout(); //total dash paid out by this budget +// int64_t GetValidEndTimestamp() {return 0;} +// int64_t GetValidStartTimestamp() {return 32503680000;} +// int GetVoteCount() {return (int)mapVotes.size();} - bool HasMinimumRequiredSupport(); - bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); - bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); +// bool HasMinimumRequiredSupport(); +// bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); +// bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); - // **** Serializer **** +// // **** Serializer **** - ADD_SERIALIZE_METHODS; +// ADD_SERIALIZE_METHODS; - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - // TODO: Do we need names for these? I don't think so - READWRITE(LIMITED_STRING(strBudgetName, 20)); - READWRITE(nFeeTXHash); - READWRITE(nTime); - READWRITE(nBlockStart); - READWRITE(vecBudgetPayments); - READWRITE(fAutoChecked); +// template +// inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { +// // TODO: Do we need names for these? I don't think so +// READWRITE(LIMITED_STRING(strBudgetName, 20)); +// READWRITE(nFeeTXHash); +// READWRITE(nTime); +// READWRITE(nBlockStart); +// READWRITE(vecBudgetPayments); +// READWRITE(fAutoChecked); - READWRITE(mapVotes); - } -}; +// READWRITE(mapVotes); +// } +// }; diff --git a/src/drafted/governance-keys.cpp b/src/drafted/governance-keys.cpp index 0b0686ae8..79075bb99 100644 --- a/src/drafted/governance-keys.cpp +++ b/src/drafted/governance-keys.cpp @@ -1,45 +1,45 @@ -// Copyright (c) 2014-2016 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. +// // Copyright (c) 2014-2016 The Dash Core developers +// // Distributed under the MIT/X11 software license, see the accompanying +// // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef GOVERNANCE_KEYS_H -#define GOVERNANCE_KEYS_H +// #ifndef GOVERNANCE_KEYS_H +// #define GOVERNANCE_KEYS_H -#include -#include -#include +// #include +// #include +// #include -#include -#include "support/allocators/secure.h" -#include "" +// #include +// #include "support/allocators/secure.h" +// #include "" -vector vGovernanceKeys; -CCriticalSection cs_vGovernanceKeys; +// vector vGovernanceKeys; +// CCriticalSection cs_vGovernanceKeys; -bool CGovernanceKeyManager::InitGovernanceKeys(std::string strError) -{ +// bool CGovernanceKeyManager::InitGovernanceKeys(std::string strError) +// { - { - LOCK(cs_vGovernanceKeys); - vGovernanceKeys = mapMultiArgs["-addgovkey"]; - } +// { +// LOCK(cs_vGovernanceKeys); +// vGovernanceKeys = mapMultiArgs["-addgovkey"]; +// } - BOOST_FOREACH(SecureString& strSecure, vGovernanceKeys) - { - std::vector vecTokenized = SplitBy(strSubCommand, ":"); +// BOOST_FOREACH(SecureString& strSecure, vGovernanceKeys) +// { +// std::vector vecTokenized = SplitBy(strSubCommand, ":"); - if(vecTokenized.size() == 2) continue; +// if(vecTokenized.size() == 2) continue; - CBitcoinSecret vchSecret; - bool fGood = vchSecret.SetString(vecTokenized[0]); +// CBitcoinSecret vchSecret; +// bool fGood = vchSecret.SetString(vecTokenized[0]); - if(!fGood) { - strError = "Invalid Governance Key : " + vecTokenized[0]; - return false; - } +// if(!fGood) { +// strError = "Invalid Governance Key : " + vecTokenized[0]; +// return false; +// } - CGovernanceKey key(vecTokenized[0], vecTokenized[1]); - vGovernanceKeys.push_back(key); - } -} \ No newline at end of file +// CGovernanceKey key(vecTokenized[0], vecTokenized[1]); +// vGovernanceKeys.push_back(key); +// } +// } \ No newline at end of file diff --git a/src/drafted/governance-types.h b/src/drafted/governance-types.h index ce13ddced..4b653f805 100644 --- a/src/drafted/governance-types.h +++ b/src/drafted/governance-types.h @@ -73,29 +73,29 @@ extern std::string GovernanceTypeToString(GovernanceObjectType type); // Payments for a finalized budget -class CTxBudgetPayment -{ -public: - uint256 nProposalHash; - CScript payee; - CAmount nAmount; +// class CTxBudgetPayment +// { +// public: +// uint256 nProposalHash; +// CScript payee; +// CAmount nAmount; - CTxBudgetPayment() { - payee = CScript(); - nAmount = 0; - nProposalHash = uint256(); - } +// CTxBudgetPayment() { +// payee = CScript(); +// nAmount = 0; +// nProposalHash = uint256(); +// } - ADD_SERIALIZE_METHODS; +// ADD_SERIALIZE_METHODS; - //for saving to the serialized db - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(*(CScriptBase*)(&payee)); - READWRITE(nAmount); - READWRITE(nProposalHash); - } -}; +// //for saving to the serialized db +// template +// inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { +// READWRITE(*(CScriptBase*)(&payee)); +// READWRITE(nAmount); +// READWRITE(nProposalHash); +// } +// }; #endif \ No newline at end of file diff --git a/src/drafted/governance.new.cpp b/src/drafted/governance.new.cpp index b9a53ac20..d46659a25 100644 --- a/src/drafted/governance.new.cpp +++ b/src/drafted/governance.new.cpp @@ -1,1366 +1,1982 @@ -// Copyright (c) 2014-2016 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. +// // Copyright (c) 2014-2016 The Dash Core developers +// // Distributed under the MIT/X11 software license, see the accompanying +// // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "core_io.h" -#include "main.h" -#include "init.h" +// #include "core_io.h" +// #include "main.h" +// #include "init.h" -#include "governance.h" -#include "masternode.h" -#include "darksend.h" -#include "masternodeman.h" -#include "masternode-sync.h" -#include "util.h" -#include "addrman.h" -#include -#include +// #include "governance.h" +// #include "masternode.h" +// #include "darksend.h" +// #include "masternodeman.h" +// #include "masternode-sync.h" +// #include "util.h" +// #include "addrman.h" +// #include +// #include -CGovernanceManager govman; -CCriticalSection cs_budget; +// CGovernanceManager govman; +// CCriticalSection cs_budget; -std::map askedForSourceProposalOrBudget; -std::vector vecImmatureGovernanceNodes; +// std::map askedForSourceProposalOrBudget; +// std::vector vecImmatureGovernanceNodes; -int nSubmittedFinalBudget; +// int nSubmittedFinalBudget; -bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime, int& nConf) -{ - CTransaction txCollateral; - uint256 nBlockHash; - if(!GetTransaction(nTxCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)){ - strError = strprintf("Can't find collateral tx %s", txCollateral.ToString()); - LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s\n", strError); - return false; - } - - if(txCollateral.vout.size() < 1) return false; - if(txCollateral.nLockTime != 0) return false; - - CScript findScript; - findScript << OP_RETURN << ToByteVector(nExpectedHash); - - bool foundOpReturn = false; - BOOST_FOREACH(const CTxOut o, txCollateral.vout){ - if(!o.scriptPubKey.IsNormalPaymentScript() && !o.scriptPubKey.IsUnspendable()){ - strError = strprintf("Invalid Script %s", txCollateral.ToString()); - LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s\n", strError); - return false; - } - if(o.scriptPubKey == findScript && o.nValue >= BUDGET_FEE_TX) foundOpReturn = true; - - } - if(!foundOpReturn){ - strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral.ToString()); - LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s\n", strError); - return false; - } - - LOCK(cs_main); - int conf = GetIXConfirmations(nTxCollateralHash); - if (nBlockHash != uint256()) { - BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); - if (mi != mapBlockIndex.end() && (*mi).second) { - CBlockIndex* pindex = (*mi).second; - if (chainActive.Contains(pindex)) { - conf += chainActive.Height() - pindex->nHeight + 1; - nTime = pindex->nTime; - } - } - } - - nConf = conf; - - //if we're syncing we won't have instantX information, so accept 1 confirmation - if(conf >= BUDGET_FEE_CONFIRMATIONS){ - return true; - } else { - strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", BUDGET_FEE_CONFIRMATIONS, conf); - LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s - %d confirmations\n", strError, conf); - return false; - } -} - -void CGovernanceManager::CheckOrphanVotes() -{ - LOCK(cs); - - - std::string strError = ""; - std::map::iterator it1 = mapOrphanGovernanceVotes.begin(); - while(it1 != mapOrphanGovernanceVotes.end()){ - if(govman.UpdateGovernanceObjectVotes(((*it1).second), NULL, strError)){ - LogPrintf("CGovernanceManager::CheckOrphanVotes - Proposal/Budget is known, activating and removing orphan vote\n"); - mapOrphanGovernanceVotes.erase(it1++); - } else { - ++it1; - } - } -} - -void CGovernanceManager::SubmitFinalBudget() -{ - - - - // if(!pCurrentBlockIndex) return; - - // int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - // if(nSubmittedFinalBudget >= nBlockStart) return; - // if(nBlockStart - pCurrentBlockIndex->nHeight > 576*2) return; //submit final budget 2 days before payment - - // std::vector vBudgetProposals = govman.GetBudget(); - // std::string strBudgetName = "main"; - // std::vector vecTxBudgetPayments; - - // for(unsigned int i = 0; i < vBudgetProposals.size(); i++){ - // CTxBudgetPayment txBudgetPayment; - // txBudgetPayment.nProposalHash = vBudgetProposals[i]->GetHash(); - // txBudgetPayment.payee = vBudgetProposals[i]->GetPayee(); - // txBudgetPayment.nAmount = vBudgetProposals[i]->GetAllotted(); - // vecTxBudgetPayments.push_back(txBudgetPayment); - // } - - // if(vecTxBudgetPayments.size() < 1) { - // LogPrintf("CGovernanceManager::SubmitFinalBudget - Found No Proposals For Period\n"); - // return; - // } - - // CFinalizedBudgetBroadcast tempBudget(strBudgetName, nBlockStart, vecTxBudgetPayments, uint256()); - // if(mapSeenFinalizedBudgets.count(tempBudget.GetHash())) { - // LogPrintf("CGovernanceManager::SubmitFinalBudget - Budget already exists - %s\n", tempBudget.GetHash().ToString()); - // nSubmittedFinalBudget = pCurrentBlockIndex->nHeight; - // return; //already exists - // } - - // //create fee tx - // CTransaction tx; - // if(!mapCollateral.count(tempBudget.GetHash())){ - // CWalletTx wtx; - // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, tempBudget.GetHash(), false)){ - // LogPrintf("CGovernanceManager::SubmitFinalBudget - Can't make collateral transaction\n"); - // return; - // } - - // // make our change address - // CReserveKey reservekey(pwalletMain); - // //send the tx to the network - // pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::IX); - - // mapCollateral.insert(make_pair(tempBudget.GetHash(), (CTransaction)wtx)); - // tx = (CTransaction)wtx; - // } else { - // tx = mapCollateral[tempBudget.GetHash()]; - // } - - // CTxIn in(COutPoint(tx.GetHash(), 0)); - // int conf = GetInputAgeIX(tx.GetHash(), in); - // /* - // Wait will we have 1 extra confirmation, otherwise some clients might reject this feeTX - // -- This function is tied to NewBlock, so we will propagate this budget while the block is also propagating - // */ - // if(conf < BUDGET_FEE_CONFIRMATIONS+1){ - // LogPrintf ("CGovernanceManager::SubmitFinalBudget - Collateral requires at least %d confirmations - %s - %d confirmations\n", BUDGET_FEE_CONFIRMATIONS, tx.GetHash().ToString(), conf); - // return; - // } - - // nSubmittedFinalBudget = nBlockStart; - - // //create the proposal incase we're the first to make it - // CFinalizedBudgetBroadcast finalizedBudgetBroadcast(strBudgetName, nBlockStart, vecTxBudgetPayments, tx.GetHash()); - - // std::string strError = ""; - // if(!finalizedBudgetBroadcast.IsValid(pCurrentBlockIndex, strError)){ - // LogPrintf("CGovernanceManager::SubmitFinalBudget - Invalid finalized budget - %s \n", strError); - // return; - // } - - // LOCK(cs); - // mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast)); - // finalizedBudgetBroadcast.Relay(); - // govman.AddFinalizedBudget(finalizedBudgetBroadcast); -} - -// -// CBudgetDB -// - -CBudgetDB::CBudgetDB() -{ - pathDB = GetDataDir() / "budget.dat"; - strMagicMessage = "MasternodeBudget"; -} - -bool CBudgetDB::Write(const CGovernanceManager& objToSave) -{ - LOCK(objToSave.cs); - - int64_t nStart = GetTimeMillis(); - - // serialize, checksum data up to that point, then append checksum - CDataStream ssObj(SER_DISK, CLIENT_VERSION); - ssObj << strMagicMessage; // masternode cache file specific magic message - ssObj << FLATDATA(Params().MessageStart()); // network specific magic number - ssObj << objToSave; - uint256 hash = Hash(ssObj.begin(), ssObj.end()); - ssObj << hash; - - // open output file, and associate with CAutoFile - FILE *file = fopen(pathDB.string().c_str(), "wb"); - CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); - if (fileout.IsNull()) - return error("%s : Failed to open file %s", __func__, pathDB.string()); - - // Write and commit header, data - try { - fileout << ssObj; - } - catch (std::exception &e) { - return error("%s : Serialize or I/O error - %s", __func__, e.what()); - } - fileout.fclose(); - - LogPrintf("Written info to budget.dat %dms\n", GetTimeMillis() - nStart); - LogPrintf("Budget manager - %s\n", objToSave.ToString()); - - return true; -} - -CBudgetDB::ReadResult CBudgetDB::Read(CGovernanceManager& objToLoad, bool fDryRun) -{ - //LOCK(objToLoad.cs); - - int64_t nStart = GetTimeMillis(); - // open input file, and associate with CAutoFile - FILE *file = fopen(pathDB.string().c_str(), "rb"); - CAutoFile filein(file, SER_DISK, CLIENT_VERSION); - if (filein.IsNull()) - { - error("%s : Failed to open file %s", __func__, pathDB.string()); - return FileError; - } - - // use file size to size memory buffer - int fileSize = boost::filesystem::file_size(pathDB); - int dataSize = fileSize - sizeof(uint256); - // Don't try to resize to a negative number if file is small - if (dataSize < 0) - dataSize = 0; - vector vchData; - vchData.resize(dataSize); - uint256 hashIn; - - // read data and checksum from file - try { - filein.read((char *)&vchData[0], dataSize); - filein >> hashIn; - } - catch (std::exception &e) { - error("%s : Deserialize or I/O error - %s", __func__, e.what()); - return HashReadError; - } - filein.fclose(); - - CDataStream ssObj(vchData, SER_DISK, CLIENT_VERSION); - - // verify stored checksum matches input data - uint256 hashTmp = Hash(ssObj.begin(), ssObj.end()); - if (hashIn != hashTmp) - { - error("%s : Checksum mismatch, data corrupted", __func__); - return IncorrectHash; - } - - - unsigned char pchMsgTmp[4]; - std::string strMagicMessageTmp; - try { - // de-serialize file header (masternode cache file specific magic message) and .. - ssObj >> strMagicMessageTmp; - - // ... verify the message matches predefined one - if (strMagicMessage != strMagicMessageTmp) - { - error("%s : Invalid masternode cache magic message", __func__); - return IncorrectMagicMessage; - } - - - // de-serialize file header (network specific magic number) and .. - ssObj >> FLATDATA(pchMsgTmp); - - // ... verify the network matches ours - if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) - { - error("%s : Invalid network magic number", __func__); - return IncorrectMagicNumber; - } - - // de-serialize data into CGovernanceManager object - ssObj >> objToLoad; - } - catch (std::exception &e) { - objToLoad.Clear(); - error("%s : Deserialize or I/O error - %s", __func__, e.what()); - return IncorrectFormat; - } - - LogPrintf("Loaded info from budget.dat %dms\n", GetTimeMillis() - nStart); - LogPrintf(" %s\n", objToLoad.ToString()); - if(!fDryRun) { - LogPrintf("Budget manager - cleaning....\n"); - objToLoad.CheckAndRemove(); - LogPrintf("Budget manager - %s\n", objToLoad.ToString()); - } - - return Ok; -} - -// bool CGovernanceManager::AddFinalizedBudget(CFinalizedBudget& finalizedBudget) +// bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime, int& nConf) // { -// std::string strError = ""; -// if(!finalizedBudget.IsValid(pCurrentBlockIndex, strError)) return false; - -// if(mapFinalizedBudgets.count(finalizedBudget.GetHash())) { +// CTransaction txCollateral; +// uint256 nBlockHash; +// if(!GetTransaction(nTxCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)){ +// strError = strprintf("Can't find collateral tx %s", txCollateral.ToString()); +// LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s\n", strError); // return false; // } -// mapFinalizedBudgets.insert(make_pair(finalizedBudget.GetHash(), finalizedBudget)); +// if(txCollateral.vout.size() < 1) return false; +// if(txCollateral.nLockTime != 0) return false; + +// CScript findScript; +// findScript << OP_RETURN << ToByteVector(nExpectedHash); + +// bool foundOpReturn = false; +// BOOST_FOREACH(const CTxOut o, txCollateral.vout){ +// if(!o.scriptPubKey.IsNormalPaymentScript() && !o.scriptPubKey.IsUnspendable()){ +// strError = strprintf("Invalid Script %s", txCollateral.ToString()); +// LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s\n", strError); +// return false; +// } +// if(o.scriptPubKey == findScript && o.nValue >= BUDGET_FEE_TX) foundOpReturn = true; + +// } +// if(!foundOpReturn){ +// strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral.ToString()); +// LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s\n", strError); +// return false; +// } + +// LOCK(cs_main); +// int conf = GetIXConfirmations(nTxCollateralHash); +// if (nBlockHash != uint256()) { +// BlockMap::iterator mi = mapBlockIndex.find(nBlockHash); +// if (mi != mapBlockIndex.end() && (*mi).second) { +// CBlockIndex* pindex = (*mi).second; +// if (chainActive.Contains(pindex)) { +// conf += chainActive.Height() - pindex->nHeight + 1; +// nTime = pindex->nTime; +// } +// } +// } + +// nConf = conf; + +// //if we're syncing we won't have instantX information, so accept 1 confirmation +// if(conf >= BUDGET_FEE_CONFIRMATIONS){ +// return true; +// } else { +// strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", BUDGET_FEE_CONFIRMATIONS, conf); +// LogPrintf ("CGovernanceNodeBroadcast::IsBudgetCollateralValid - %s - %d confirmations\n", strError, conf); +// return false; +// } +// } + +// void CGovernanceManager::CheckOrphanVotes() +// { +// LOCK(cs); + + +// std::string strError = ""; +// std::map::iterator it1 = mapOrphanGovernanceVotes.begin(); +// while(it1 != mapOrphanGovernanceVotes.end()){ +// if(govman.UpdateGovernanceObjectVotes(((*it1).second), NULL, strError)){ +// LogPrintf("CGovernanceManager::CheckOrphanVotes - Proposal/Budget is known, activating and removing orphan vote\n"); +// mapOrphanGovernanceVotes.erase(it1++); +// } else { +// ++it1; +// } +// } +// } + +// void CGovernanceManager::SubmitFinalBudget() +// { + + + +// // if(!pCurrentBlockIndex) return; + +// // int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// // if(nSubmittedFinalBudget >= nBlockStart) return; +// // if(nBlockStart - pCurrentBlockIndex->nHeight > 576*2) return; //submit final budget 2 days before payment + +// // std::vector vBudgetProposals = govman.GetBudget(); +// // std::string strBudgetName = "main"; +// // std::vector vecTxBudgetPayments; + +// // for(unsigned int i = 0; i < vBudgetProposals.size(); i++){ +// // CTxBudgetPayment txBudgetPayment; +// // txBudgetPayment.nProposalHash = vBudgetProposals[i]->GetHash(); +// // txBudgetPayment.payee = vBudgetProposals[i]->GetPayee(); +// // txBudgetPayment.nAmount = vBudgetProposals[i]->GetAllotted(); +// // vecTxBudgetPayments.push_back(txBudgetPayment); +// // } + +// // if(vecTxBudgetPayments.size() < 1) { +// // LogPrintf("CGovernanceManager::SubmitFinalBudget - Found No Proposals For Period\n"); +// // return; +// // } + +// // CFinalizedBudgetBroadcast tempBudget(strBudgetName, nBlockStart, vecTxBudgetPayments, uint256()); +// // if(mapSeenFinalizedBudgets.count(tempBudget.GetHash())) { +// // LogPrintf("CGovernanceManager::SubmitFinalBudget - Budget already exists - %s\n", tempBudget.GetHash().ToString()); +// // nSubmittedFinalBudget = pCurrentBlockIndex->nHeight; +// // return; //already exists +// // } + +// // //create fee tx +// // CTransaction tx; +// // if(!mapCollateral.count(tempBudget.GetHash())){ +// // CWalletTx wtx; +// // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, tempBudget.GetHash(), false)){ +// // LogPrintf("CGovernanceManager::SubmitFinalBudget - Can't make collateral transaction\n"); +// // return; +// // } + +// // // make our change address +// // CReserveKey reservekey(pwalletMain); +// // //send the tx to the network +// // pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::IX); + +// // mapCollateral.insert(make_pair(tempBudget.GetHash(), (CTransaction)wtx)); +// // tx = (CTransaction)wtx; +// // } else { +// // tx = mapCollateral[tempBudget.GetHash()]; +// // } + +// // CTxIn in(COutPoint(tx.GetHash(), 0)); +// // int conf = GetInputAgeIX(tx.GetHash(), in); +// // /* +// // Wait will we have 1 extra confirmation, otherwise some clients might reject this feeTX +// // -- This function is tied to NewBlock, so we will propagate this budget while the block is also propagating +// // */ +// // if(conf < BUDGET_FEE_CONFIRMATIONS+1){ +// // LogPrintf ("CGovernanceManager::SubmitFinalBudget - Collateral requires at least %d confirmations - %s - %d confirmations\n", BUDGET_FEE_CONFIRMATIONS, tx.GetHash().ToString(), conf); +// // return; +// // } + +// // nSubmittedFinalBudget = nBlockStart; + +// // //create the proposal incase we're the first to make it +// // CFinalizedBudgetBroadcast finalizedBudgetBroadcast(strBudgetName, nBlockStart, vecTxBudgetPayments, tx.GetHash()); + +// // std::string strError = ""; +// // if(!finalizedBudgetBroadcast.IsValid(pCurrentBlockIndex, strError)){ +// // LogPrintf("CGovernanceManager::SubmitFinalBudget - Invalid finalized budget - %s \n", strError); +// // return; +// // } + +// // LOCK(cs); +// // mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast)); +// // finalizedBudgetBroadcast.Relay(); +// // govman.AddFinalizedBudget(finalizedBudgetBroadcast); +// } + +// // +// // CBudgetDB +// // + +// CBudgetDB::CBudgetDB() +// { +// pathDB = GetDataDir() / "budget.dat"; +// strMagicMessage = "MasternodeBudget"; +// } + +// bool CBudgetDB::Write(const CGovernanceManager& objToSave) +// { +// LOCK(objToSave.cs); + +// int64_t nStart = GetTimeMillis(); + +// // serialize, checksum data up to that point, then append checksum +// CDataStream ssObj(SER_DISK, CLIENT_VERSION); +// ssObj << strMagicMessage; // masternode cache file specific magic message +// ssObj << FLATDATA(Params().MessageStart()); // network specific magic number +// ssObj << objToSave; +// uint256 hash = Hash(ssObj.begin(), ssObj.end()); +// ssObj << hash; + +// // open output file, and associate with CAutoFile +// FILE *file = fopen(pathDB.string().c_str(), "wb"); +// CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); +// if (fileout.IsNull()) +// return error("%s : Failed to open file %s", __func__, pathDB.string()); + +// // Write and commit header, data +// try { +// fileout << ssObj; +// } +// catch (std::exception &e) { +// return error("%s : Serialize or I/O error - %s", __func__, e.what()); +// } +// fileout.fclose(); + +// LogPrintf("Written info to budget.dat %dms\n", GetTimeMillis() - nStart); +// LogPrintf("Budget manager - %s\n", objToSave.ToString()); + // return true; // } -bool CGovernanceManager::AddGovernanceObject(CGovernanceNode& budgetProposal) -{ - LOCK(cs); - std::string strError = ""; - if(!budgetProposal.IsValid(pCurrentBlockIndex, strError)) { - LogPrintf("CGovernanceManager::AddGovernanceObject - invalid budget proposal - %s\n", strError); - return false; - } - - if(mapGovernanceObjects.count(budgetProposal.GetHash())) { - return false; - } - - mapGovernanceObjects.insert(make_pair(budgetProposal.GetHash(), budgetProposal)); - return true; -} - -void CGovernanceManager::CheckAndRemove() -{ - LogPrintf("CGovernanceManager::CheckAndRemove \n"); - - if(!pCurrentBlockIndex) return; - - std::string strError = ""; - - // TODO 12.1 - // std::map::iterator it = mapFinalizedBudgets.begin(); - // while(it != mapFinalizedBudgets.end()) - // { - // CFinalizedBudget* pfinalizedBudget = &((*it).second); - - // pfinalizedBudget->fValid = pfinalizedBudget->IsValid(pCurrentBlockIndex, strError); - // if(pfinalizedBudget->fValid) { - // pfinalizedBudget->AutoCheckSuperBlockVoting(); - // ++it; - // continue; - // } else if(pfinalizedBudget->nBlockStart != 0 && pfinalizedBudget->nBlockStart < pCurrentBlockIndex->nHeight - Params().GetConsensus().nBudgetPaymentsCycleBlocks) { - // // it's too old, remove it - // mapFinalizedBudgets.erase(it++); - // LogPrintf("CGovernanceManager::CheckAndRemove - removing budget %s\n", pfinalizedBudget->GetHash().ToString()); - // continue; - // } - // // it's not valid already but it's not too old yet, keep it and move to the next one - // ++it; - // } - - std::map::iterator it2 = mapGovernanceObjects.begin(); - while(it2 != mapGovernanceObjects.end()) - { - CGovernanceNode* node = &((*it2).second); - node->fValid = node->IsValid(pCurrentBlockIndex, strError); - ++it2; - } -} - -void CGovernanceManager::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees) -{ - LOCK(cs); - - AssertLockHeld(cs_main); - if(!chainActive.Tip()) return; - - int nHighestCount = 0; - CScript payee; - CAmount nAmount = 0; - - // ------- Grab The Highest Count - - // TODO 12.1 - // std::map::iterator it = mapFinalizedBudgets.begin(); - // while(it != mapFinalizedBudgets.end()) - // { - // CFinalizedBudget* pfinalizedBudget = &((*it).second); - // if(pfinalizedBudget->GetVoteCount() > nHighestCount && - // chainActive.Tip()->nHeight + 1 >= pfinalizedBudget->GetBlockStart() && - // chainActive.Tip()->nHeight + 1 <= pfinalizedBudget->GetBlockEnd() && - // pfinalizedBudget->GetPayeeAndAmount(chainActive.Tip()->nHeight + 1, payee, nAmount)){ - // nHighestCount = pfinalizedBudget->GetVoteCount(); - // } - - // ++it; - // } - - //miners get the full amount on these blocks - txNew.vout[0].nValue = nFees + GetBlockSubsidy(chainActive.Tip()->nBits, chainActive.Tip()->nHeight, Params().GetConsensus()); - - if(nHighestCount > 0){ - txNew.vout.resize(2); - - //these are super blocks, so their value can be much larger than normal - txNew.vout[1].scriptPubKey = payee; - txNew.vout[1].nValue = nAmount; - - CTxDestination address1; - ExtractDestination(payee, address1); - CBitcoinAddress address2(address1); - - LogPrintf("CGovernanceManager::FillBlockPayee - Budget payment to %s for %lld\n", address2.ToString(), nAmount); - } - -} - -// CFinalizedBudget *CGovernanceManager::FindFinalizedBudget(uint256 nHash) +// CBudgetDB::ReadResult CBudgetDB::Read(CGovernanceManager& objToLoad, bool fDryRun) // { -// if(mapFinalizedBudgets.count(nHash)) -// return &mapFinalizedBudgets[nHash]; +// //LOCK(objToLoad.cs); + +// int64_t nStart = GetTimeMillis(); +// // open input file, and associate with CAutoFile +// FILE *file = fopen(pathDB.string().c_str(), "rb"); +// CAutoFile filein(file, SER_DISK, CLIENT_VERSION); +// if (filein.IsNull()) +// { +// error("%s : Failed to open file %s", __func__, pathDB.string()); +// return FileError; +// } + +// // use file size to size memory buffer +// int fileSize = boost::filesystem::file_size(pathDB); +// int dataSize = fileSize - sizeof(uint256); +// // Don't try to resize to a negative number if file is small +// if (dataSize < 0) +// dataSize = 0; +// vector vchData; +// vchData.resize(dataSize); +// uint256 hashIn; + +// // read data and checksum from file +// try { +// filein.read((char *)&vchData[0], dataSize); +// filein >> hashIn; +// } +// catch (std::exception &e) { +// error("%s : Deserialize or I/O error - %s", __func__, e.what()); +// return HashReadError; +// } +// filein.fclose(); + +// CDataStream ssObj(vchData, SER_DISK, CLIENT_VERSION); + +// // verify stored checksum matches input data +// uint256 hashTmp = Hash(ssObj.begin(), ssObj.end()); +// if (hashIn != hashTmp) +// { +// error("%s : Checksum mismatch, data corrupted", __func__); +// return IncorrectHash; +// } + + +// unsigned char pchMsgTmp[4]; +// std::string strMagicMessageTmp; +// try { +// // de-serialize file header (masternode cache file specific magic message) and .. +// ssObj >> strMagicMessageTmp; + +// // ... verify the message matches predefined one +// if (strMagicMessage != strMagicMessageTmp) +// { +// error("%s : Invalid masternode cache magic message", __func__); +// return IncorrectMagicMessage; +// } + + +// // de-serialize file header (network specific magic number) and .. +// ssObj >> FLATDATA(pchMsgTmp); + +// // ... verify the network matches ours +// if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) +// { +// error("%s : Invalid network magic number", __func__); +// return IncorrectMagicNumber; +// } + +// // de-serialize data into CGovernanceManager object +// ssObj >> objToLoad; +// } +// catch (std::exception &e) { +// objToLoad.Clear(); +// error("%s : Deserialize or I/O error - %s", __func__, e.what()); +// return IncorrectFormat; +// } + +// LogPrintf("Loaded info from budget.dat %dms\n", GetTimeMillis() - nStart); +// LogPrintf(" %s\n", objToLoad.ToString()); +// if(!fDryRun) { +// LogPrintf("Budget manager - cleaning....\n"); +// objToLoad.CheckAndRemove(); +// LogPrintf("Budget manager - %s\n", objToLoad.ToString()); +// } + +// return Ok; +// } + +// // bool CGovernanceManager::AddFinalizedBudget(CFinalizedBudget& finalizedBudget) +// // { +// // std::string strError = ""; +// // if(!finalizedBudget.IsValid(pCurrentBlockIndex, strError)) return false; + +// // if(mapFinalizedBudgets.count(finalizedBudget.GetHash())) { +// // return false; +// // } + +// // mapFinalizedBudgets.insert(make_pair(finalizedBudget.GetHash(), finalizedBudget)); +// // return true; +// // } + +// bool CGovernanceManager::AddGovernanceObject(CGovernanceNode& budgetProposal) +// { +// LOCK(cs); +// std::string strError = ""; +// if(!budgetProposal.IsValid(pCurrentBlockIndex, strError)) { +// LogPrintf("CGovernanceManager::AddGovernanceObject - invalid budget proposal - %s\n", strError); +// return false; +// } + +// if(mapGovernanceObjects.count(budgetProposal.GetHash())) { +// return false; +// } + +// mapGovernanceObjects.insert(make_pair(budgetProposal.GetHash(), budgetProposal)); +// return true; +// } + +// void CGovernanceManager::CheckAndRemove() +// { +// LogPrintf("CGovernanceManager::CheckAndRemove \n"); + +// if(!pCurrentBlockIndex) return; + +// std::string strError = ""; + +// // TODO 12.1 +// // std::map::iterator it = mapFinalizedBudgets.begin(); +// // while(it != mapFinalizedBudgets.end()) +// // { +// // CFinalizedBudget* pfinalizedBudget = &((*it).second); + +// // pfinalizedBudget->fValid = pfinalizedBudget->IsValid(pCurrentBlockIndex, strError); +// // if(pfinalizedBudget->fValid) { +// // pfinalizedBudget->AutoCheckSuperBlockVoting(); +// // ++it; +// // continue; +// // } else if(pfinalizedBudget->nBlockStart != 0 && pfinalizedBudget->nBlockStart < pCurrentBlockIndex->nHeight - Params().GetConsensus().nBudgetPaymentsCycleBlocks) { +// // // it's too old, remove it +// // mapFinalizedBudgets.erase(it++); +// // LogPrintf("CGovernanceManager::CheckAndRemove - removing budget %s\n", pfinalizedBudget->GetHash().ToString()); +// // continue; +// // } +// // // it's not valid already but it's not too old yet, keep it and move to the next one +// // ++it; +// // } + +// std::map::iterator it2 = mapGovernanceObjects.begin(); +// while(it2 != mapGovernanceObjects.end()) +// { +// CGovernanceNode* node = &((*it2).second); +// node->fValid = node->IsValid(pCurrentBlockIndex, strError); +// ++it2; +// } +// } + +// void CGovernanceManager::FillBlockPayee(CMutableTransaction& txNew, CAmount nFees) +// { +// LOCK(cs); + +// AssertLockHeld(cs_main); +// if(!chainActive.Tip()) return; + +// int nHighestCount = 0; +// CScript payee; +// CAmount nAmount = 0; + +// // ------- Grab The Highest Count + +// // TODO 12.1 +// // std::map::iterator it = mapFinalizedBudgets.begin(); +// // while(it != mapFinalizedBudgets.end()) +// // { +// // CFinalizedBudget* pfinalizedBudget = &((*it).second); +// // if(pfinalizedBudget->GetVoteCount() > nHighestCount && +// // chainActive.Tip()->nHeight + 1 >= pfinalizedBudget->GetBlockStart() && +// // chainActive.Tip()->nHeight + 1 <= pfinalizedBudget->GetBlockEnd() && +// // pfinalizedBudget->GetPayeeAndAmount(chainActive.Tip()->nHeight + 1, payee, nAmount)){ +// // nHighestCount = pfinalizedBudget->GetVoteCount(); +// // } + +// // ++it; +// // } + +// //miners get the full amount on these blocks +// txNew.vout[0].nValue = nFees + GetBlockSubsidy(chainActive.Tip()->nBits, chainActive.Tip()->nHeight, Params().GetConsensus()); + +// if(nHighestCount > 0){ +// txNew.vout.resize(2); + +// //these are super blocks, so their value can be much larger than normal +// txNew.vout[1].scriptPubKey = payee; +// txNew.vout[1].nValue = nAmount; + +// CTxDestination address1; +// ExtractDestination(payee, address1); +// CBitcoinAddress address2(address1); + +// LogPrintf("CGovernanceManager::FillBlockPayee - Budget payment to %s for %lld\n", address2.ToString(), nAmount); +// } + +// } + +// // CFinalizedBudget *CGovernanceManager::FindFinalizedBudget(uint256 nHash) +// // { +// // if(mapFinalizedBudgets.count(nHash)) +// // return &mapFinalizedBudgets[nHash]; + +// // return NULL; +// // } + +// CGovernanceNode *CGovernanceManager::FindGovernanceObject(const std::string &strName) +// { +// //find the prop with the highest yes count + +// int nYesCount = -99999; +// CGovernanceNode* pbudgetProposal = NULL; + +// std::map::iterator it = mapGovernanceObjects.begin(); +// while(it != mapGovernanceObjects.end()){ +// if((*it).second.strName == strName && (*it).second.GetYesCount() > nYesCount){ +// pbudgetProposal = &((*it).second); +// nYesCount = pbudgetProposal->GetYesCount(); +// } +// ++it; +// } + +// if(nYesCount == -99999) return NULL; + +// return pbudgetProposal; +// } + +// CGovernanceNode *CGovernanceManager::FindGovernanceObject(uint256 nHash) +// { +// LOCK(cs); + +// if(mapGovernanceObjects.count(nHash)) +// return &mapGovernanceObjects[nHash]; // return NULL; // } -CGovernanceNode *CGovernanceManager::FindGovernanceObject(const std::string &strName) -{ - //find the prop with the highest yes count +// bool CGovernanceManager::IsBudgetPaymentBlock(int nBlockHeight) +// { +// int nHighestCount = -1; - int nYesCount = -99999; - CGovernanceNode* pbudgetProposal = NULL; +// // TODO 12.1 +// // std::map::iterator it = mapFinalizedBudgets.begin(); +// // while(it != mapFinalizedBudgets.end()) +// // { +// // CFinalizedBudget* pfinalizedBudget = &((*it).second); +// // if(pfinalizedBudget->GetVoteCount() > nHighestCount && +// // nBlockHeight >= pfinalizedBudget->GetBlockStart() && +// // nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ +// // nHighestCount = pfinalizedBudget->GetVoteCount(); +// // } - std::map::iterator it = mapGovernanceObjects.begin(); - while(it != mapGovernanceObjects.end()){ - if((*it).second.strName == strName && (*it).second.GetYesCount() > nYesCount){ - pbudgetProposal = &((*it).second); - nYesCount = pbudgetProposal->GetYesCount(); - } - ++it; - } - - if(nYesCount == -99999) return NULL; +// // ++it; +// // } - return pbudgetProposal; -} +// // /* +// // If budget doesn't have 5% of the network votes, then we should pay a masternode instead +// // */ +// // if(nHighestCount > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return true; -CGovernanceNode *CGovernanceManager::FindGovernanceObject(uint256 nHash) -{ - LOCK(cs); +// return false; +// } - if(mapGovernanceObjects.count(nHash)) - return &mapGovernanceObjects[nHash]; +// bool CGovernanceManager::HasNextFinalizedBudget() +// { +// if(!pCurrentBlockIndex) return false; - return NULL; -} +// if(masternodeSync.IsBudgetFinEmpty()) return true; -bool CGovernanceManager::IsBudgetPaymentBlock(int nBlockHeight) -{ - int nHighestCount = -1; +// int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// if(nBlockStart - pCurrentBlockIndex->nHeight > 576*2) return true; //we wouldn't have the budget yet - // TODO 12.1 - // std::map::iterator it = mapFinalizedBudgets.begin(); - // while(it != mapFinalizedBudgets.end()) - // { - // CFinalizedBudget* pfinalizedBudget = &((*it).second); - // if(pfinalizedBudget->GetVoteCount() > nHighestCount && - // nBlockHeight >= pfinalizedBudget->GetBlockStart() && - // nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ - // nHighestCount = pfinalizedBudget->GetVoteCount(); - // } +// if(govman.IsBudgetPaymentBlock(nBlockStart)) return true; - // ++it; - // } +// LogPrintf("CGovernanceManager::HasNextFinalizedBudget() - Client is missing budget - %lli\n", nBlockStart); - // /* - // If budget doesn't have 5% of the network votes, then we should pay a masternode instead - // */ - // if(nHighestCount > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return true; +// return false; +// } - return false; -} +// bool CGovernanceManager::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) +// { +// LOCK(cs); -bool CGovernanceManager::HasNextFinalizedBudget() -{ - if(!pCurrentBlockIndex) return false; +// // TODO 12.1 - if(masternodeSync.IsBudgetFinEmpty()) return true; +// // int nHighestCount = 0; +// // std::vector ret; - int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - if(nBlockStart - pCurrentBlockIndex->nHeight > 576*2) return true; //we wouldn't have the budget yet +// // // ------- Grab The Highest Count - if(govman.IsBudgetPaymentBlock(nBlockStart)) return true; +// // std::map::iterator it = mapFinalizedBudgets.begin(); +// // while(it != mapFinalizedBudgets.end()) +// // { +// // CFinalizedBudget* pfinalizedBudget = &((*it).second); +// // if(pfinalizedBudget->GetVoteCount() > nHighestCount && +// // nBlockHeight >= pfinalizedBudget->GetBlockStart() && +// // nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ +// // nHighestCount = pfinalizedBudget->GetVoteCount(); +// // } - LogPrintf("CGovernanceManager::HasNextFinalizedBudget() - Client is missing budget - %lli\n", nBlockStart); +// // ++it; +// // } - return false; -} +// // /* +// // If budget doesn't have 5% of the network votes, then we should pay a masternode instead +// // */ +// // if(nHighestCount < mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return false; -bool CGovernanceManager::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) -{ - LOCK(cs); +// // // check the highest finalized budgets (+/- 10% to assist in consensus) - // TODO 12.1 +// // it = mapFinalizedBudgets.begin(); +// // while(it != mapFinalizedBudgets.end()) +// // { +// // CFinalizedBudget* pfinalizedBudget = &((*it).second); - // int nHighestCount = 0; - // std::vector ret; +// // if(pfinalizedBudget->GetVoteCount() > nHighestCount - mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){ +// // if(nBlockHeight >= pfinalizedBudget->GetBlockStart() && nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ +// // if(pfinalizedBudget->IsTransactionValid(txNew, nBlockHeight)){ +// // return true; +// // } +// // } +// // } - // // ------- Grab The Highest Count +// // ++it; +// // } - // std::map::iterator it = mapFinalizedBudgets.begin(); - // while(it != mapFinalizedBudgets.end()) - // { - // CFinalizedBudget* pfinalizedBudget = &((*it).second); - // if(pfinalizedBudget->GetVoteCount() > nHighestCount && - // nBlockHeight >= pfinalizedBudget->GetBlockStart() && - // nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ - // nHighestCount = pfinalizedBudget->GetVoteCount(); - // } +// //we looked through all of the known budgets +// return false; +// } - // ++it; - // } +// std::vector CGovernanceManager::FindMatchingGovernanceObjects(GovernanceObjectType type) +// { +// LOCK(cs); - // /* - // If budget doesn't have 5% of the network votes, then we should pay a masternode instead - // */ - // if(nHighestCount < mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/20) return false; - // // check the highest finalized budgets (+/- 10% to assist in consensus) +// std::vector vBudgetProposalRet; - // it = mapFinalizedBudgets.begin(); - // while(it != mapFinalizedBudgets.end()) - // { - // CFinalizedBudget* pfinalizedBudget = &((*it).second); +// // TODO 12.1 - // if(pfinalizedBudget->GetVoteCount() > nHighestCount - mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){ - // if(nBlockHeight >= pfinalizedBudget->GetBlockStart() && nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ - // if(pfinalizedBudget->IsTransactionValid(txNew, nBlockHeight)){ - // return true; - // } - // } - // } +// // if(type == Proposal || type == Contract || type == Switch || type == Setting) +// // { +// // std::map::iterator it = mapGovernanceObjects.begin(); +// // while(it != mapGovernanceObjects.end()) +// // { +// // if((*it).second.GetGovernanceType() != type) {++it; continue;} - // ++it; - // } +// // (*it).second.CleanAndRemove(false); - //we looked through all of the known budgets - return false; -} +// // CGovernanceNode* pbudgetProposal = &((*it).second); +// // vBudgetProposalRet.push_back(pbudgetProposal); -std::vector CGovernanceManager::FindMatchingGovernanceObjects(GovernanceObjectType type) -{ - LOCK(cs); +// // ++it; +// // } +// // } +// // Finalized Budgets should use - std::vector vBudgetProposalRet; +// return vBudgetProposalRet; +// } - // TODO 12.1 - - // if(type == Proposal || type == Contract || type == Switch || type == Setting) - // { - // std::map::iterator it = mapGovernanceObjects.begin(); - // while(it != mapGovernanceObjects.end()) - // { - // if((*it).second.GetGovernanceType() != type) {++it; continue;} - - // (*it).second.CleanAndRemove(false); - - // CGovernanceNode* pbudgetProposal = &((*it).second); - // vBudgetProposalRet.push_back(pbudgetProposal); - - // ++it; - // } - // } - - // Finalized Budgets should use - - return vBudgetProposalRet; -} - -// -// Sort by votes, if there's a tie sort by their feeHash TX -// -struct sortProposalsByVotes { - bool operator()(const std::pair &left, const std::pair &right) { - if( left.second != right.second) - return (left.second > right.second); - return (UintToArith256(left.first->nFeeTXHash) > UintToArith256(right.first->nFeeTXHash)); - } -}; - -//Need to review this function -std::vector CGovernanceManager::GetBudget() -{ - LOCK(cs); - std::vector vBudgetProposalsRet; - - - // TODO 12.1 - - // // ------- Sort budgets by Yes Count - - // std::vector > vBudgetPorposalsSort; - - // std::map::iterator it = mapGovernanceObjects.begin(); - // while(it != mapGovernanceObjects.end()){ - // (*it).second.CleanAndRemove(false); - - // /* - // list offset - - // count * 0.00 : Proposal (marked charity) : 0% to 05% - // count * 0.05 : Proposals : 5% to 100% - // count * 1.00 : Contracts : 100% to 200% - // count * 2.00 : High Priority Contracts : 200%+ - // */ - // int nOffset = 0; - - // if((*it).second.GetGovernanceType() == Setting) {it++; continue;} - // if((*it).second.GetGovernanceType() == Proposal) nOffset += 0; - // if((*it).second.GetGovernanceType() == Contract) nOffset += mnodeman.CountEnabled(); - - // vBudgetPorposalsSort.push_back(make_pair(&((*it).second), nOffset+((*it).second.GetYesCount()-(*it).second.GetNoCount()))); - - // ++it; - // } - - // std::sort(vBudgetPorposalsSort.begin(), vBudgetPorposalsSort.end(), sortProposalsByVotes()); - - // // ------- Grab The Budgets In Order - - // CAmount nBudgetAllocated = 0; - // if(!pCurrentBlockIndex) return vBudgetProposalsRet; - - // int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - // int nBlockEnd = nBlockStart + Params().GetConsensus().nBudgetPaymentsWindowBlocks; - // CAmount nTotalBudget = GetTotalBudget(nBlockStart); - - - // std::vector >::iterator it2 = vBudgetPorposalsSort.begin(); - // while(it2 != vBudgetPorposalsSort.end()) - // { - // CGovernanceNode* pbudgetProposal = (*it2).first; - - - // printf("-> Budget Name : %s\n", pbudgetProposal->strName.c_str()); - // printf("------- nBlockStart : %d\n", pbudgetProposal->nBlockStart); - // printf("------- nBlockEnd : %d\n", pbudgetProposal->nBlockEnd); - // printf("------- nBlockStart2 : %d\n", nBlockStart); - // printf("------- nBlockEnd2 : %d\n", nBlockEnd); - - // printf("------- 1 : %d\n", pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart); - // printf("------- 2 : %d\n", pbudgetProposal->nBlockEnd >= nBlockEnd); - // printf("------- 3 : %d\n", pbudgetProposal->GetYesCount() - pbudgetProposal->GetNoCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10); - // printf("------- 4 : %d\n", pbudgetProposal->IsEstablished()); - - // //prop start/end should be inside this period - // if(pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart && - // pbudgetProposal->nBlockEnd >= nBlockEnd && - // pbudgetProposal->GetYesCount() - pbudgetProposal->GetNoCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10 && - // pbudgetProposal->IsEstablished()) - // { - // printf("------- In range \n"); - - // if(pbudgetProposal->GetAmount() + nBudgetAllocated <= nTotalBudget) { - // pbudgetProposal->SetAllotted(pbudgetProposal->GetAmount()); - // nBudgetAllocated += pbudgetProposal->GetAmount(); - // vBudgetProposalsRet.push_back(pbudgetProposal); - // printf("------- YES \n"); - // } else { - // pbudgetProposal->SetAllotted(0); - // } - // } - - // ++it2; - // } - - return vBudgetProposalsRet; -} - -// struct sortFinalizedBudgetsByVotes { -// bool operator()(const std::pair &left, const std::pair &right) { -// return left.second > right.second; +// // +// // Sort by votes, if there's a tie sort by their feeHash TX +// // +// struct sortProposalsByVotes { +// bool operator()(const std::pair &left, const std::pair &right) { +// if( left.second != right.second) +// return (left.second > right.second); +// return (UintToArith256(left.first->nFeeTXHash) > UintToArith256(right.first->nFeeTXHash)); // } // }; -std::vector CGovernanceManager::GetFinalizedBudgets() -{ - LOCK(cs); +// //Need to review this function +// std::vector CGovernanceManager::GetBudget() +// { +// LOCK(cs); +// std::vector vBudgetProposalsRet; - // TODO 12.1 - std::vector vFinalizedBudgetsRet; - // std::vector > vFinalizedBudgetsSort; +// // TODO 12.1 - // // ------- Grab The Budgets In Order +// // // ------- Sort budgets by Yes Count - // std::map::iterator it = mapFinalizedBudgets.begin(); - // while(it != mapFinalizedBudgets.end()) - // { - // CFinalizedBudget* pfinalizedBudget = &((*it).second); +// // std::vector > vBudgetPorposalsSort; - // vFinalizedBudgetsSort.push_back(make_pair(pfinalizedBudget, pfinalizedBudget->GetVoteCount())); - // ++it; - // } - // std::sort(vFinalizedBudgetsSort.begin(), vFinalizedBudgetsSort.end(), sortFinalizedBudgetsByVotes()); +// // std::map::iterator it = mapGovernanceObjects.begin(); +// // while(it != mapGovernanceObjects.end()){ +// // (*it).second.CleanAndRemove(false); - // std::vector >::iterator it2 = vFinalizedBudgetsSort.begin(); - // while(it2 != vFinalizedBudgetsSort.end()) - // { - // vFinalizedBudgetsRet.push_back((*it2).first); - // ++it2; - // } +// // /* +// // list offset - return vFinalizedBudgetsRet; -} +// // count * 0.00 : Proposal (marked charity) : 0% to 05% +// // count * 0.05 : Proposals : 5% to 100% +// // count * 1.00 : Contracts : 100% to 200% +// // count * 2.00 : High Priority Contracts : 200%+ +// // */ +// // int nOffset = 0; -std::string CGovernanceManager::GetRequiredPaymentsString(int nBlockHeight) -{ - LOCK(cs); - - std::string ret = "unknown-budget"; - - std::map::iterator it = mapFinalizedBudgets.begin(); - while(it != mapFinalizedBudgets.end()) - { - CFinalizedBudget* pfinalizedBudget = &((*it).second); - if(nBlockHeight >= pfinalizedBudget->GetBlockStart() && nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ - CTxBudgetPayment payment; - if(pfinalizedBudget->GetBudgetPaymentByBlock(nBlockHeight, payment)){ - if(ret == "unknown-budget"){ - ret = payment.nProposalHash.ToString(); - } else { - ret += ","; - ret += payment.nProposalHash.ToString(); - } - } else { - LogPrintf("CGovernanceManager::GetRequiredPaymentsString - Couldn't find budget payment for block %d\n", nBlockHeight); - } - } - - ++it; - } - - return ret; -} - -CAmount CGovernanceManager::GetTotalBudget(int nHeight) -{ - if(!pCurrentBlockIndex) return 0; - - //get min block value and calculate from that - CAmount nSubsidy = 5 * COIN; - - const Consensus::Params consensusParams = Params().GetConsensus(); - - // TODO: Remove this to further unify logic among mainnet/testnet/whatevernet, - // use single formula instead (the one that is for current mainnet). - // Probably a good idea to use a significally lower consensusParams.nSubsidyHalvingInterval - // for testnet (like 10 times for example) to see the effect of halving there faster. - // Will require testnet restart. - if(Params().NetworkIDString() == CBaseChainParams::TESTNET){ - for(int i = 46200; i <= nHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14; - } else { - // yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050. - for(int i = consensusParams.nSubsidyHalvingInterval; i <= nHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14; - } - - // 10% - return ((nSubsidy/100)*10)*consensusParams.nBudgetPaymentsCycleBlocks; -} - -void CGovernanceManager::NewBlock() -{ - TRY_LOCK(cs, fBudgetNewBlock); - if(!fBudgetNewBlock) return; - - if(!pCurrentBlockIndex) return; - - if (masternodeSync.RequestedMasternodeAssets <= MASTERNODE_SYNC_BUDGET) return; - - if (strBudgetMode == "suggest") { //suggest the budget we see - SubmitFinalBudget(); - } - - //this function should be called 1/6 blocks, allowing up to 100 votes per day on all proposals - if(pCurrentBlockIndex->nHeight % 6 != 0) return; - - // incremental sync with our peers - // if(masternodeSync.IsSynced()){ - // LogPrintf("CGovernanceManager::NewBlock - incremental sync started\n"); - // if(pCurrentBlockIndex->nHeight % 600 == rand() % 600) { - // ClearSeen(); - // ResetSync(); - // } - - // LOCK(cs_vNodes); - // BOOST_FOREACH(CNode* pnode, vNodes) - // if(pnode->nVersion >= MIN_BUDGET_PEER_PROTO_VERSION) - // Sync(pnode, uint256()); - - // MarkSynced(); - // } - - CheckAndRemove(); - - //remove invalid votes once in a while (we have to check the signatures and validity of every vote, somewhat CPU intensive) - - std::map::iterator it = askedForSourceProposalOrBudget.begin(); - while(it != askedForSourceProposalOrBudget.end()){ - if((*it).second > GetTime() - (60*60*24)){ - ++it; - } else { - askedForSourceProposalOrBudget.erase(it++); - } - } - - std::map::iterator it2 = mapGovernanceObjects.begin(); - while(it2 != mapGovernanceObjects.end()){ - (*it2).second.CleanAndRemove(false); - ++it2; - } - - std::map::iterator it3 = mapFinalizedBudgets.begin(); - while(it3 != mapFinalizedBudgets.end()){ - (*it3).second.CleanAndRemove(false); - ++it3; - } - - std::vector::iterator it4 = vecImmatureGovernanceNodes.begin(); - while(it4 != vecImmatureGovernanceNodes.end()) - { - std::string strError = ""; - int nConf = 0; - if(!IsBudgetCollateralValid((*it4).nFeeTXHash, (*it4).GetHash(), strError, (*it4).nTime, nConf)){ - ++it4; - continue; - } - - if(!(*it4).IsValid(pCurrentBlockIndex, strError)) { - LogPrintf("mprop (immature) - invalid budget proposal - %s\n", strError); - it4 = vecImmatureGovernanceNodes.erase(it4); - continue; - } - - CGovernanceNode budgetProposal((*it4)); - if(AddGovernanceObject(budgetProposal)) {(*it4).Relay();} - - LogPrintf("mprop (immature) - new budget - %s\n", (*it4).GetHash().ToString()); - it4 = vecImmatureGovernanceNodes.erase(it4); - } - - // std::vector::iterator it5 = vecImmatureFinalizedBudgets.begin(); - // while(it5 != vecImmatureFinalizedBudgets.end()) - // { - // std::string strError = ""; - // int nConf = 0; - // if(!IsBudgetCollateralValid((*it5).nFeeTXHash, (*it5).GetHash(), strError, (*it5).nTime, nConf)){ - // ++it5; - // continue; - // } - - // if(!(*it5).IsValid(pCurrentBlockIndex, strError)) { - // LogPrintf("fbs (immature) - invalid finalized budget - %s\n", strError); - // it5 = vecImmatureFinalizedBudgets.erase(it5); - // continue; - // } - - // LogPrintf("fbs (immature) - new finalized budget - %s\n", (*it5).GetHash().ToString()); - - // CFinalizedBudget finalizedBudget((*it5)); - // if(AddFinalizedBudget(finalizedBudget)) {(*it5).Relay();} - - // it5 = vecImmatureFinalizedBudgets.erase(it5); - // } - -} - -void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) -{ - // lite mode is not supported - if(fLiteMode) return; - if(!masternodeSync.IsBlockchainSynced()) return; - - LOCK(cs_budget); - - if (strCommand == NetMsgType::GOVERNANCE_VOTESYNC) { //Masternode vote sync - uint256 nProp; - vRecv >> nProp; - - if(Params().NetworkIDString() == CBaseChainParams::MAIN){ - if(nProp == uint256()) { - if(pfrom->HasFulfilledRequest(NetMsgType::GOVERNANCE_VOTESYNC)) { - LogPrintf("mnvs - peer already asked me for the list\n"); - Misbehaving(pfrom->GetId(), 20); - return; - } - pfrom->FulfilledRequest(NetMsgType::GOVERNANCE_VOTESYNC); - } - } - - Sync(pfrom, nProp); - LogPrintf("mnvs - Sent Masternode votes to %s\n", pfrom->addr.ToString()); - } - - if (strCommand == NetMsgType::GOVERNANCE_OBJECT) { //Governance Object : Proposal, Contract, Switch, Setting (Finalized Budgets are elsewhere) - - CGovernanceNodeBroadcast budgetProposalBroadcast; - vRecv >> budgetProposalBroadcast; - - if(mapSeenGovernanceObjects.count(budgetProposalBroadcast.GetHash())){ - masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash()); - return; - } - - std::string strError = ""; - int nConf = 0; - if(!IsBudgetCollateralValid(budgetProposalBroadcast.nFeeTXHash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf)){ - LogPrintf("Proposal FeeTX is not valid - %s - %s\n", budgetProposalBroadcast.nFeeTXHash.ToString(), strError); - if(nConf >= 1) vecImmatureGovernanceNodes.push_back(budgetProposalBroadcast); - return; - } - - mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast)); - - if(!budgetProposalBroadcast.IsValid(pCurrentBlockIndex, strError)) { - LogPrintf("mprop - invalid budget proposal - %s\n", strError); - return; - } - - CGovernanceNode budgetProposal(budgetProposalBroadcast); - if(AddGovernanceObject(budgetProposal)) {budgetProposalBroadcast.Relay();} - masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash()); - - LogPrintf("mprop - new budget - %s\n", budgetProposalBroadcast.GetHash().ToString()); - - //We might have active votes for this proposal that are valid now - CheckOrphanVotes(); - } - - if (strCommand == NetMsgType::GOVERNANCE_VOTE) { //Masternode Vote - CGovernanceVote vote; - vRecv >> vote; - vote.fValid = true; - - if(mapSeenGovernanceVotes.count(vote.GetHash())){ - masternodeSync.AddedBudgetItem(vote.GetHash()); - return; - } - - CMasternode* pmn = mnodeman.Find(vote.vin); - if(pmn == NULL) { - LogPrint("mnbudget", "mvote - unknown masternode - vin: %s\n", vote.vin.ToString()); - mnodeman.AskForMN(pfrom, vote.vin); - return; - } - - // setup the parent object for the vote - if(vote.GetGovernanceType() == FinalizedBudget) - { - CFinalizedBudget* obj = govman.FindFinalizedBudget(vote.nParentHash); - if(!obj) - { - LogPrint("mnbudget", "mvote - unknown finalized budget - hash: %s\n", vote.nParentHash.ToString()); - govman.AddOrphanGovernanceVote(vote, pfrom); - return; - } - vote.SetParent(obj); - } else { // Proposal, Contract, Setting or Switch - CGovernanceNode* obj = govman.FindGovernanceObject(vote.nParentHash); - if(!obj) - { - LogPrint("mnbudget", "mvote - unknown finalized budget - hash: %s\n", vote.nParentHash.ToString()); - govman.AddOrphanGovernanceVote(vote, pfrom); - return; - } - vote.SetParent(obj); - } - - mapSeenGovernanceVotes.insert(make_pair(vote.GetHash(), vote)); - - std::string strReason = ""; - if(!vote.IsValid(true, strReason)){ - if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20); - // it could just be a non-synced masternode - LogPrint("mnbudget", "mvote - signature invalid - %s\n", strReason); - mnodeman.AskForMN(pfrom, vote.vin); - return; - } - - std::string strError = ""; - if(UpdateGovernanceObjectVotes(vote, pfrom, strError)) { - vote.Relay(); - masternodeSync.AddedBudgetItem(vote.GetHash()); - LogPrint("mnbudget", "mvote - new budget vote - %s\n", vote.GetHash().ToString()); - } - - } - - // TODO 12.1 - // if (strCommand == NetMsgType::MNBUDGETFINAL) { //Finalized Budget Suggestion - // CFinalizedBudgetBroadcast finalizedBudgetBroadcast; - // vRecv >> finalizedBudgetBroadcast; - - // if(mapSeenFinalizedBudgets.count(finalizedBudgetBroadcast.GetHash())){ - // masternodeSync.AddedBudgetItem(finalizedBudgetBroadcast.GetHash()); - // return; - // } - - // std::string strError = ""; - // int nConf = 0; - // if(!IsBudgetCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError, finalizedBudgetBroadcast.nTime, nConf)){ - // LogPrintf("Finalized Budget FeeTX is not valid - %s - %s\n", finalizedBudgetBroadcast.nFeeTXHash.ToString(), strError); - - // if(nConf >= 1) vecImmatureFinalizedBudgets.push_back(finalizedBudgetBroadcast); - // return; - // } - - // mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast)); - - // if(!finalizedBudgetBroadcast.IsValid(pCurrentBlockIndex, strError)) { - // // This shouldn't be a debug message, it's important - // LogPrintf("fbs - invalid finalized budget - %s\n", strError); - // return; - // } - - // LogPrintf("fbs - new finalized budget - %s\n", finalizedBudgetBroadcast.GetHash().ToString()); - - // CFinalizedBudget finalizedBudget(finalizedBudgetBroadcast); - // if(AddFinalizedBudget(finalizedBudget)) {finalizedBudgetBroadcast.Relay();} - // masternodeSync.AddedBudgetItem(finalizedBudgetBroadcast.GetHash()); - - // //we might have active votes for this budget that are now valid - // CheckOrphanVotes(); - // } - - if (strCommand == NetMsgType::MNBUDGETFINALVOTE) { //Finalized Budget Vote - CGovernanceVote vote; - vRecv >> vote; - vote.fValid = true; - - if(mapSeenGovernanceVotes.count(vote.GetHash())){ - masternodeSync.AddedBudgetItem(vote.GetHash()); - return; - } - - CMasternode* pmn = mnodeman.Find(vote.vin); - if(pmn == NULL) { - LogPrint("mnbudget", "fbvote - unknown masternode - vin: %s\n", vote.vin.ToString()); - mnodeman.AskForMN(pfrom, vote.vin); - return; - } - - mapSeenGovernanceVotes.insert(make_pair(vote.GetHash(), vote)); - - std::string strReason = ""; - if(!vote.IsValid(true, strReason)){ - if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20); - - LogPrint("mnbudget", "fbvote - error: %s\n", strReason); - - //TODO: This needs to somehow only ask if the error was related to a missing masternode - // I would check for "unknown masternode" but the string includes the vin - - // it could just be a non-synced masternode - mnodeman.AskForMN(pfrom, vote.vin); - return; - } - - std::string strError = ""; - if(UpdateGovernanceObjectVotes(vote, pfrom, strError)) { - vote.Relay(); - masternodeSync.AddedBudgetItem(vote.GetHash()); - - LogPrintf("fbvote - new finalized budget vote - %s\n", vote.GetHash().ToString()); - } else { - LogPrintf("fbvote - rejected finalized budget vote - %s - %s\n", vote.GetHash().ToString(), strError); - } - } -} - -//mark that a full sync is needed -void CGovernanceManager::ResetSync() -{ - LOCK(cs); - - - std::map::iterator it1 = mapSeenGovernanceObjects.begin(); - while(it1 != mapSeenGovernanceObjects.end()){ - CGovernanceNode* pbudgetProposal = FindGovernanceObject((*it1).first); - if(pbudgetProposal && pbudgetProposal->fValid){ +// // if((*it).second.GetGovernanceType() == Setting) {it++; continue;} +// // if((*it).second.GetGovernanceType() == Proposal) nOffset += 0; +// // if((*it).second.GetGovernanceType() == Contract) nOffset += mnodeman.CountEnabled(); - //mark votes - std::map::iterator it2 = pbudgetProposal->mapVotes.begin(); - while(it2 != pbudgetProposal->mapVotes.end()){ - (*it2).second.fSynced = false; - ++it2; - } - } - ++it1; - } +// // vBudgetPorposalsSort.push_back(make_pair(&((*it).second), nOffset+((*it).second.GetYesCount()-(*it).second.GetNoCount()))); - std::map::iterator it3 = mapSeenFinalizedBudgets.begin(); - while(it3 != mapSeenFinalizedBudgets.end()){ - CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first); - if(pfinalizedBudget && pfinalizedBudget->fValid){ +// // ++it; +// // } - //send votes - std::map::iterator it4 = pfinalizedBudget->mapVotes.begin(); - while(it4 != pfinalizedBudget->mapVotes.end()){ - (*it4).second.fSynced = false; - ++it4; - } - } - ++it3; - } -} +// // std::sort(vBudgetPorposalsSort.begin(), vBudgetPorposalsSort.end(), sortProposalsByVotes()); -void CGovernanceManager::MarkSynced() -{ - LOCK(cs); +// // // ------- Grab The Budgets In Order - /* - Mark that we've sent all valid items - */ +// // CAmount nBudgetAllocated = 0; +// // if(!pCurrentBlockIndex) return vBudgetProposalsRet; - std::map::iterator it1 = mapSeenGovernanceObjects.begin(); - while(it1 != mapSeenGovernanceObjects.end()){ - CGovernanceNode* pbudgetProposal = FindGovernanceObject((*it1).first); - if(pbudgetProposal && pbudgetProposal->fValid){ +// // int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// // int nBlockEnd = nBlockStart + Params().GetConsensus().nBudgetPaymentsWindowBlocks; +// // CAmount nTotalBudget = GetTotalBudget(nBlockStart); + + +// // std::vector >::iterator it2 = vBudgetPorposalsSort.begin(); +// // while(it2 != vBudgetPorposalsSort.end()) +// // { +// // CGovernanceNode* pbudgetProposal = (*it2).first; + + +// // printf("-> Budget Name : %s\n", pbudgetProposal->strName.c_str()); +// // printf("------- nBlockStart : %d\n", pbudgetProposal->nBlockStart); +// // printf("------- nBlockEnd : %d\n", pbudgetProposal->nBlockEnd); +// // printf("------- nBlockStart2 : %d\n", nBlockStart); +// // printf("------- nBlockEnd2 : %d\n", nBlockEnd); + +// // printf("------- 1 : %d\n", pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart); +// // printf("------- 2 : %d\n", pbudgetProposal->nBlockEnd >= nBlockEnd); +// // printf("------- 3 : %d\n", pbudgetProposal->GetYesCount() - pbudgetProposal->GetNoCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10); +// // printf("------- 4 : %d\n", pbudgetProposal->IsEstablished()); + +// // //prop start/end should be inside this period +// // if(pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart && +// // pbudgetProposal->nBlockEnd >= nBlockEnd && +// // pbudgetProposal->GetYesCount() - pbudgetProposal->GetNoCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10 && +// // pbudgetProposal->IsEstablished()) +// // { +// // printf("------- In range \n"); + +// // if(pbudgetProposal->GetAmount() + nBudgetAllocated <= nTotalBudget) { +// // pbudgetProposal->SetAllotted(pbudgetProposal->GetAmount()); +// // nBudgetAllocated += pbudgetProposal->GetAmount(); +// // vBudgetProposalsRet.push_back(pbudgetProposal); +// // printf("------- YES \n"); +// // } else { +// // pbudgetProposal->SetAllotted(0); +// // } +// // } + +// // ++it2; +// // } + +// return vBudgetProposalsRet; +// } + +// // struct sortFinalizedBudgetsByVotes { +// // bool operator()(const std::pair &left, const std::pair &right) { +// // return left.second > right.second; +// // } +// // }; + +// std::vector CGovernanceManager::GetFinalizedBudgets() +// { +// LOCK(cs); + +// // TODO 12.1 + +// std::vector vFinalizedBudgetsRet; +// // std::vector > vFinalizedBudgetsSort; + +// // // ------- Grab The Budgets In Order + +// // std::map::iterator it = mapFinalizedBudgets.begin(); +// // while(it != mapFinalizedBudgets.end()) +// // { +// // CFinalizedBudget* pfinalizedBudget = &((*it).second); + +// // vFinalizedBudgetsSort.push_back(make_pair(pfinalizedBudget, pfinalizedBudget->GetVoteCount())); +// // ++it; +// // } +// // std::sort(vFinalizedBudgetsSort.begin(), vFinalizedBudgetsSort.end(), sortFinalizedBudgetsByVotes()); + +// // std::vector >::iterator it2 = vFinalizedBudgetsSort.begin(); +// // while(it2 != vFinalizedBudgetsSort.end()) +// // { +// // vFinalizedBudgetsRet.push_back((*it2).first); +// // ++it2; +// // } + +// return vFinalizedBudgetsRet; +// } + +// std::string CGovernanceManager::GetRequiredPaymentsString(int nBlockHeight) +// { +// LOCK(cs); + +// std::string ret = "unknown-budget"; + +// std::map::iterator it = mapFinalizedBudgets.begin(); +// while(it != mapFinalizedBudgets.end()) +// { +// CFinalizedBudget* pfinalizedBudget = &((*it).second); +// if(nBlockHeight >= pfinalizedBudget->GetBlockStart() && nBlockHeight <= pfinalizedBudget->GetBlockEnd()){ +// CTxBudgetPayment payment; +// if(pfinalizedBudget->GetBudgetPaymentByBlock(nBlockHeight, payment)){ +// if(ret == "unknown-budget"){ +// ret = payment.nProposalHash.ToString(); +// } else { +// ret += ","; +// ret += payment.nProposalHash.ToString(); +// } +// } else { +// LogPrintf("CGovernanceManager::GetRequiredPaymentsString - Couldn't find budget payment for block %d\n", nBlockHeight); +// } +// } + +// ++it; +// } + +// return ret; +// } + +// CAmount CGovernanceManager::GetTotalBudget(int nHeight) +// { +// if(!pCurrentBlockIndex) return 0; + +// //get min block value and calculate from that +// CAmount nSubsidy = 5 * COIN; + +// const Consensus::Params consensusParams = Params().GetConsensus(); + +// // TODO: Remove this to further unify logic among mainnet/testnet/whatevernet, +// // use single formula instead (the one that is for current mainnet). +// // Probably a good idea to use a significally lower consensusParams.nSubsidyHalvingInterval +// // for testnet (like 10 times for example) to see the effect of halving there faster. +// // Will require testnet restart. +// if(Params().NetworkIDString() == CBaseChainParams::TESTNET){ +// for(int i = 46200; i <= nHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14; +// } else { +// // yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050. +// for(int i = consensusParams.nSubsidyHalvingInterval; i <= nHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14; +// } + +// // 10% +// return ((nSubsidy/100)*10)*consensusParams.nBudgetPaymentsCycleBlocks; +// } + +// void CGovernanceManager::NewBlock() +// { +// TRY_LOCK(cs, fBudgetNewBlock); +// if(!fBudgetNewBlock) return; + +// if(!pCurrentBlockIndex) return; + +// if (masternodeSync.RequestedMasternodeAssets <= MASTERNODE_SYNC_BUDGET) return; + +// if (strBudgetMode == "suggest") { //suggest the budget we see +// SubmitFinalBudget(); +// } + +// //this function should be called 1/6 blocks, allowing up to 100 votes per day on all proposals +// if(pCurrentBlockIndex->nHeight % 6 != 0) return; + +// // incremental sync with our peers +// // if(masternodeSync.IsSynced()){ +// // LogPrintf("CGovernanceManager::NewBlock - incremental sync started\n"); +// // if(pCurrentBlockIndex->nHeight % 600 == rand() % 600) { +// // ClearSeen(); +// // ResetSync(); +// // } + +// // LOCK(cs_vNodes); +// // BOOST_FOREACH(CNode* pnode, vNodes) +// // if(pnode->nVersion >= MIN_BUDGET_PEER_PROTO_VERSION) +// // Sync(pnode, uint256()); + +// // MarkSynced(); +// // } + +// CheckAndRemove(); + +// //remove invalid votes once in a while (we have to check the signatures and validity of every vote, somewhat CPU intensive) + +// std::map::iterator it = askedForSourceProposalOrBudget.begin(); +// while(it != askedForSourceProposalOrBudget.end()){ +// if((*it).second > GetTime() - (60*60*24)){ +// ++it; +// } else { +// askedForSourceProposalOrBudget.erase(it++); +// } +// } + +// std::map::iterator it2 = mapGovernanceObjects.begin(); +// while(it2 != mapGovernanceObjects.end()){ +// (*it2).second.CleanAndRemove(false); +// ++it2; +// } + +// std::map::iterator it3 = mapFinalizedBudgets.begin(); +// while(it3 != mapFinalizedBudgets.end()){ +// (*it3).second.CleanAndRemove(false); +// ++it3; +// } + +// std::vector::iterator it4 = vecImmatureGovernanceNodes.begin(); +// while(it4 != vecImmatureGovernanceNodes.end()) +// { +// std::string strError = ""; +// int nConf = 0; +// if(!IsBudgetCollateralValid((*it4).nFeeTXHash, (*it4).GetHash(), strError, (*it4).nTime, nConf)){ +// ++it4; +// continue; +// } + +// if(!(*it4).IsValid(pCurrentBlockIndex, strError)) { +// LogPrintf("mprop (immature) - invalid budget proposal - %s\n", strError); +// it4 = vecImmatureGovernanceNodes.erase(it4); +// continue; +// } + +// CGovernanceNode budgetProposal((*it4)); +// if(AddGovernanceObject(budgetProposal)) {(*it4).Relay();} + +// LogPrintf("mprop (immature) - new budget - %s\n", (*it4).GetHash().ToString()); +// it4 = vecImmatureGovernanceNodes.erase(it4); +// } + +// // std::vector::iterator it5 = vecImmatureFinalizedBudgets.begin(); +// // while(it5 != vecImmatureFinalizedBudgets.end()) +// // { +// // std::string strError = ""; +// // int nConf = 0; +// // if(!IsBudgetCollateralValid((*it5).nFeeTXHash, (*it5).GetHash(), strError, (*it5).nTime, nConf)){ +// // ++it5; +// // continue; +// // } + +// // if(!(*it5).IsValid(pCurrentBlockIndex, strError)) { +// // LogPrintf("fbs (immature) - invalid finalized budget - %s\n", strError); +// // it5 = vecImmatureFinalizedBudgets.erase(it5); +// // continue; +// // } + +// // LogPrintf("fbs (immature) - new finalized budget - %s\n", (*it5).GetHash().ToString()); + +// // CFinalizedBudget finalizedBudget((*it5)); +// // if(AddFinalizedBudget(finalizedBudget)) {(*it5).Relay();} + +// // it5 = vecImmatureFinalizedBudgets.erase(it5); +// // } + +// } + +// void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) +// { +// // lite mode is not supported +// if(fLiteMode) return; +// if(!masternodeSync.IsBlockchainSynced()) return; + +// LOCK(cs_budget); + +// if (strCommand == NetMsgType::GOVERNANCE_VOTESYNC) { //Masternode vote sync +// uint256 nProp; +// vRecv >> nProp; + +// if(Params().NetworkIDString() == CBaseChainParams::MAIN){ +// if(nProp == uint256()) { +// if(pfrom->HasFulfilledRequest(NetMsgType::GOVERNANCE_VOTESYNC)) { +// LogPrintf("mnvs - peer already asked me for the list\n"); +// Misbehaving(pfrom->GetId(), 20); +// return; +// } +// pfrom->FulfilledRequest(NetMsgType::GOVERNANCE_VOTESYNC); +// } +// } + +// Sync(pfrom, nProp); +// LogPrintf("mnvs - Sent Masternode votes to %s\n", pfrom->addr.ToString()); +// } + +// if (strCommand == NetMsgType::GOVERNANCE_OBJECT) { //Governance Object : Proposal, Contract, Switch, Setting (Finalized Budgets are elsewhere) + +// CGovernanceNodeBroadcast budgetProposalBroadcast; +// vRecv >> budgetProposalBroadcast; + +// if(mapSeenGovernanceObjects.count(budgetProposalBroadcast.GetHash())){ +// masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash()); +// return; +// } + +// std::string strError = ""; +// int nConf = 0; +// if(!IsBudgetCollateralValid(budgetProposalBroadcast.nFeeTXHash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf)){ +// LogPrintf("Proposal FeeTX is not valid - %s - %s\n", budgetProposalBroadcast.nFeeTXHash.ToString(), strError); +// if(nConf >= 1) vecImmatureGovernanceNodes.push_back(budgetProposalBroadcast); +// return; +// } + +// mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast)); + +// if(!budgetProposalBroadcast.IsValid(pCurrentBlockIndex, strError)) { +// LogPrintf("mprop - invalid budget proposal - %s\n", strError); +// return; +// } + +// CGovernanceNode budgetProposal(budgetProposalBroadcast); +// if(AddGovernanceObject(budgetProposal)) {budgetProposalBroadcast.Relay();} +// masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash()); + +// LogPrintf("mprop - new budget - %s\n", budgetProposalBroadcast.GetHash().ToString()); + +// //We might have active votes for this proposal that are valid now +// CheckOrphanVotes(); +// } + +// if (strCommand == NetMsgType::GOVERNANCE_VOTE) { //Masternode Vote +// CGovernanceVote vote; +// vRecv >> vote; +// vote.fValid = true; + +// if(mapSeenGovernanceVotes.count(vote.GetHash())){ +// masternodeSync.AddedBudgetItem(vote.GetHash()); +// return; +// } + +// CMasternode* pmn = mnodeman.Find(vote.vin); +// if(pmn == NULL) { +// LogPrint("mnbudget", "mvote - unknown masternode - vin: %s\n", vote.vin.ToString()); +// mnodeman.AskForMN(pfrom, vote.vin); +// return; +// } + +// // setup the parent object for the vote +// if(vote.GetGovernanceType() == FinalizedBudget) +// { +// CFinalizedBudget* obj = govman.FindFinalizedBudget(vote.nParentHash); +// if(!obj) +// { +// LogPrint("mnbudget", "mvote - unknown finalized budget - hash: %s\n", vote.nParentHash.ToString()); +// govman.AddOrphanGovernanceVote(vote, pfrom); +// return; +// } +// vote.SetParent(obj); +// } else { // Proposal, Contract, Setting or Switch +// CGovernanceNode* obj = govman.FindGovernanceObject(vote.nParentHash); +// if(!obj) +// { +// LogPrint("mnbudget", "mvote - unknown finalized budget - hash: %s\n", vote.nParentHash.ToString()); +// govman.AddOrphanGovernanceVote(vote, pfrom); +// return; +// } +// vote.SetParent(obj); +// } + +// mapSeenGovernanceVotes.insert(make_pair(vote.GetHash(), vote)); + +// std::string strReason = ""; +// if(!vote.IsValid(true, strReason)){ +// if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20); +// // it could just be a non-synced masternode +// LogPrint("mnbudget", "mvote - signature invalid - %s\n", strReason); +// mnodeman.AskForMN(pfrom, vote.vin); +// return; +// } + +// std::string strError = ""; +// if(UpdateGovernanceObjectVotes(vote, pfrom, strError)) { +// vote.Relay(); +// masternodeSync.AddedBudgetItem(vote.GetHash()); +// LogPrint("mnbudget", "mvote - new budget vote - %s\n", vote.GetHash().ToString()); +// } + +// } + +// // TODO 12.1 +// // if (strCommand == NetMsgType::MNBUDGETFINAL) { //Finalized Budget Suggestion +// // CFinalizedBudgetBroadcast finalizedBudgetBroadcast; +// // vRecv >> finalizedBudgetBroadcast; + +// // if(mapSeenFinalizedBudgets.count(finalizedBudgetBroadcast.GetHash())){ +// // masternodeSync.AddedBudgetItem(finalizedBudgetBroadcast.GetHash()); +// // return; +// // } + +// // std::string strError = ""; +// // int nConf = 0; +// // if(!IsBudgetCollateralValid(finalizedBudgetBroadcast.nFeeTXHash, finalizedBudgetBroadcast.GetHash(), strError, finalizedBudgetBroadcast.nTime, nConf)){ +// // LogPrintf("Finalized Budget FeeTX is not valid - %s - %s\n", finalizedBudgetBroadcast.nFeeTXHash.ToString(), strError); + +// // if(nConf >= 1) vecImmatureFinalizedBudgets.push_back(finalizedBudgetBroadcast); +// // return; +// // } + +// // mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast)); + +// // if(!finalizedBudgetBroadcast.IsValid(pCurrentBlockIndex, strError)) { +// // // This shouldn't be a debug message, it's important +// // LogPrintf("fbs - invalid finalized budget - %s\n", strError); +// // return; +// // } + +// // LogPrintf("fbs - new finalized budget - %s\n", finalizedBudgetBroadcast.GetHash().ToString()); + +// // CFinalizedBudget finalizedBudget(finalizedBudgetBroadcast); +// // if(AddFinalizedBudget(finalizedBudget)) {finalizedBudgetBroadcast.Relay();} +// // masternodeSync.AddedBudgetItem(finalizedBudgetBroadcast.GetHash()); + +// // //we might have active votes for this budget that are now valid +// // CheckOrphanVotes(); +// // } + +// if (strCommand == NetMsgType::MNBUDGETFINALVOTE) { //Finalized Budget Vote +// CGovernanceVote vote; +// vRecv >> vote; +// vote.fValid = true; + +// if(mapSeenGovernanceVotes.count(vote.GetHash())){ +// masternodeSync.AddedBudgetItem(vote.GetHash()); +// return; +// } + +// CMasternode* pmn = mnodeman.Find(vote.vin); +// if(pmn == NULL) { +// LogPrint("mnbudget", "fbvote - unknown masternode - vin: %s\n", vote.vin.ToString()); +// mnodeman.AskForMN(pfrom, vote.vin); +// return; +// } + +// mapSeenGovernanceVotes.insert(make_pair(vote.GetHash(), vote)); + +// std::string strReason = ""; +// if(!vote.IsValid(true, strReason)){ +// if(masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20); + +// LogPrint("mnbudget", "fbvote - error: %s\n", strReason); + +// //TODO: This needs to somehow only ask if the error was related to a missing masternode +// // I would check for "unknown masternode" but the string includes the vin + +// // it could just be a non-synced masternode +// mnodeman.AskForMN(pfrom, vote.vin); +// return; +// } + +// std::string strError = ""; +// if(UpdateGovernanceObjectVotes(vote, pfrom, strError)) { +// vote.Relay(); +// masternodeSync.AddedBudgetItem(vote.GetHash()); + +// LogPrintf("fbvote - new finalized budget vote - %s\n", vote.GetHash().ToString()); +// } else { +// LogPrintf("fbvote - rejected finalized budget vote - %s - %s\n", vote.GetHash().ToString(), strError); +// } +// } +// } + +// //mark that a full sync is needed +// void CGovernanceManager::ResetSync() +// { +// LOCK(cs); + + +// std::map::iterator it1 = mapSeenGovernanceObjects.begin(); +// while(it1 != mapSeenGovernanceObjects.end()){ +// CGovernanceNode* pbudgetProposal = FindGovernanceObject((*it1).first); +// if(pbudgetProposal && pbudgetProposal->fValid){ - //mark votes - std::map::iterator it2 = pbudgetProposal->mapVotes.begin(); - while(it2 != pbudgetProposal->mapVotes.end()){ - if((*it2).second.fValid) - (*it2).second.fSynced = true; - ++it2; - } - } - ++it1; - } +// //mark votes +// std::map::iterator it2 = pbudgetProposal->mapVotes.begin(); +// while(it2 != pbudgetProposal->mapVotes.end()){ +// (*it2).second.fSynced = false; +// ++it2; +// } +// } +// ++it1; +// } - std::map::iterator it3 = mapSeenFinalizedBudgets.begin(); - while(it3 != mapSeenFinalizedBudgets.end()){ - CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first); - if(pfinalizedBudget && pfinalizedBudget->fValid){ +// std::map::iterator it3 = mapSeenFinalizedBudgets.begin(); +// while(it3 != mapSeenFinalizedBudgets.end()){ +// CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first); +// if(pfinalizedBudget && pfinalizedBudget->fValid){ - //mark votes - std::map::iterator it4 = pfinalizedBudget->mapVotes.begin(); - while(it4 != pfinalizedBudget->mapVotes.end()){ - if((*it4).second.fValid) - (*it4).second.fSynced = true; - ++it4; - } - } - ++it3; - } +// //send votes +// std::map::iterator it4 = pfinalizedBudget->mapVotes.begin(); +// while(it4 != pfinalizedBudget->mapVotes.end()){ +// (*it4).second.fSynced = false; +// ++it4; +// } +// } +// ++it3; +// } +// } -} +// void CGovernanceManager::MarkSynced() +// { +// LOCK(cs); +// /* +// Mark that we've sent all valid items +// */ -void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial) -{ - LOCK(cs); - - /* - Sync with a client on the network - - -- - - This code checks each of the hash maps for all known budget proposals and finalized budget proposals, then checks them against the - budget object to see if they're OK. If all checks pass, we'll send it to the peer. - - */ - - int nInvCount = 0; - - - // todo - why does this code not always sync properly? - // the next place this data arrives at is main.cpp:4024 and main.cpp:4030 - std::map::iterator it1 = mapSeenGovernanceObjects.begin(); - while(it1 != mapSeenGovernanceObjects.end()){ - CGovernanceNode* pbudgetProposal = FindGovernanceObject((*it1).first); - if(pbudgetProposal && pbudgetProposal->fValid && (nProp == uint256() || (*it1).first == nProp)){ - // Push the inventory budget proposal message over to the other client - pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT, (*it1).second.GetHash())); - nInvCount++; +// std::map::iterator it1 = mapSeenGovernanceObjects.begin(); +// while(it1 != mapSeenGovernanceObjects.end()){ +// CGovernanceNode* pbudgetProposal = FindGovernanceObject((*it1).first); +// if(pbudgetProposal && pbudgetProposal->fValid){ - //send votes, at the same time. We should collect votes and store them if we don't have the proposal yet on the other side - std::map::iterator it2 = pbudgetProposal->mapVotes.begin(); - while(it2 != pbudgetProposal->mapVotes.end()){ - if((*it2).second.fValid){ - if((fPartial && !(*it2).second.fSynced) || !fPartial) { - pfrom->PushInventory(CInv(MSG_GOVERNANCE_VOTE, (*it2).second.GetHash())); - nInvCount++; - } - } - ++it2; - } - } - ++it1; - } +// //mark votes +// std::map::iterator it2 = pbudgetProposal->mapVotes.begin(); +// while(it2 != pbudgetProposal->mapVotes.end()){ +// if((*it2).second.fValid) +// (*it2).second.fSynced = true; +// ++it2; +// } +// } +// ++it1; +// } - pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_PROP, nInvCount); +// std::map::iterator it3 = mapSeenFinalizedBudgets.begin(); +// while(it3 != mapSeenFinalizedBudgets.end()){ +// CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first); +// if(pfinalizedBudget && pfinalizedBudget->fValid){ - LogPrintf("CGovernanceManager::Sync - sent %d items\n", nInvCount); +// //mark votes +// std::map::iterator it4 = pfinalizedBudget->mapVotes.begin(); +// while(it4 != pfinalizedBudget->mapVotes.end()){ +// if((*it4).second.fValid) +// (*it4).second.fSynced = true; +// ++it4; +// } +// } +// ++it3; +// } - nInvCount = 0; +// } - // finalized budget -- this code has no issues as far as we can tell - std::map::iterator it3 = mapSeenFinalizedBudgets.begin(); - while(it3 != mapSeenFinalizedBudgets.end()){ - CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first); - if(pfinalizedBudget && pfinalizedBudget->fValid && (nProp == uint256() || (*it3).first == nProp)){ - pfrom->PushInventory(CInv(MSG_GOVERNANCE_FINALIZED_BUDGET, (*it3).second.GetHash())); - nInvCount++; - //send votes - std::map::iterator it4 = pfinalizedBudget->mapVotes.begin(); - while(it4 != pfinalizedBudget->mapVotes.end()){ - if((*it4).second.fValid) { - if((fPartial && !(*it4).second.fSynced) || !fPartial) { - pfrom->PushInventory(CInv(MSG_GOVERNANCE_VOTE, (*it4).second.GetHash())); - nInvCount++; - } - } - ++it4; - } - } - ++it3; - } +// void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial) +// { +// LOCK(cs); - pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_FIN, nInvCount); - LogPrintf("CGovernanceManager::Sync - sent %d items\n", nInvCount); +// /* +// Sync with a client on the network -} +// -- -// we will ask for this governance object and hold the vote -bool CGovernanceManager::AddOrphanGovernanceVote(CGovernanceVote& vote, CNode* pfrom) -{ - LogPrintf("CGovernanceManager::UpdateFinalizedBudget - Unknown Finalized Proposal %s, asking for source budget\n", vote.nParentHash.ToString()); - mapOrphanGovernanceVotes[vote.nParentHash] = vote; +// This code checks each of the hash maps for all known budget proposals and finalized budget proposals, then checks them against the +// budget object to see if they're OK. If all checks pass, we'll send it to the peer. - if(!askedForSourceProposalOrBudget.count(vote.nParentHash)){ - pfrom->PushMessage(NetMsgType::GOVERNANCE_VOTESYNC, vote.nParentHash); - askedForSourceProposalOrBudget[vote.nParentHash] = GetTime(); - return true; - } +// */ - return false; -} +// int nInvCount = 0; -bool CGovernanceManager::UpdateGovernanceObjectVotes(CGovernanceVote& vote, CNode* pfrom, std::string& strError) -{ - LOCK(cs); - // is this a proposal? - if(vote.nGovernanceType == FinalizedBudget) - { - if(!mapFinalizedBudgets.count(vote.nParentHash)){ - if(pfrom){ - // only ask for missing items after our syncing process is complete -- - // otherwise we'll think a full sync succeeded when they return a result - if(!masternodeSync.IsSynced()) return false; +// // todo - why does this code not always sync properly? +// // the next place this data arrives at is main.cpp:4024 and main.cpp:4030 +// std::map::iterator it1 = mapSeenGovernanceObjects.begin(); +// while(it1 != mapSeenGovernanceObjects.end()){ +// CGovernanceNode* pbudgetProposal = FindGovernanceObject((*it1).first); +// if(pbudgetProposal && pbudgetProposal->fValid && (nProp == uint256() || (*it1).first == nProp)){ +// // Push the inventory budget proposal message over to the other client +// pfrom->PushInventory(CInv(MSG_GOVERNANCE_OBJECT, (*it1).second.GetHash())); +// nInvCount++; + +// //send votes, at the same time. We should collect votes and store them if we don't have the proposal yet on the other side +// std::map::iterator it2 = pbudgetProposal->mapVotes.begin(); +// while(it2 != pbudgetProposal->mapVotes.end()){ +// if((*it2).second.fValid){ +// if((fPartial && !(*it2).second.fSynced) || !fPartial) { +// pfrom->PushInventory(CInv(MSG_GOVERNANCE_VOTE, (*it2).second.GetHash())); +// nInvCount++; +// } +// } +// ++it2; +// } +// } +// ++it1; +// } - AddOrphanGovernanceVote(vote, pfrom); - } +// pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_PROP, nInvCount); - strError = "Finalized Budget not found!"; - return false; - } else { - CFinalizedBudget* obj = &mapFinalizedBudgets[vote.nParentHash]; - vote.SetParent(obj); - } +// LogPrintf("CGovernanceManager::Sync - sent %d items\n", nInvCount); - return mapFinalizedBudgets[vote.nParentHash].AddOrUpdateVote(vote, strError); - } +// nInvCount = 0; - // is this a proposal? - if(vote.nGovernanceType == Proposal) - { - if(!mapGovernanceObjects.count(vote.nParentHash)){ - if(pfrom){ - // only ask for missing items after our syncing process is complete -- - // otherwise we'll think a full sync succeeded when they return a result - if(!masternodeSync.IsSynced()) return false; +// // finalized budget -- this code has no issues as far as we can tell +// std::map::iterator it3 = mapSeenFinalizedBudgets.begin(); +// while(it3 != mapSeenFinalizedBudgets.end()){ +// CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first); +// if(pfinalizedBudget && pfinalizedBudget->fValid && (nProp == uint256() || (*it3).first == nProp)){ +// pfrom->PushInventory(CInv(MSG_GOVERNANCE_FINALIZED_BUDGET, (*it3).second.GetHash())); +// nInvCount++; - LogPrintf("CGovernanceManager::UpdateProposal - Unknown proposal %d, asking for source proposal\n", vote.nParentHash.ToString()); - mapOrphanGovernanceVotes[vote.nParentHash] = vote; +// //send votes +// std::map::iterator it4 = pfinalizedBudget->mapVotes.begin(); +// while(it4 != pfinalizedBudget->mapVotes.end()){ +// if((*it4).second.fValid) { +// if((fPartial && !(*it4).second.fSynced) || !fPartial) { +// pfrom->PushInventory(CInv(MSG_GOVERNANCE_VOTE, (*it4).second.GetHash())); +// nInvCount++; +// } +// } +// ++it4; +// } +// } +// ++it3; +// } - if(!askedForSourceProposalOrBudget.count(vote.nParentHash)){ - pfrom->PushMessage(NetMsgType::GOVERNANCE_VOTESYNC, vote.nParentHash); - askedForSourceProposalOrBudget[vote.nParentHash] = GetTime(); - } - } +// pfrom->PushMessage(NetMsgType::SYNCSTATUSCOUNT, MASTERNODE_SYNC_BUDGET_FIN, nInvCount); +// LogPrintf("CGovernanceManager::Sync - sent %d items\n", nInvCount); - strError = "Proposal not found!"; - return false; - } else { - CGovernanceNode* obj = &mapGovernanceObjects[vote.nParentHash]; - vote.SetParent(obj); - } +// } - return mapGovernanceObjects[vote.nParentHash].AddOrUpdateVote(vote, strError); - } +// // we will ask for this governance object and hold the vote +// bool CGovernanceManager::AddOrphanGovernanceVote(CGovernanceVote& vote, CNode* pfrom) +// { +// LogPrintf("CGovernanceManager::UpdateFinalizedBudget - Unknown Finalized Proposal %s, asking for source budget\n", vote.nParentHash.ToString()); +// mapOrphanGovernanceVotes[vote.nParentHash] = vote; - return false; -} +// if(!askedForSourceProposalOrBudget.count(vote.nParentHash)){ +// pfrom->PushMessage(NetMsgType::GOVERNANCE_VOTESYNC, vote.nParentHash); +// askedForSourceProposalOrBudget[vote.nParentHash] = GetTime(); +// return true; +// } -CFinalizedBudget::CFinalizedBudget() -{ - strBudgetName = ""; - nBlockStart = 0; - vecBudgetPayments.clear(); - mapVotes.clear(); - nFeeTXHash = uint256(); - nTime = 0; - fValid = true; - fAutoChecked = false; -} +// return false; +// } -CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other) -{ - strBudgetName = other.strBudgetName; - nBlockStart = other.nBlockStart; - vecBudgetPayments = other.vecBudgetPayments; - mapVotes = other.mapVotes; - nFeeTXHash = other.nFeeTXHash; - nTime = other.nTime; - fValid = true; - fAutoChecked = false; -} +// bool CGovernanceManager::UpdateGovernanceObjectVotes(CGovernanceVote& vote, CNode* pfrom, std::string& strError) +// { +// LOCK(cs); -// bool CFinalizedBudget::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError) +// // is this a proposal? +// if(vote.nGovernanceType == FinalizedBudget) +// { +// if(!mapFinalizedBudgets.count(vote.nParentHash)){ +// if(pfrom){ +// // only ask for missing items after our syncing process is complete -- +// // otherwise we'll think a full sync succeeded when they return a result +// if(!masternodeSync.IsSynced()) return false; + +// AddOrphanGovernanceVote(vote, pfrom); +// } + +// strError = "Finalized Budget not found!"; +// return false; +// } else { +// CFinalizedBudget* obj = &mapFinalizedBudgets[vote.nParentHash]; +// vote.SetParent(obj); +// } + +// return mapFinalizedBudgets[vote.nParentHash].AddOrUpdateVote(vote, strError); +// } + +// // is this a proposal? +// if(vote.nGovernanceType == Proposal) +// { +// if(!mapGovernanceObjects.count(vote.nParentHash)){ +// if(pfrom){ +// // only ask for missing items after our syncing process is complete -- +// // otherwise we'll think a full sync succeeded when they return a result +// if(!masternodeSync.IsSynced()) return false; + +// LogPrintf("CGovernanceManager::UpdateProposal - Unknown proposal %d, asking for source proposal\n", vote.nParentHash.ToString()); +// mapOrphanGovernanceVotes[vote.nParentHash] = vote; + +// if(!askedForSourceProposalOrBudget.count(vote.nParentHash)){ +// pfrom->PushMessage(NetMsgType::GOVERNANCE_VOTESYNC, vote.nParentHash); +// askedForSourceProposalOrBudget[vote.nParentHash] = GetTime(); +// } +// } + +// strError = "Proposal not found!"; +// return false; +// } else { +// CGovernanceNode* obj = &mapGovernanceObjects[vote.nParentHash]; +// vote.SetParent(obj); +// } + +// return mapGovernanceObjects[vote.nParentHash].AddOrUpdateVote(vote, strError); +// } + +// return false; +// } + +// CFinalizedBudget::CFinalizedBudget() +// { +// strBudgetName = ""; +// nBlockStart = 0; +// vecBudgetPayments.clear(); +// mapVotes.clear(); +// nFeeTXHash = uint256(); +// nTime = 0; +// fValid = true; +// fAutoChecked = false; +// } + +// CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other) +// { +// strBudgetName = other.strBudgetName; +// nBlockStart = other.nBlockStart; +// vecBudgetPayments = other.vecBudgetPayments; +// mapVotes = other.mapVotes; +// nFeeTXHash = other.nFeeTXHash; +// nTime = other.nTime; +// fValid = true; +// fAutoChecked = false; +// } + +// // bool CFinalizedBudget::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError) +// // { +// // LOCK(cs); + +// // uint256 hash = vote.vin.prevout.GetHash(); +// // if(mapVotes.count(hash)){ +// // if(mapVotes[hash].nTime > vote.nTime){ +// // strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString()); +// // LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); +// // return false; +// // } +// // if(vote.nTime - mapVotes[hash].nTime < BUDGET_VOTE_UPDATE_MIN){ +// // strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash].nTime); +// // LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); +// // return false; +// // } +// // } + +// // mapVotes[hash] = vote; +// // return true; +// // } + +// //evaluate if we should vote for this. Masternode only +// void CFinalizedBudget::AutoCheckSuperBlockVoting() +// { +// LOCK(cs); + +// CBlockIndex* pindexPrev = chainActive.Tip(); +// if(!pindexPrev) return; + +// LogPrintf("CFinalizedBudget::AutoCheck - %lli - %d\n", pindexPrev->nHeight, fAutoChecked); + +// if(!fMasterNode || fAutoChecked) return; + +// //do this 1 in 4 blocks -- spread out the voting activity on mainnet +// // -- this function is only called every sixth block, so this is really 1 in 24 blocks +// if(Params().NetworkIDString() == CBaseChainParams::MAIN && rand() % 4 != 0) { +// LogPrintf("CFinalizedBudget::AutoCheck - waiting\n"); +// return; +// } + +// fAutoChecked = true; //we only need to check this once + + +// if(strBudgetMode == "auto") //only vote for exact matches +// { +// std::vector vBudgetProposals = govman.GetBudget(); + + +// for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ +// LogPrintf("CFinalizedBudget::AutoCheck - nProp %d %s\n", i, vecBudgetPayments[i].nProposalHash.ToString()); +// LogPrintf("CFinalizedBudget::AutoCheck - Payee %d %s\n", i, ScriptToAsmStr(vecBudgetPayments[i].payee)); +// LogPrintf("CFinalizedBudget::AutoCheck - nAmount %d %lli\n", i, vecBudgetPayments[i].nAmount); +// } + +// for(unsigned int i = 0; i < vBudgetProposals.size(); i++){ +// LogPrintf("CFinalizedBudget::AutoCheck - nProp %d %s\n", i, vBudgetProposals[i]->GetHash().ToString()); +// LogPrintf("CFinalizedBudget::AutoCheck - Payee %d %s\n", i, ScriptToAsmStr(vBudgetProposals[i]->GetPayee())); +// LogPrintf("CFinalizedBudget::AutoCheck - nAmount %d %lli\n", i, vBudgetProposals[i]->GetAmount()); +// } + +// if(vBudgetProposals.size() == 0) { +// LogPrintf("CFinalizedBudget::AutoCheck - Can't get Budget, aborting\n"); +// return; +// } + +// if(vBudgetProposals.size() != vecBudgetPayments.size()) { +// LogPrintf("CFinalizedBudget::AutoCheck - Budget length doesn't match\n"); +// return; +// } + + +// for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ +// if(i > vBudgetProposals.size() - 1) { +// LogPrintf("CFinalizedBudget::AutoCheck - Vector size mismatch, aborting\n"); +// return; +// } + +// if(vecBudgetPayments[i].nProposalHash != vBudgetProposals[i]->GetHash()){ +// LogPrintf("CFinalizedBudget::AutoCheck - item #%d doesn't match %s %s\n", i, vecBudgetPayments[i].nProposalHash.ToString(), vBudgetProposals[i]->GetHash().ToString()); +// return; +// } + +// // if(vecBudgetPayments[i].payee != vBudgetProposals[i]->GetPayee()){ -- triggered with false positive +// if(vecBudgetPayments[i].payee != vBudgetProposals[i]->GetPayee()){ +// LogPrintf("CFinalizedBudget::AutoCheck - item #%d payee doesn't match %s %s\n", i, ScriptToAsmStr(vecBudgetPayments[i].payee), ScriptToAsmStr(vBudgetProposals[i]->GetPayee())); +// return; +// } + +// if(vecBudgetPayments[i].nAmount != vBudgetProposals[i]->GetAmount()){ +// LogPrintf("CFinalizedBudget::AutoCheck - item #%d payee doesn't match %lli %lli\n", i, vecBudgetPayments[i].nAmount, vBudgetProposals[i]->GetAmount()); +// return; +// } +// } + +// LogPrintf("CFinalizedBudget::AutoCheck - Finalized Budget Matches! Submitting Vote.\n"); +// SubmitVote(); + +// } +// } +// // If masternode voted for a proposal, but is now invalid -- remove the vote +// void CFinalizedBudget::CleanAndRemove(bool fSignatureCheck) +// { +// std::map::iterator it = mapVotes.begin(); + +// while(it != mapVotes.end()) { +// std::string strReason = ""; +// (*it).second.fValid = (*it).second.IsValid(fSignatureCheck, strReason); +// ++it; +// } +// } + + +// CAmount CFinalizedBudget::GetTotalPayout() +// { +// CAmount ret = 0; + +// for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ +// ret += vecBudgetPayments[i].nAmount; +// } + +// return ret; +// } + +// std::string CFinalizedBudget::GetProposals() +// { +// LOCK(cs); +// std::string ret = ""; + +// BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){ +// CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(budgetPayment.nProposalHash); + +// std::string token = budgetPayment.nProposalHash.ToString(); + +// if(pbudgetProposal) token = pbudgetProposal->GetName(); +// if(ret == "") {ret = token;} +// else {ret += "," + token;} +// } +// return ret; +// } + +// std::string CFinalizedBudget::GetStatus() +// { +// std::string retBadHashes = ""; +// std::string retBadPayeeOrAmount = ""; + +// for(int nBlockHeight = GetBlockStart(); nBlockHeight <= GetBlockEnd(); nBlockHeight++) +// { +// CTxBudgetPayment budgetPayment; +// if(!GetBudgetPaymentByBlock(nBlockHeight, budgetPayment)){ +// LogPrintf("CFinalizedBudget::GetStatus - Couldn't find budget payment for block %lld\n", nBlockHeight); +// continue; +// } + +// CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(budgetPayment.nProposalHash); +// if(!pbudgetProposal){ +// if(retBadHashes == ""){ +// retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString(); +// } else { +// retBadHashes += "," + budgetPayment.nProposalHash.ToString(); +// } +// } else { +// if(pbudgetProposal->GetPayee() != budgetPayment.payee || pbudgetProposal->GetAmount() != budgetPayment.nAmount) +// { +// if(retBadPayeeOrAmount == ""){ +// retBadPayeeOrAmount = "Budget payee/nAmount doesn't match our proposal! " + budgetPayment.nProposalHash.ToString(); +// } else { +// retBadPayeeOrAmount += "," + budgetPayment.nProposalHash.ToString(); +// } +// } +// } +// } + +// if(retBadHashes == "" && retBadPayeeOrAmount == "") return "OK"; + +// return retBadHashes + retBadPayeeOrAmount; +// } + +// bool CFinalizedBudget::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral) +// { +// //must be the correct block for payment to happen (once a month) +// if(nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks != 0) {strError = "Invalid BlockStart"; return false;} +// if(GetBlockEnd() - nBlockStart > Params().GetConsensus().nBudgetPaymentsWindowBlocks) {strError = "Invalid BlockEnd"; return false;} +// if((int)vecBudgetPayments.size() > Params().GetConsensus().nBudgetPaymentsWindowBlocks) {strError = "Invalid budget payments count (too many)"; return false;} +// if(strBudgetName == "") {strError = "Invalid Budget Name"; return false;} +// if(nBlockStart == 0) {strError = "Invalid BlockStart == 0"; return false;} +// if(nFeeTXHash == uint256()) {strError = "Invalid FeeTx == 0"; return false;} + +// //can only pay out 10% of the possible coins (min value of coins) +// if(GetTotalPayout() > govman.GetTotalBudget(nBlockStart)) {strError = "Invalid Payout (more than max)"; return false;} + +// std::string strError2 = ""; +// if(fCheckCollateral){ +// int nConf = 0; +// if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2, nTime, nConf)){ +// strError = "Invalid Collateral : " + strError2; +// return false; +// } +// } + +// //TODO: if N cycles old, invalid, invalid + +// if(!pindex) return true; + +// if(nBlockStart < pindex->nHeight - Params().GetConsensus().nBudgetPaymentsWindowBlocks) { +// strError = "Older than current blockHeight"; +// return false; +// } + +// return true; +// } + +// bool CFinalizedBudget::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) +// { +// int nCurrentBudgetPayment = nBlockHeight - GetBlockStart(); +// if(nCurrentBudgetPayment < 0) { +// LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - height: %d start: %d\n", nBlockHeight, GetBlockStart()); +// return false; +// } + +// if(nCurrentBudgetPayment > (int)vecBudgetPayments.size() - 1) { +// LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - current budget payment: %d of %d\n", nCurrentBudgetPayment + 1, (int)vecBudgetPayments.size()); +// return false; +// } + +// bool found = false; +// BOOST_FOREACH(CTxOut out, txNew.vout) +// { +// if(vecBudgetPayments[nCurrentBudgetPayment].payee == out.scriptPubKey && vecBudgetPayments[nCurrentBudgetPayment].nAmount == out.nValue) +// found = true; +// } +// if(!found) { +// CTxDestination address1; +// ExtractDestination(vecBudgetPayments[nCurrentBudgetPayment].payee, address1); +// CBitcoinAddress address2(address1); + +// LogPrintf("CFinalizedBudget::IsTransactionValid - Missing required payment - %s: %d\n", address2.ToString(), vecBudgetPayments[nCurrentBudgetPayment].nAmount); +// } + +// return found; +// } + +// void CFinalizedBudget::SubmitVote() +// { +// CPubKey pubKeyMasternode; +// CKey keyMasternode; +// std::string errorMessage; + +// if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)){ +// LogPrintf("CFinalizedBudget::SubmitVote - Error upon calling SetKey\n"); +// return; +// } + +// CGovernanceNode* goParent = govman.FindGovernanceObject(GetHash()); +// if(!goParent) +// { +// return; +// } + +// CGovernanceVote vote(goParent, activeMasternode.vin, GetHash(), VOTE_YES); +// if(!vote.Sign(keyMasternode, pubKeyMasternode)){ +// LogPrintf("CFinalizedBudget::SubmitVote - Failure to sign."); +// return; +// } + +// std::string strError = ""; +// if(govman.UpdateGovernanceObjectVotes(vote, NULL, strError)){ +// LogPrintf("CFinalizedBudget::SubmitVote - new finalized budget vote - %s\n", vote.GetHash().ToString()); + +// govman.mapSeenGovernanceVotes.insert(make_pair(vote.GetHash(), vote)); +// vote.Relay(); +// } else { +// LogPrintf("CFinalizedBudget::SubmitVote : Error submitting vote - %s\n", strError); +// } +// } + +// CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast() +// { +// strBudgetName = ""; +// nBlockStart = 0; +// vecBudgetPayments.clear(); +// mapVotes.clear(); +// vchSig.clear(); +// nFeeTXHash = uint256(); +// } + +// CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(const CFinalizedBudget& other) +// { +// strBudgetName = other.strBudgetName; +// nBlockStart = other.nBlockStart; +// BOOST_FOREACH(CTxBudgetPayment out, other.vecBudgetPayments) vecBudgetPayments.push_back(out); +// mapVotes = other.mapVotes; +// nFeeTXHash = other.nFeeTXHash; +// } + +// CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(std::string strBudgetNameIn, int nBlockStartIn, std::vector vecBudgetPaymentsIn, uint256 nFeeTXHashIn) +// { +// strBudgetName = strBudgetNameIn; +// nBlockStart = nBlockStartIn; +// BOOST_FOREACH(CTxBudgetPayment out, vecBudgetPaymentsIn) vecBudgetPayments.push_back(out); +// mapVotes.clear(); +// nFeeTXHash = nFeeTXHashIn; +// } + +// void CFinalizedBudgetBroadcast::Relay() +// { +// CInv inv(MSG_GOVERNANCE_FINALIZED_BUDGET, GetHash()); +// RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION); +// } + +// std::string CGovernanceManager::ToString() const +// { +// std::ostringstream info; + +// info << "Proposals: " << (int)mapGovernanceObjects.size() << +// ", Budgets: " << (int)mapFinalizedBudgets.size() << +// ", Seen Budgets: " << (int)mapSeenGovernanceObjects.size() << +// ", Seen Budget Votes: " << (int)mapSeenGovernanceVotes.size() << +// ", Seen Final Budgets: " << (int)mapSeenFinalizedBudgets.size(); + +// return info.str(); +// } + +// void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex) +// { +// pCurrentBlockIndex = pindex; +// LogPrint("mnbudget", "pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight); + +// if(!fLiteMode && masternodeSync.RequestedMasternodeAssets > MASTERNODE_SYNC_LIST) +// NewBlock(); +// } + +// CGovernanceNode::CGovernanceNode(UniValue obj) +// { + +// if 'type' == 'dash-network': +// CCategory cat(json['level']); +// if not cat.isSubcategoryOf("level"): +// return Error("Invalid subcategory"); +// else: +// SetLevel(json['level']); + +// //... etc ... +// } + +// int64_t CGovernanceNode::GetValidStartTimestamp() +// { +// //Proposals/Settings/Switches have no restrictions +// if(nGovernanceType == Proposal || nGovernanceType == Setting || nGovernanceType == Switch) return 0; + +// //Contracts have a two week voting period, afterwhich is locked in +// if(nGovernanceType == Contract) return nTime - (60*60); //an hour earlier than when this was created + +// return 0; +// } + +// int64_t CGovernanceNode::GetValidEndTimestamp() +// { +// //Proposals/Settings/Switches have no restrictions +// if(nGovernanceType == Proposal || nGovernanceType == Setting || nGovernanceType == Switch) return 32503680000; + +// //Contracts have a two week voting period, afterwhich is locked in +// if(nGovernanceType == Contract) return nTime + (60*60*24*14); //two week window + +// return 32503680000; +// } + +// GovernanceObjectType CGovernanceManager::GetGovernanceTypeByHash(uint256 nHash) +// { +// // covers proposals, contracts, switches and settings +// CGovernanceNode* obj = FindGovernanceObject(nHash); +// if(obj) return obj->GetGovernanceType(); + +// // finalized budgets +// CFinalizedBudget* obj2 = FindFinalizedBudget(nHash); +// if(obj2) return FinalizedBudget; + +// return Error; +// } + +// GovernanceObjectType CGovernanceNode::GetGovernanceType() +// { +// return (GovernanceObjectType)nGovernanceType; +// } + +// std::string CGovernanceNode::GetGovernanceTypeAsString() +// { +// return GovernanceTypeToString((GovernanceObjectType)nGovernanceType); +// } + +// void CGovernanceNode::SetNull() +// { +// fValid = false; +// strName = "unknown"; +// nGovernanceType = -1; + +// strURL = ""; +// nBlockStart = 0; +// nBlockEnd = 576*365*100; +// nAmount = 0; +// nTime = 0; +// nFeeTXHash = uint256(); +// } + +// void CGovernanceNodeBroadcast::CreateProposalOrContract(GovernanceObjectType nTypeIn, std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) +// { +// nGovernanceType = (int)nTypeIn; + +// strName = strNameIn; +// strURL = strURLIn; + +// nBlockStart = nBlockStartIn; + +// int nPaymentsStart = nBlockStart - nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// //calculate the end of the cycle for this vote, add half a cycle (vote will be deleted after that block) +// nBlockEnd = nPaymentsStart + Params().GetConsensus().nBudgetPaymentsCycleBlocks * nPaymentCount; + +// address = addressIn; +// nAmount = nAmountIn; + +// nFeeTXHash = nFeeTXHashIn; +// } + +// void CGovernanceNodeBroadcast::CreateProposal(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) +// { +// //they are exactly the same parameter wise, all changed are in enforcement of the voting window and budgeting logic +// CreateProposalOrContract(Proposal, strNameIn, strURLIn, nPaymentCount, addressIn, nAmountIn, nBlockStartIn, nFeeTXHashIn); +// } + +// void CGovernanceNodeBroadcast::CreateContract(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) +// { +// //they are exactly the same parameter wise, all changed are in enforcement of the voting window and budgeting logic +// CreateProposalOrContract(Contract, strNameIn, strURLIn, nPaymentCount, addressIn, nAmountIn, nBlockStartIn, nFeeTXHashIn); +// } + +// void CGovernanceNodeBroadcast::CreateSetting(std::string strNameIn, std::string strURLIn, std::string strSuggestedValueIn, uint256 nFeeTXHashIn) +// { +// GovernanceObjectType nType = Setting; +// nGovernanceType = (int)nType; + +// strURL = strURLIn; //url where the argument for activation is +// strName = strNameIn; +// strSuggestedValue = strSuggestedValueIn; +// nFeeTXHash = nFeeTXHashIn; +// } + +// CGovernanceNode::CGovernanceNode() +// { +// strName = "unknown"; +// nBlockStart = 0; +// nBlockEnd = 0; +// nAmount = 0; +// nTime = 0; +// fValid = true; +// nGovernanceType = 0; +// } + +// CGovernanceNode::CGovernanceNode(const CGovernanceNode& other) +// { +// strName = other.strName; +// strURL = other.strURL; +// nBlockStart = other.nBlockStart; +// nBlockEnd = other.nBlockEnd; +// address = other.address; +// nAmount = other.nAmount; +// nTime = other.nTime; +// nFeeTXHash = other.nFeeTXHash; +// mapVotes = other.mapVotes; +// nGovernanceType = other.nGovernanceType; +// fValid = true; +// } + +// bool CGovernanceNode::IsCategoryValid() +// { +// std::string strRootCat = govman.FindCategoryRoot(category); +// std::string strPrimaryTypeName = PrimaryTypeToString(GetType()); +// return strRootCat == strPrimaryTypeName; +// } + +// bool CGovernanceNode::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral) +// { + +// if(GetNoCount() - GetYesCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){ +// strError = "Active removal"; +// return false; +// } + +// if(nBlockStart < 0) { +// strError = "Invalid Proposal"; +// return false; +// } + +// if(!pindex) { +// strError = "Tip is NULL"; +// return true; +// } + +// if(nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks != 0){ +// int nNext = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// strError = strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nNext); +// return false; +// } + +// if(nBlockEnd % Params().GetConsensus().nBudgetPaymentsCycleBlocks != Params().GetConsensus().nBudgetPaymentsCycleBlocks/2){ +// strError = "Invalid block end"; +// return false; +// } + +// if(nBlockEnd < nBlockStart) { +// strError = "Invalid block end - must be greater then block start."; +// return false; +// } + +// if(nAmount < 1*COIN) { +// strError = "Invalid proposal amount"; +// return false; +// } + +// if(strName.size() > 20) { +// strError = "Invalid proposal name, limit of 20 characters."; +// return false; +// } + +// if(strName != SanitizeString(strName)) { +// 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 proposal Payment Address"; +// return false; +// } + +// if(IsCategoryValid()) { +// // NOTE: PRINT CATEGORY TO STRING +// strError = "Category type is invalid"; +// return false; +// } + +// if(fCheckCollateral){ +// int nConf = 0; +// if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError, nTime, nConf)){ +// return false; +// } +// } + +// /* +// TODO: There might be an issue with multisig in the coinbase on mainnet, we will add support for it in a future release. +// */ +// if(address.IsPayToScriptHash()) { +// strError = "Multisig is not currently supported."; +// return false; +// } + +// // -- If GetAbsoluteYesCount is more than -10% of the network, flag as invalid +// if(GetAbsoluteYesCount() < -(mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10)) { +// strError = "Voted Down"; +// return false; +// } + +// //can only pay out 10% of the possible coins (min value of coins) +// if(nAmount > govman.GetTotalBudget(nBlockStart)) { +// strError = "Payment more than max"; +// return false; +// } + +// if(GetBlockEnd() + Params().GetConsensus().nBudgetPaymentsWindowBlocks < pindex->nHeight) return false; + +// /* +// governance checking through the dynamic part of the system +// */ + +// // this verifies the node tree rules +// if(!pParent.CanAdd((*this), strError)) +// { +// return false; +// } + +// // we need to verify the user signature and the parent nodes key possible as well +// if(!CGovernanceBrain::IsPlacementValid(GetType(), pParent->GetType()) +// { +// return false; +// } + +// // if(!pParent.IsChildValid((*this), strError)) +// // { +// // return false; +// // } + +// // in either case they should have signed this message correctly too +// // -- isn't this done elsewhere? Should it be last? +// if(!VerifySignature(strError)) +// { +// return false; +// } + + +// return true; +// } + +// bool CGovernanceNode::IsEstablished() { +// //Proposals must be established to make it into a budget +// return (nTime < GetTime() - Params().GetConsensus().nBudgetProposalEstablishingTime); +// } + +// bool CGovernanceNode::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError) // { // LOCK(cs); // uint256 hash = vote.vin.prevout.GetHash(); + // if(mapVotes.count(hash)){ // if(mapVotes[hash].nTime > vote.nTime){ // strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString()); -// LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); +// LogPrint("mnbudget", "CGovernanceNode::AddOrUpdateVote - %s\n", strError); // return false; // } // if(vote.nTime - mapVotes[hash].nTime < BUDGET_VOTE_UPDATE_MIN){ // strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash].nTime); -// LogPrint("mnbudget", "CFinalizedBudget::AddOrUpdateVote - %s\n", strError); +// LogPrint("mnbudget", "CGovernanceNode::AddOrUpdateVote - %s\n", strError); // return false; // } // } @@ -1369,767 +1985,151 @@ CFinalizedBudget::CFinalizedBudget(const CFinalizedBudget& other) // return true; // } -//evaluate if we should vote for this. Masternode only -void CFinalizedBudget::AutoCheckSuperBlockVoting() -{ - LOCK(cs); - - CBlockIndex* pindexPrev = chainActive.Tip(); - if(!pindexPrev) return; - - LogPrintf("CFinalizedBudget::AutoCheck - %lli - %d\n", pindexPrev->nHeight, fAutoChecked); - - if(!fMasterNode || fAutoChecked) return; - - //do this 1 in 4 blocks -- spread out the voting activity on mainnet - // -- this function is only called every sixth block, so this is really 1 in 24 blocks - if(Params().NetworkIDString() == CBaseChainParams::MAIN && rand() % 4 != 0) { - LogPrintf("CFinalizedBudget::AutoCheck - waiting\n"); - return; - } - - fAutoChecked = true; //we only need to check this once - - - if(strBudgetMode == "auto") //only vote for exact matches - { - std::vector vBudgetProposals = govman.GetBudget(); - - - for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ - LogPrintf("CFinalizedBudget::AutoCheck - nProp %d %s\n", i, vecBudgetPayments[i].nProposalHash.ToString()); - LogPrintf("CFinalizedBudget::AutoCheck - Payee %d %s\n", i, ScriptToAsmStr(vecBudgetPayments[i].payee)); - LogPrintf("CFinalizedBudget::AutoCheck - nAmount %d %lli\n", i, vecBudgetPayments[i].nAmount); - } - - for(unsigned int i = 0; i < vBudgetProposals.size(); i++){ - LogPrintf("CFinalizedBudget::AutoCheck - nProp %d %s\n", i, vBudgetProposals[i]->GetHash().ToString()); - LogPrintf("CFinalizedBudget::AutoCheck - Payee %d %s\n", i, ScriptToAsmStr(vBudgetProposals[i]->GetPayee())); - LogPrintf("CFinalizedBudget::AutoCheck - nAmount %d %lli\n", i, vBudgetProposals[i]->GetAmount()); - } - - if(vBudgetProposals.size() == 0) { - LogPrintf("CFinalizedBudget::AutoCheck - Can't get Budget, aborting\n"); - return; - } - - if(vBudgetProposals.size() != vecBudgetPayments.size()) { - LogPrintf("CFinalizedBudget::AutoCheck - Budget length doesn't match\n"); - return; - } - - - for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ - if(i > vBudgetProposals.size() - 1) { - LogPrintf("CFinalizedBudget::AutoCheck - Vector size mismatch, aborting\n"); - return; - } - - if(vecBudgetPayments[i].nProposalHash != vBudgetProposals[i]->GetHash()){ - LogPrintf("CFinalizedBudget::AutoCheck - item #%d doesn't match %s %s\n", i, vecBudgetPayments[i].nProposalHash.ToString(), vBudgetProposals[i]->GetHash().ToString()); - return; - } - - // if(vecBudgetPayments[i].payee != vBudgetProposals[i]->GetPayee()){ -- triggered with false positive - if(vecBudgetPayments[i].payee != vBudgetProposals[i]->GetPayee()){ - LogPrintf("CFinalizedBudget::AutoCheck - item #%d payee doesn't match %s %s\n", i, ScriptToAsmStr(vecBudgetPayments[i].payee), ScriptToAsmStr(vBudgetProposals[i]->GetPayee())); - return; - } - - if(vecBudgetPayments[i].nAmount != vBudgetProposals[i]->GetAmount()){ - LogPrintf("CFinalizedBudget::AutoCheck - item #%d payee doesn't match %lli %lli\n", i, vecBudgetPayments[i].nAmount, vBudgetProposals[i]->GetAmount()); - return; - } - } - - LogPrintf("CFinalizedBudget::AutoCheck - Finalized Budget Matches! Submitting Vote.\n"); - SubmitVote(); - - } -} -// If masternode voted for a proposal, but is now invalid -- remove the vote -void CFinalizedBudget::CleanAndRemove(bool fSignatureCheck) -{ - std::map::iterator it = mapVotes.begin(); - - while(it != mapVotes.end()) { - std::string strReason = ""; - (*it).second.fValid = (*it).second.IsValid(fSignatureCheck, strReason); - ++it; - } -} - - -CAmount CFinalizedBudget::GetTotalPayout() -{ - CAmount ret = 0; - - for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){ - ret += vecBudgetPayments[i].nAmount; - } - - return ret; -} - -std::string CFinalizedBudget::GetProposals() -{ - LOCK(cs); - std::string ret = ""; - - BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){ - CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(budgetPayment.nProposalHash); - - std::string token = budgetPayment.nProposalHash.ToString(); - - if(pbudgetProposal) token = pbudgetProposal->GetName(); - if(ret == "") {ret = token;} - else {ret += "," + token;} - } - return ret; -} - -std::string CFinalizedBudget::GetStatus() -{ - std::string retBadHashes = ""; - std::string retBadPayeeOrAmount = ""; - - for(int nBlockHeight = GetBlockStart(); nBlockHeight <= GetBlockEnd(); nBlockHeight++) - { - CTxBudgetPayment budgetPayment; - if(!GetBudgetPaymentByBlock(nBlockHeight, budgetPayment)){ - LogPrintf("CFinalizedBudget::GetStatus - Couldn't find budget payment for block %lld\n", nBlockHeight); - continue; - } - - CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(budgetPayment.nProposalHash); - if(!pbudgetProposal){ - if(retBadHashes == ""){ - retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString(); - } else { - retBadHashes += "," + budgetPayment.nProposalHash.ToString(); - } - } else { - if(pbudgetProposal->GetPayee() != budgetPayment.payee || pbudgetProposal->GetAmount() != budgetPayment.nAmount) - { - if(retBadPayeeOrAmount == ""){ - retBadPayeeOrAmount = "Budget payee/nAmount doesn't match our proposal! " + budgetPayment.nProposalHash.ToString(); - } else { - retBadPayeeOrAmount += "," + budgetPayment.nProposalHash.ToString(); - } - } - } - } - - if(retBadHashes == "" && retBadPayeeOrAmount == "") return "OK"; - - return retBadHashes + retBadPayeeOrAmount; -} - -bool CFinalizedBudget::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral) -{ - //must be the correct block for payment to happen (once a month) - if(nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks != 0) {strError = "Invalid BlockStart"; return false;} - if(GetBlockEnd() - nBlockStart > Params().GetConsensus().nBudgetPaymentsWindowBlocks) {strError = "Invalid BlockEnd"; return false;} - if((int)vecBudgetPayments.size() > Params().GetConsensus().nBudgetPaymentsWindowBlocks) {strError = "Invalid budget payments count (too many)"; return false;} - if(strBudgetName == "") {strError = "Invalid Budget Name"; return false;} - if(nBlockStart == 0) {strError = "Invalid BlockStart == 0"; return false;} - if(nFeeTXHash == uint256()) {strError = "Invalid FeeTx == 0"; return false;} - - //can only pay out 10% of the possible coins (min value of coins) - if(GetTotalPayout() > govman.GetTotalBudget(nBlockStart)) {strError = "Invalid Payout (more than max)"; return false;} - - std::string strError2 = ""; - if(fCheckCollateral){ - int nConf = 0; - if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError2, nTime, nConf)){ - strError = "Invalid Collateral : " + strError2; - return false; - } - } - - //TODO: if N cycles old, invalid, invalid - - if(!pindex) return true; - - if(nBlockStart < pindex->nHeight - Params().GetConsensus().nBudgetPaymentsWindowBlocks) { - strError = "Older than current blockHeight"; - return false; - } - - return true; -} - -bool CFinalizedBudget::IsTransactionValid(const CTransaction& txNew, int nBlockHeight) -{ - int nCurrentBudgetPayment = nBlockHeight - GetBlockStart(); - if(nCurrentBudgetPayment < 0) { - LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - height: %d start: %d\n", nBlockHeight, GetBlockStart()); - return false; - } - - if(nCurrentBudgetPayment > (int)vecBudgetPayments.size() - 1) { - LogPrintf("CFinalizedBudget::IsTransactionValid - Invalid block - current budget payment: %d of %d\n", nCurrentBudgetPayment + 1, (int)vecBudgetPayments.size()); - return false; - } - - bool found = false; - BOOST_FOREACH(CTxOut out, txNew.vout) - { - if(vecBudgetPayments[nCurrentBudgetPayment].payee == out.scriptPubKey && vecBudgetPayments[nCurrentBudgetPayment].nAmount == out.nValue) - found = true; - } - if(!found) { - CTxDestination address1; - ExtractDestination(vecBudgetPayments[nCurrentBudgetPayment].payee, address1); - CBitcoinAddress address2(address1); - - LogPrintf("CFinalizedBudget::IsTransactionValid - Missing required payment - %s: %d\n", address2.ToString(), vecBudgetPayments[nCurrentBudgetPayment].nAmount); - } - - return found; -} - -void CFinalizedBudget::SubmitVote() -{ - CPubKey pubKeyMasternode; - CKey keyMasternode; - std::string errorMessage; - - if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)){ - LogPrintf("CFinalizedBudget::SubmitVote - Error upon calling SetKey\n"); - return; - } - - CGovernanceNode* goParent = govman.FindGovernanceObject(GetHash()); - if(!goParent) - { - return; - } - - CGovernanceVote vote(goParent, activeMasternode.vin, GetHash(), VOTE_YES); - if(!vote.Sign(keyMasternode, pubKeyMasternode)){ - LogPrintf("CFinalizedBudget::SubmitVote - Failure to sign."); - return; - } - - std::string strError = ""; - if(govman.UpdateGovernanceObjectVotes(vote, NULL, strError)){ - LogPrintf("CFinalizedBudget::SubmitVote - new finalized budget vote - %s\n", vote.GetHash().ToString()); - - govman.mapSeenGovernanceVotes.insert(make_pair(vote.GetHash(), vote)); - vote.Relay(); - } else { - LogPrintf("CFinalizedBudget::SubmitVote : Error submitting vote - %s\n", strError); - } -} - -CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast() -{ - strBudgetName = ""; - nBlockStart = 0; - vecBudgetPayments.clear(); - mapVotes.clear(); - vchSig.clear(); - nFeeTXHash = uint256(); -} - -CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(const CFinalizedBudget& other) -{ - strBudgetName = other.strBudgetName; - nBlockStart = other.nBlockStart; - BOOST_FOREACH(CTxBudgetPayment out, other.vecBudgetPayments) vecBudgetPayments.push_back(out); - mapVotes = other.mapVotes; - nFeeTXHash = other.nFeeTXHash; -} - -CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast(std::string strBudgetNameIn, int nBlockStartIn, std::vector vecBudgetPaymentsIn, uint256 nFeeTXHashIn) -{ - strBudgetName = strBudgetNameIn; - nBlockStart = nBlockStartIn; - BOOST_FOREACH(CTxBudgetPayment out, vecBudgetPaymentsIn) vecBudgetPayments.push_back(out); - mapVotes.clear(); - nFeeTXHash = nFeeTXHashIn; -} - -void CFinalizedBudgetBroadcast::Relay() -{ - CInv inv(MSG_GOVERNANCE_FINALIZED_BUDGET, GetHash()); - RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION); -} - -std::string CGovernanceManager::ToString() const -{ - std::ostringstream info; - - info << "Proposals: " << (int)mapGovernanceObjects.size() << - ", Budgets: " << (int)mapFinalizedBudgets.size() << - ", Seen Budgets: " << (int)mapSeenGovernanceObjects.size() << - ", Seen Budget Votes: " << (int)mapSeenGovernanceVotes.size() << - ", Seen Final Budgets: " << (int)mapSeenFinalizedBudgets.size(); - - return info.str(); -} - -void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex) -{ - pCurrentBlockIndex = pindex; - LogPrint("mnbudget", "pCurrentBlockIndex->nHeight: %d\n", pCurrentBlockIndex->nHeight); - - if(!fLiteMode && masternodeSync.RequestedMasternodeAssets > MASTERNODE_SYNC_LIST) - NewBlock(); -} - -CGovernanceNode::CGovernanceNode(UniValue obj) -{ - - if 'type' == 'dash-network': - CCategory cat(json['level']); - if not cat.isSubcategoryOf("level"): - return Error("Invalid subcategory"); - else: - SetLevel(json['level']); - - //... etc ... -} - -int64_t CGovernanceNode::GetValidStartTimestamp() -{ - //Proposals/Settings/Switches have no restrictions - if(nGovernanceType == Proposal || nGovernanceType == Setting || nGovernanceType == Switch) return 0; - - //Contracts have a two week voting period, afterwhich is locked in - if(nGovernanceType == Contract) return nTime - (60*60); //an hour earlier than when this was created - - return 0; -} - -int64_t CGovernanceNode::GetValidEndTimestamp() -{ - //Proposals/Settings/Switches have no restrictions - if(nGovernanceType == Proposal || nGovernanceType == Setting || nGovernanceType == Switch) return 32503680000; - - //Contracts have a two week voting period, afterwhich is locked in - if(nGovernanceType == Contract) return nTime + (60*60*24*14); //two week window - - return 32503680000; -} - -GovernanceObjectType CGovernanceManager::GetGovernanceTypeByHash(uint256 nHash) -{ - // covers proposals, contracts, switches and settings - CGovernanceNode* obj = FindGovernanceObject(nHash); - if(obj) return obj->GetGovernanceType(); - - // finalized budgets - CFinalizedBudget* obj2 = FindFinalizedBudget(nHash); - if(obj2) return FinalizedBudget; - - return Error; -} - -GovernanceObjectType CGovernanceNode::GetGovernanceType() -{ - return (GovernanceObjectType)nGovernanceType; -} - -std::string CGovernanceNode::GetGovernanceTypeAsString() -{ - return GovernanceTypeToString((GovernanceObjectType)nGovernanceType); -} - -void CGovernanceNode::SetNull() -{ - fValid = false; - strName = "unknown"; - nGovernanceType = -1; - - strURL = ""; - nBlockStart = 0; - nBlockEnd = 576*365*100; - nAmount = 0; - nTime = 0; - nFeeTXHash = uint256(); -} - -void CGovernanceNodeBroadcast::CreateProposalOrContract(GovernanceObjectType nTypeIn, std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) -{ - nGovernanceType = (int)nTypeIn; - - strName = strNameIn; - strURL = strURLIn; - - nBlockStart = nBlockStartIn; - - int nPaymentsStart = nBlockStart - nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks; - //calculate the end of the cycle for this vote, add half a cycle (vote will be deleted after that block) - nBlockEnd = nPaymentsStart + Params().GetConsensus().nBudgetPaymentsCycleBlocks * nPaymentCount; - - address = addressIn; - nAmount = nAmountIn; - - nFeeTXHash = nFeeTXHashIn; -} - -void CGovernanceNodeBroadcast::CreateProposal(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) -{ - //they are exactly the same parameter wise, all changed are in enforcement of the voting window and budgeting logic - CreateProposalOrContract(Proposal, strNameIn, strURLIn, nPaymentCount, addressIn, nAmountIn, nBlockStartIn, nFeeTXHashIn); -} - -void CGovernanceNodeBroadcast::CreateContract(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn) -{ - //they are exactly the same parameter wise, all changed are in enforcement of the voting window and budgeting logic - CreateProposalOrContract(Contract, strNameIn, strURLIn, nPaymentCount, addressIn, nAmountIn, nBlockStartIn, nFeeTXHashIn); -} - -void CGovernanceNodeBroadcast::CreateSetting(std::string strNameIn, std::string strURLIn, std::string strSuggestedValueIn, uint256 nFeeTXHashIn) -{ - GovernanceObjectType nType = Setting; - nGovernanceType = (int)nType; - - strURL = strURLIn; //url where the argument for activation is - strName = strNameIn; - strSuggestedValue = strSuggestedValueIn; - nFeeTXHash = nFeeTXHashIn; -} - -CGovernanceNode::CGovernanceNode() -{ - strName = "unknown"; - nBlockStart = 0; - nBlockEnd = 0; - nAmount = 0; - nTime = 0; - fValid = true; - nGovernanceType = 0; -} - -CGovernanceNode::CGovernanceNode(const CGovernanceNode& other) -{ - strName = other.strName; - strURL = other.strURL; - nBlockStart = other.nBlockStart; - nBlockEnd = other.nBlockEnd; - address = other.address; - nAmount = other.nAmount; - nTime = other.nTime; - nFeeTXHash = other.nFeeTXHash; - mapVotes = other.mapVotes; - nGovernanceType = other.nGovernanceType; - fValid = true; -} - -bool CGovernanceNode::IsCategoryValid() -{ - std::string strRootCat = govman.FindCategoryRoot(category); - std::string strPrimaryTypeName = PrimaryTypeToString(GetType()); - return strRootCat == strPrimaryTypeName; -} - -bool CGovernanceNode::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral) -{ - - if(GetNoCount() - GetYesCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){ - strError = "Active removal"; - return false; - } - - if(nBlockStart < 0) { - strError = "Invalid Proposal"; - return false; - } - - if(!pindex) { - strError = "Tip is NULL"; - return true; - } - - if(nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks != 0){ - int nNext = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - strError = strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nNext); - return false; - } - - if(nBlockEnd % Params().GetConsensus().nBudgetPaymentsCycleBlocks != Params().GetConsensus().nBudgetPaymentsCycleBlocks/2){ - strError = "Invalid block end"; - return false; - } - - if(nBlockEnd < nBlockStart) { - strError = "Invalid block end - must be greater then block start."; - return false; - } - - if(nAmount < 1*COIN) { - strError = "Invalid proposal amount"; - return false; - } - - if(strName.size() > 20) { - strError = "Invalid proposal name, limit of 20 characters."; - return false; - } - - if(strName != SanitizeString(strName)) { - 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 proposal Payment Address"; - return false; - } - - if(IsCategoryValid()) { - // NOTE: PRINT CATEGORY TO STRING - strError = "Category type is invalid"; - return false; - } - - if(fCheckCollateral){ - int nConf = 0; - if(!IsBudgetCollateralValid(nFeeTXHash, GetHash(), strError, nTime, nConf)){ - return false; - } - } - - /* - TODO: There might be an issue with multisig in the coinbase on mainnet, we will add support for it in a future release. - */ - if(address.IsPayToScriptHash()) { - strError = "Multisig is not currently supported."; - return false; - } - - // -- If GetAbsoluteYesCount is more than -10% of the network, flag as invalid - if(GetAbsoluteYesCount() < -(mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10)) { - strError = "Voted Down"; - return false; - } - - //can only pay out 10% of the possible coins (min value of coins) - if(nAmount > govman.GetTotalBudget(nBlockStart)) { - strError = "Payment more than max"; - return false; - } - - if(GetBlockEnd() + Params().GetConsensus().nBudgetPaymentsWindowBlocks < pindex->nHeight) return false; - - /* - governance checking through the dynamic part of the system - */ - - // this verifies the node tree rules - if(!pParent.CanAdd((*this), strError)) - { - return false; - } - - // we need to verify the user signature and the parent nodes key possible as well - if(!CGovernanceBrain::IsPlacementValid(GetType(), pParent->GetType()) - { - return false; - } - - // if(!pParent.IsChildValid((*this), strError)) - // { - // return false; - // } - - // in either case they should have signed this message correctly too - // -- isn't this done elsewhere? Should it be last? - if(!VerifySignature(strError)) - { - return false; - } - - - return true; -} - -bool CGovernanceNode::IsEstablished() { - //Proposals must be established to make it into a budget - return (nTime < GetTime() - Params().GetConsensus().nBudgetProposalEstablishingTime); -} - -bool CGovernanceNode::AddOrUpdateVote(CGovernanceVote& vote, std::string& strError) -{ - LOCK(cs); - - uint256 hash = vote.vin.prevout.GetHash(); - - if(mapVotes.count(hash)){ - if(mapVotes[hash].nTime > vote.nTime){ - strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString()); - LogPrint("mnbudget", "CGovernanceNode::AddOrUpdateVote - %s\n", strError); - return false; - } - if(vote.nTime - mapVotes[hash].nTime < BUDGET_VOTE_UPDATE_MIN){ - strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash].nTime); - LogPrint("mnbudget", "CGovernanceNode::AddOrUpdateVote - %s\n", strError); - return false; - } - } - - mapVotes[hash] = vote; - return true; -} - -// If masternode voted for a proposal, but is now invalid -- remove the vote -void CGovernanceNode::CleanAndRemove(bool fSignatureCheck) -{ - std::map::iterator it = mapVotes.begin(); - - while(it != mapVotes.end()) { - std::string strReason = ""; - (*it).second.fValid = (*it).second.IsValid(fSignatureCheck, strReason); - ++it; - } -} - -double CGovernanceNode::GetRatio() -{ - int yeas = 0; - int nays = 0; - - std::map::iterator it = mapVotes.begin(); - - while(it != mapVotes.end()) { - if ((*it).second.nVote == VOTE_YES) yeas++; - if ((*it).second.nVote == VOTE_NO) nays++; - ++it; - } - - if(yeas+nays == 0) return 0.0f; - - return ((double)(yeas) / (double)(yeas+nays)); -} - -int CGovernanceNode::GetAbsoluteYesCount() -{ - return GetYesCount() - GetNoCount(); -} - -int CGovernanceNode::GetYesCount() -{ - int ret = 0; - - std::map::iterator it = mapVotes.begin(); - while(it != mapVotes.end()){ - if ((*it).second.nVote == VOTE_YES && (*it).second.fValid) ret++; - ++it; - } - - return ret; -} - -int CGovernanceNode::GetNoCount() -{ - int ret = 0; - - std::map::iterator it = mapVotes.begin(); - while(it != mapVotes.end()){ - if ((*it).second.nVote == VOTE_NO && (*it).second.fValid) ret++; - ++it; - } - - return ret; -} - -int CGovernanceNode::GetAbstainCount() -{ - int ret = 0; - - std::map::iterator it = mapVotes.begin(); - while(it != mapVotes.end()){ - if ((*it).second.nVote == VOTE_ABSTAIN && (*it).second.fValid) ret++; - ++it; - } - - return ret; -} - -int CGovernanceNode::GetBlockStartCycle() -{ - //end block is half way through the next cycle (so the proposal will be removed much after the payment is sent) - - return nBlockStart - nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks; -} - -int CGovernanceNode::GetBlockCurrentCycle(const CBlockIndex* pindex) -{ - if(!pindex) return -1; - - if(pindex->nHeight >= GetBlockEndCycle()) return -1; - - return pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks; -} - -int CGovernanceNode::GetBlockEndCycle() -{ - //end block is half way through the next cycle (so the proposal will be removed much after the payment is sent) - - return nBlockEnd - Params().GetConsensus().nBudgetPaymentsCycleBlocks/2; -} - -int CGovernanceNode::GetTotalPaymentCount() -{ - return (GetBlockEndCycle() - GetBlockStartCycle()) / Params().GetConsensus().nBudgetPaymentsCycleBlocks; -} - -int CGovernanceNode::GetRemainingPaymentCount(int nBlockHeight) -{ - int nPayments = 0; - // printf("-> Budget Name : %s\n", strName.c_str()); - // printf("------- nBlockStart : %d\n", nBlockStart); - // printf("------- nBlockEnd : %d\n", nBlockEnd); - while(nBlockHeight + Params().GetConsensus().nBudgetPaymentsCycleBlocks < GetBlockEndCycle()) - { - // printf("------- P : %d %d - %d < %d - %d\n", nBlockHeight, nPayments, nBlockHeight + Params().GetConsensus().nBudgetPaymentsCycleBlocks, nBlockEnd, nBlockHeight + Params().GetConsensus().nBudgetPaymentsCycleBlocks < nBlockEnd); - nBlockHeight += Params().GetConsensus().nBudgetPaymentsCycleBlocks; - nPayments++; - } - return nPayments; -} - - -// for contracts (should we subclass a contract object??) -int64_t CGovernanceNode::GetContractActivationTime() -{ - //contracts always have at least two weeks - return nTime+CONTRACT_ACTIVATION_TIME; -} - -bool CGovernanceNode::IsContractActivated() -{ - return GetTime() > GetContractActivationTime(); -} - -GovernanceObjectType CGovernanceNode::GetType() -{ - return (GovernanceObjectType)nGovernanceType; -} - -int64_t CGovernanceNode::GetValidStartTimestamp() -{ - if(pParent1) {return pParent1->GetValidStartTimestamp();} - if(pParent2) {return pParent2->GetValidStartTimestamp();} - return -1; -} - -int64_t CGovernanceNode::GetValidEndTimestamp() -{ - if(pParent1) {return pParent1->GetValidEndTimestamp();} - if(pParent2) {return pParent2->GetValidEndTimestamp();} - return -1; -} \ No newline at end of file +// // If masternode voted for a proposal, but is now invalid -- remove the vote +// void CGovernanceNode::CleanAndRemove(bool fSignatureCheck) +// { +// std::map::iterator it = mapVotes.begin(); + +// while(it != mapVotes.end()) { +// std::string strReason = ""; +// (*it).second.fValid = (*it).second.IsValid(fSignatureCheck, strReason); +// ++it; +// } +// } + +// double CGovernanceNode::GetRatio() +// { +// int yeas = 0; +// int nays = 0; + +// std::map::iterator it = mapVotes.begin(); + +// while(it != mapVotes.end()) { +// if ((*it).second.nVote == VOTE_YES) yeas++; +// if ((*it).second.nVote == VOTE_NO) nays++; +// ++it; +// } + +// if(yeas+nays == 0) return 0.0f; + +// return ((double)(yeas) / (double)(yeas+nays)); +// } + +// int CGovernanceNode::GetAbsoluteYesCount() +// { +// return GetYesCount() - GetNoCount(); +// } + +// int CGovernanceNode::GetYesCount() +// { +// int ret = 0; + +// std::map::iterator it = mapVotes.begin(); +// while(it != mapVotes.end()){ +// if ((*it).second.nVote == VOTE_YES && (*it).second.fValid) ret++; +// ++it; +// } + +// return ret; +// } + +// int CGovernanceNode::GetNoCount() +// { +// int ret = 0; + +// std::map::iterator it = mapVotes.begin(); +// while(it != mapVotes.end()){ +// if ((*it).second.nVote == VOTE_NO && (*it).second.fValid) ret++; +// ++it; +// } + +// return ret; +// } + +// int CGovernanceNode::GetAbstainCount() +// { +// int ret = 0; + +// std::map::iterator it = mapVotes.begin(); +// while(it != mapVotes.end()){ +// if ((*it).second.nVote == VOTE_ABSTAIN && (*it).second.fValid) ret++; +// ++it; +// } + +// return ret; +// } + +// int CGovernanceNode::GetBlockStartCycle() +// { +// //end block is half way through the next cycle (so the proposal will be removed much after the payment is sent) + +// return nBlockStart - nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// } + +// int CGovernanceNode::GetBlockCurrentCycle(const CBlockIndex* pindex) +// { +// if(!pindex) return -1; + +// if(pindex->nHeight >= GetBlockEndCycle()) return -1; + +// return pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// } + +// int CGovernanceNode::GetBlockEndCycle() +// { +// //end block is half way through the next cycle (so the proposal will be removed much after the payment is sent) + +// return nBlockEnd - Params().GetConsensus().nBudgetPaymentsCycleBlocks/2; +// } + +// int CGovernanceNode::GetTotalPaymentCount() +// { +// return (GetBlockEndCycle() - GetBlockStartCycle()) / Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// } + +// int CGovernanceNode::GetRemainingPaymentCount(int nBlockHeight) +// { +// int nPayments = 0; +// // printf("-> Budget Name : %s\n", strName.c_str()); +// // printf("------- nBlockStart : %d\n", nBlockStart); +// // printf("------- nBlockEnd : %d\n", nBlockEnd); +// while(nBlockHeight + Params().GetConsensus().nBudgetPaymentsCycleBlocks < GetBlockEndCycle()) +// { +// // printf("------- P : %d %d - %d < %d - %d\n", nBlockHeight, nPayments, nBlockHeight + Params().GetConsensus().nBudgetPaymentsCycleBlocks, nBlockEnd, nBlockHeight + Params().GetConsensus().nBudgetPaymentsCycleBlocks < nBlockEnd); +// nBlockHeight += Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// nPayments++; +// } +// return nPayments; +// } + + +// // for contracts (should we subclass a contract object??) +// int64_t CGovernanceNode::GetContractActivationTime() +// { +// //contracts always have at least two weeks +// return nTime+CONTRACT_ACTIVATION_TIME; +// } + +// bool CGovernanceNode::IsContractActivated() +// { +// return GetTime() > GetContractActivationTime(); +// } + +// GovernanceObjectType CGovernanceNode::GetType() +// { +// return (GovernanceObjectType)nGovernanceType; +// } + +// int64_t CGovernanceNode::GetValidStartTimestamp() +// { +// if(pParent1) {return pParent1->GetValidStartTimestamp();} +// if(pParent2) {return pParent2->GetValidStartTimestamp();} +// return -1; +// } + +// int64_t CGovernanceNode::GetValidEndTimestamp() +// { +// if(pParent1) {return pParent1->GetValidEndTimestamp();} +// if(pParent2) {return pParent2->GetValidEndTimestamp();} +// return -1; +// } \ No newline at end of file diff --git a/src/drafted/governance.new.h b/src/drafted/governance.new.h index 1d2a188f3..c1155c915 100644 --- a/src/drafted/governance.new.h +++ b/src/drafted/governance.new.h @@ -1,331 +1,331 @@ -// Copyright (c) 2014-2016 The Dash Core developers +// // Copyright (c) 2014-2016 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef GOVERNANCE_H -#define GOVERNANCE_H +// // Distributed under the MIT/X11 software license, see the accompanying +// // file COPYING or http://www.opensource.org/licenses/mit-license.php. +// #ifndef GOVERNANCE_H +// #define GOVERNANCE_H -//todo: which of these do we need? -#include "main.h" -#include "sync.h" -#include "net.h" -#include "key.h" -#include "util.h" -#include "base58.h" -#include "masternode.h" -#include "governance-types.h" -#include "governance-vote.h" -#include -#include "init.h" -#include +// //todo: which of these do we need? +// #include "main.h" +// #include "sync.h" +// #include "net.h" +// #include "key.h" +// #include "util.h" +// #include "base58.h" +// #include "masternode.h" +// #include "governance-types.h" +// #include "governance-vote.h" +// #include +// #include "init.h" +// #include -using namespace std; +// using namespace std; -extern CCriticalSection cs_budget; +// extern CCriticalSection cs_budget; -class CGovernanceManager; -class CGovernanceNode; -class CTxBudgetPayment; -class CFinalizedBudgetBroadcast; -class CFinalizedBudget; +// class CGovernanceManager; +// class CGovernanceNode; +// class CTxBudgetPayment; +// class CFinalizedBudgetBroadcast; +// class CFinalizedBudget; -extern CGovernanceManager govman; -extern std::vector vecImmatureGovernanceNodes; +// extern CGovernanceManager govman; +// extern std::vector vecImmatureGovernanceNodes; -void DumpBudgets(); +// void DumpBudgets(); -//Check the collateral transaction for the budget proposal/finalized budget -bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime, int& nConf); -std::string PrimaryTypeToString(GovernanceObjectType type); +// //Check the collateral transaction for the budget proposal/finalized budget +// bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::string& strError, int64_t& nTime, int& nConf); +// std::string PrimaryTypeToString(GovernanceObjectType type); -/* - GOVERNANCE CLASSES -*/ +// /* +// GOVERNANCE CLASSES +// */ -/** Save Budget Manager (budget.dat) - */ -class CBudgetDB -{ -private: - boost::filesystem::path pathDB; - std::string strMagicMessage; -public: - enum ReadResult { - Ok, - FileError, - HashReadError, - IncorrectHash, - IncorrectMagicMessage, - IncorrectMagicNumber, - IncorrectFormat - }; - - CBudgetDB(); - bool Write(const CGovernanceManager &objToSave); - ReadResult Read(CGovernanceManager& objToLoad, bool fDryRun = false); -}; - - -// -// Governance Manager : Contains all proposals for the budget -// -class CGovernanceManager -{ // **** Objects and memory **** - -private: - - //hold txes until they mature enough to use - map mapCollateral; - // Keep track of current block index - const CBlockIndex *pCurrentBlockIndex; - -public: - // critical section to protect the inner data structures - mutable CCriticalSection cs; - - // hold governance objects (proposals, contracts, settings and switches) - std::map mapGovernanceObjects; - // finalized budgets are kept in their own object - // std::map mapFinalizedBudgets; - - std::map mapSeenGovernanceObjects; - std::map mapSeenGovernanceVotes; - std::map mapOrphanGovernanceVotes; - //std::map mapSeenFinalizedBudgets; - - // VOTES > - std::map > mapVotes; - - // **** Initialization **** - - CGovernanceManager() { - mapGovernanceObjects.clear(); - //mapFinalizedBudgets.clear(); - } - - void Clear(){ - LOCK(cs); - - LogPrintf("Governance object cleared\n"); - mapGovernanceObjects.clear(); - //mapFinalizedBudgets.clear(); - mapSeenGovernanceObjects.clear(); - mapSeenGovernanceVotes.clear(); - //mapSeenFinalizedBudgets.clear(); - mapOrphanGovernanceVotes.clear(); - } - - void ClearSeen() { - mapSeenGovernanceObjects.clear(); - mapSeenGovernanceVotes.clear(); - //mapSeenFinalizedBudgets.clear(); - } - - void Sync(CNode* node, uint256 nProp, bool fPartial=false); - void ResetSync(); - void MarkSynced(); - - // **** Search / Statistics / Information **** - - int CountProposalInventoryItems() { return mapSeenGovernanceObjects.size() + mapSeenGovernanceVotes.size(); } - //int CountFinalizedInventoryItems() { return mapSeenFinalizedBudgets.size(); } - - CGovernanceNode *FindGovernanceObject(const std::string &strName); - CGovernanceNode *FindGovernanceObject(uint256 nHash); - //CFinalizedBudget *FindFinalizedBudget(uint256 nHash); - GovernanceObjectType GetGovernanceTypeByHash(uint256 nHash); - std::vector GetBudget(); - CAmount GetTotalBudget(int nHeight); - bool HasNextFinalizedBudget(); // Do we have the next finalized budget? - bool IsBudgetPaymentBlock(int nBlockHeight); - bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); - - std::vector FindMatchingGovernanceObjects(GovernanceObjectType type); - //std::vector GetFinalizedBudgets(); - std::string GetRequiredPaymentsString(int nBlockHeight); - std::string ToString() const; - - // **** Update **** - - //bool AddFinalizedBudget(CFinalizedBudget& finalizedBudget); - bool AddGovernanceObject(CGovernanceNode& budgetProposal); - bool AddOrphanGovernanceVote(CGovernanceVote& vote, CNode* pfrom); - void CheckAndRemove(); - void CheckOrphanVotes(); - void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees); - void NewBlock(); - void SubmitFinalBudget(); - void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); - void UpdatedBlockTip(const CBlockIndex *pindex); - bool UpdateGovernanceObjectVotes(CGovernanceVote& vote, CNode* pfrom, std::string& strError); - - // **** Serializer **** - - ADD_SERIALIZE_METHODS; - - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - // READWRITE(mapSeenGovernanceObjects); - // READWRITE(mapSeenGovernanceVotes); - // //READWRITE(mapSeenFinalizedBudgets); - // READWRITE(mapOrphanGovernanceVotes); - - // READWRITE(mapGovernanceObjects); - // //READWRITE(mapFinalizedBudgets); - } - -}; - -// used purely for readablility -typedef std::vector signature; - -/* - * CGovernanceNode - * -------------------- - * - * This is the base class of the goverance system. - * -*/ - - -class CGovernanceNode -{ // **** Objects and memory **** - -private: - // critical section to protect the inner data structures - mutable CCriticalSection cs; - CAmount nAlloted; - -public: - bool fValid; - std::string strName; - - /* - BASE DATA that all governance objects have in common - */ - - int nGovernanceType; - int64_t nTime; - uint256 nFeeTXHash; - - // CATEGORY is mapped to the hash of a category node, see governance-categories.h - uint256 category; - - // SIGNATURES - std::vector vecSig; // USER SIGNATURE - - // CHILDREN NODES -- automatically sorted by votes desc - vector vecChildren; - - // **** v12.1 additions *** - - // //do we have sign off from the important nodes for this action - // bool IsChildValid(CGovernanceNode* child) - // { - // if(child->GetSignaturePubkey() == GetPubkey()) return true; - // } - - GovernanceObjectType GetType() - { - return (GovernanceObjectType)nGovernanceType; - } - - // **** Initialization **** - - CGovernanceNode(); - CGovernanceNode(const CGovernanceNode& other); - CGovernanceNode(UniValue obj); - - // **** Update **** - - //bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError); - void CleanAndRemove(bool fSignatureCheck); - bool HasMinimumRequiredSupport(); - - void SetAllotted(CAmount nAllotedIn) {nAlloted = nAllotedIn;} - void SetNull(); - bool SignKeySpace(int nKeySpace, CBitcoinSecret key); - - // **** Statistics / Information **** - - int GetAbsoluteYesCount(); - int GetAbstainCount(); - CAmount GetAllotted() {return nAlloted;} - - int GetBlockCurrentCycle(const CBlockIndex* pindex); - - GovernanceObjectType GetGovernanceType(); - std::string GetGovernanceTypeAsString(); - - int GetNoCount(); - int GetRemainingPaymentCount(int nBlockHeight); - double GetRatio(); - int GetTotalPaymentCount(); - int64_t GetValidEndTimestamp(); - int64_t GetValidStartTimestamp(); - int GetYesCount(); - - bool IsCategoryValid(); - bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); - bool IsEstablished(); - - virtual uint256 GetHash() - { - return uint256(); - } -}; - -/* - * Class : CGovernanceNodeBroadcast - * -------------------- - * Broadcasts have moved to governance-classes.h - * -*/ - -// Proposals are cast then sent to peers with this object, which leaves the votes out -// class CGovernanceNodeBroadcast : public CGovernanceNode +// /** Save Budget Manager (budget.dat) +// */ +// class CBudgetDB // { +// private: +// boost::filesystem::path pathDB; +// std::string strMagicMessage; // public: -// CGovernanceNodeBroadcast() : CGovernanceNode(){} -// CGovernanceNodeBroadcast(const CGovernanceNode& other) : CGovernanceNode(other){} -// CGovernanceNodeBroadcast(const CGovernanceNodeBroadcast& other) : CGovernanceNode(other){} +// enum ReadResult { +// Ok, +// FileError, +// HashReadError, +// IncorrectHash, +// IncorrectMagicMessage, +// IncorrectMagicNumber, +// IncorrectFormat +// }; -// void CreateProposalOrContract(GovernanceObjectType nTypeIn, std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); -// void CreateProposal(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); -// void CreateContract(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); -// void CreateSetting(std::string strNameIn, std::string strURLIn, std::string strSuggestedValueIn, uint256 nFeeTXHashIn); - -// void swap(CGovernanceNodeBroadcast& first, CGovernanceNodeBroadcast& second) // nothrow -// { -// // enable ADL (not necessary in our case, but good practice) -// using std::swap; - -// // by swapping the members of two classes, -// // the two classes are effectively swapped -// swap(first.nGovernanceType, second.nGovernanceType); -// swap(first.strName, second.strName); -// swap(first.nBlockStart, second.nBlockStart); -// swap(first.strURL, second.strURL); -// swap(first.nBlockEnd, second.nBlockEnd); -// swap(first.nAmount, second.nAmount); -// swap(first.address, second.address); -// swap(first.nTime, second.nTime); -// swap(first.nFeeTXHash, second.nFeeTXHash); -// swap(first.nGovernanceType, second.nGovernanceType); -// first.mapVotes.swap(second.mapVotes); -// } - -// CGovernanceNodeBroadcast& operator=(CGovernanceNodeBroadcast from) -// { -// swap(*this, from); -// return *this; -// } - -// void Relay(); +// CBudgetDB(); +// bool Write(const CGovernanceManager &objToSave); +// ReadResult Read(CGovernanceManager& objToLoad, bool fDryRun = false); // }; -#endif + +// // +// // Governance Manager : Contains all proposals for the budget +// // +// class CGovernanceManager +// { // **** Objects and memory **** + +// private: + +// //hold txes until they mature enough to use +// map mapCollateral; +// // Keep track of current block index +// const CBlockIndex *pCurrentBlockIndex; + +// public: +// // critical section to protect the inner data structures +// mutable CCriticalSection cs; + +// // hold governance objects (proposals, contracts, settings and switches) +// std::map mapGovernanceObjects; +// // finalized budgets are kept in their own object +// // std::map mapFinalizedBudgets; + +// std::map mapSeenGovernanceObjects; +// std::map mapSeenGovernanceVotes; +// std::map mapOrphanGovernanceVotes; +// //std::map mapSeenFinalizedBudgets; + +// // VOTES > +// std::map > mapVotes; + +// // **** Initialization **** + +// CGovernanceManager() { +// mapGovernanceObjects.clear(); +// //mapFinalizedBudgets.clear(); +// } + +// void Clear(){ +// LOCK(cs); + +// LogPrintf("Governance object cleared\n"); +// mapGovernanceObjects.clear(); +// //mapFinalizedBudgets.clear(); +// mapSeenGovernanceObjects.clear(); +// mapSeenGovernanceVotes.clear(); +// //mapSeenFinalizedBudgets.clear(); +// mapOrphanGovernanceVotes.clear(); +// } + +// void ClearSeen() { +// mapSeenGovernanceObjects.clear(); +// mapSeenGovernanceVotes.clear(); +// //mapSeenFinalizedBudgets.clear(); +// } + +// void Sync(CNode* node, uint256 nProp, bool fPartial=false); +// void ResetSync(); +// void MarkSynced(); + +// // **** Search / Statistics / Information **** + +// int CountProposalInventoryItems() { return mapSeenGovernanceObjects.size() + mapSeenGovernanceVotes.size(); } +// //int CountFinalizedInventoryItems() { return mapSeenFinalizedBudgets.size(); } + +// CGovernanceNode *FindGovernanceObject(const std::string &strName); +// CGovernanceNode *FindGovernanceObject(uint256 nHash); +// //CFinalizedBudget *FindFinalizedBudget(uint256 nHash); +// GovernanceObjectType GetGovernanceTypeByHash(uint256 nHash); +// std::vector GetBudget(); +// CAmount GetTotalBudget(int nHeight); +// bool HasNextFinalizedBudget(); // Do we have the next finalized budget? +// bool IsBudgetPaymentBlock(int nBlockHeight); +// bool IsTransactionValid(const CTransaction& txNew, int nBlockHeight); + +// std::vector FindMatchingGovernanceObjects(GovernanceObjectType type); +// //std::vector GetFinalizedBudgets(); +// std::string GetRequiredPaymentsString(int nBlockHeight); +// std::string ToString() const; + +// // **** Update **** + +// //bool AddFinalizedBudget(CFinalizedBudget& finalizedBudget); +// bool AddGovernanceObject(CGovernanceNode& budgetProposal); +// bool AddOrphanGovernanceVote(CGovernanceVote& vote, CNode* pfrom); +// void CheckAndRemove(); +// void CheckOrphanVotes(); +// void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees); +// void NewBlock(); +// void SubmitFinalBudget(); +// void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); +// void UpdatedBlockTip(const CBlockIndex *pindex); +// bool UpdateGovernanceObjectVotes(CGovernanceVote& vote, CNode* pfrom, std::string& strError); + +// // **** Serializer **** + +// ADD_SERIALIZE_METHODS; + +// template +// inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { +// // READWRITE(mapSeenGovernanceObjects); +// // READWRITE(mapSeenGovernanceVotes); +// // //READWRITE(mapSeenFinalizedBudgets); +// // READWRITE(mapOrphanGovernanceVotes); + +// // READWRITE(mapGovernanceObjects); +// // //READWRITE(mapFinalizedBudgets); +// } + +// }; + +// // used purely for readablility +// typedef std::vector signature; + +// /* +// * CGovernanceNode +// * -------------------- +// * +// * This is the base class of the goverance system. +// * +// */ + + +// class CGovernanceNode +// { // **** Objects and memory **** + +// private: +// // critical section to protect the inner data structures +// mutable CCriticalSection cs; +// CAmount nAlloted; + +// public: +// bool fValid; +// std::string strName; + +// /* +// BASE DATA that all governance objects have in common +// */ + +// int nGovernanceType; +// int64_t nTime; +// uint256 nFeeTXHash; + +// // CATEGORY is mapped to the hash of a category node, see governance-categories.h +// uint256 category; + +// // SIGNATURES +// std::vector vecSig; // USER SIGNATURE + +// // CHILDREN NODES -- automatically sorted by votes desc +// vector vecChildren; + +// // **** v12.1 additions *** + +// // //do we have sign off from the important nodes for this action +// // bool IsChildValid(CGovernanceNode* child) +// // { +// // if(child->GetSignaturePubkey() == GetPubkey()) return true; +// // } + +// GovernanceObjectType GetType() +// { +// return (GovernanceObjectType)nGovernanceType; +// } + +// // **** Initialization **** + +// CGovernanceNode(); +// CGovernanceNode(const CGovernanceNode& other); +// CGovernanceNode(UniValue obj); + +// // **** Update **** + +// //bool AddOrUpdateVote(CGovernanceVote& vote, std::string& strError); +// void CleanAndRemove(bool fSignatureCheck); +// bool HasMinimumRequiredSupport(); + +// void SetAllotted(CAmount nAllotedIn) {nAlloted = nAllotedIn;} +// void SetNull(); +// bool SignKeySpace(int nKeySpace, CBitcoinSecret key); + +// // **** Statistics / Information **** + +// int GetAbsoluteYesCount(); +// int GetAbstainCount(); +// CAmount GetAllotted() {return nAlloted;} + +// int GetBlockCurrentCycle(const CBlockIndex* pindex); + +// GovernanceObjectType GetGovernanceType(); +// std::string GetGovernanceTypeAsString(); + +// int GetNoCount(); +// int GetRemainingPaymentCount(int nBlockHeight); +// double GetRatio(); +// int GetTotalPaymentCount(); +// int64_t GetValidEndTimestamp(); +// int64_t GetValidStartTimestamp(); +// int GetYesCount(); + +// bool IsCategoryValid(); +// bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); +// bool IsEstablished(); + +// virtual uint256 GetHash() +// { +// return uint256(); +// } +// }; + +// /* +// * Class : CGovernanceNodeBroadcast +// * -------------------- +// * Broadcasts have moved to governance-classes.h +// * +// */ + +// // Proposals are cast then sent to peers with this object, which leaves the votes out +// // class CGovernanceNodeBroadcast : public CGovernanceNode +// // { +// // public: +// // CGovernanceNodeBroadcast() : CGovernanceNode(){} +// // CGovernanceNodeBroadcast(const CGovernanceNode& other) : CGovernanceNode(other){} +// // CGovernanceNodeBroadcast(const CGovernanceNodeBroadcast& other) : CGovernanceNode(other){} + +// // void CreateProposalOrContract(GovernanceObjectType nTypeIn, std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); +// // void CreateProposal(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); +// // void CreateContract(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); +// // void CreateSetting(std::string strNameIn, std::string strURLIn, std::string strSuggestedValueIn, uint256 nFeeTXHashIn); + +// // void swap(CGovernanceNodeBroadcast& first, CGovernanceNodeBroadcast& second) // nothrow +// // { +// // // enable ADL (not necessary in our case, but good practice) +// // using std::swap; + +// // // by swapping the members of two classes, +// // // the two classes are effectively swapped +// // swap(first.nGovernanceType, second.nGovernanceType); +// // swap(first.strName, second.strName); +// // swap(first.nBlockStart, second.nBlockStart); +// // swap(first.strURL, second.strURL); +// // swap(first.nBlockEnd, second.nBlockEnd); +// // swap(first.nAmount, second.nAmount); +// // swap(first.address, second.address); +// // swap(first.nTime, second.nTime); +// // swap(first.nFeeTXHash, second.nFeeTXHash); +// // swap(first.nGovernanceType, second.nGovernanceType); +// // first.mapVotes.swap(second.mapVotes); +// // } + +// // CGovernanceNodeBroadcast& operator=(CGovernanceNodeBroadcast from) +// // { +// // swap(*this, from); +// // return *this; +// // } + +// // void Relay(); +// // }; + +// #endif diff --git a/src/drafted/rpcgovernance.cpp b/src/drafted/rpcgovernance.cpp new file mode 100644 index 000000000..be1d3e51b --- /dev/null +++ b/src/drafted/rpcgovernance.cpp @@ -0,0 +1,1167 @@ +// // Copyright (c) 2014-2016 The Dash Core developers +// // Distributed under the MIT/X11 software license, see the accompanying +// // file COPYING or http://www.opensource.org/licenses/mit-license.php. + +// #include "main.h" +// #include "db.h" +// #include "init.h" +// #include "activemasternode.h" +// #include "governance.h" +// #include "masternode-payments.h" +// #include "masternode-sync.h" +// #include "masternodeconfig.h" +// #include "masternodeman.h" +// #include "governance.h" +// #include "governance-classes.h" +// #include "governance-types.h" +// #include "rpcserver.h" +// #include "utilmoneystr.h" +// #include + +// #include +// #include +// #include +// #include + +// using namespace std; + +// UniValue governance(const UniValue& params, bool fHelp) +// { +// string strCommand; +// if (params.size() >= 1) +// strCommand = params[0].get_str(); + +// if (fHelp || +// (strCommand != "sign" && strCommand != "create" && strCommand != "vote-once" && +// strCommand != "vote-many" && strCommand != "vote-alias" && strCommand != "list")) +// throw runtime_error( +// "governance \"command1\",\"command2\",\"command3\" ...\n" +// "Manage governance system\n" +// "\n See online documentation at http://govman.dash.org/\n" +// ); + + +// /* + +// governance sign {WITH-PUBKEY : pubkey, HASH: SIGN-HASH} // Sign a key as a company, user, group, etc + +// => {result = "success", "sig" : "SIGNATURE1", "signature-type": "user"} + +// governance create {parentHash: HASH, name:"proposal", sig1: SIGNATURE1, sig2: sig2.. } + +// => {result = "success", "hash" : "HASH1", "proposal-type": "generic", ...} + +// // WAIT 30 MINUTES + +// governance create {FEEHASH: HASH, parentHash: HASH, name:"proposal", sig1: sig1, sig2: sig2.. } + +// => {result = "success", "hash" : "HASH2", "proposal-type": "generic", ...} + +// governance (vote-once|vote-many) GOV_HASH_1 yes +// governance vote-alias MASTERNODE_NAME GOV_HASH_1 yes + +// // this is not meant to be readable, see http://www.github.com/dashpay/fetch for more info +// governance list + +// */ + + +// /* + +// { +// 'proof-of-destruction' : 'create', //or HASH +// 'valid' : true, +// 'name' : "Evan Duffield", + +// -- + +// 'type' : "proposal", +// // see governances-classes for mapping +// // CProposal lvl, proposal-type, status, status-error +// 'level' : "I", +// 'proposal-type' : "generic", +// 'status' : "ok", +// 'status-error' : "none", + +// 'time' : "now", +// 'fee-hash' : "hash1", +// 'parent-hash' : "hash2", + +// 'url' : "dashwhale.org/blah" +// 'when' : 'nextsuperblock+3 ? blockheight ?' + +// months +// amount +// payuser-by-name + +// } + +// CGovernanceObj obj(json); + +// if json['proof-of-destruction'] == "create": + +// // CWalletTx wtx; +// // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, budgetProposalBroadcast.GetHash(), useIX)){ +// // return "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."; +// // } + +// // // make our change address +// // CReserveKey reservekey(pwalletMain); +// // //send the tx to the network +// // pwalletMain->CommitTransaction(wtx, reservekey, useIX ? NetMsgType::IX : NetMsgType::TX); + +// // return wtx.GetHash().ToString(); + +// else: + +// if obj.IsValid() ? +// obj.Relay(); + + + +// */ +// // TODO: 12.1, organize these in order + + +// if(strCommand == "create") +// { +// UniValue govObjJson = params[1].get_obj(); + +// CGovernanceNode govObj; +// GovernanceObjectType govType = GovernanceStringToType(govObjJson["type"].get_str()); +// std::string strError = ""; + +// if(!CreateNewGovernanceObject(govObjJson, govObj, govType, strError)) +// { +// return strError; +// } + + +// if(govObjJson["create"].get_int() == 1) +// { + +// } else { + +// // if(govObj.IsCollateralValid()) +// // { +// // //Relay +// // } + +// // if(govObj.IsValid()) +// // { +// // //Relay +// // } +// } + +// } + +// // TODO: 12.1 +// // if(strCommand == "list") +// // { +// // return full json; //use fetch! +// // } + +// // if(strCommand == "sign") +// // { +// // string withPubkey = param(1); +// // string withSignHash = param(2); + +// // // option 1 +// // // return CGovernanceMananger::SignHashWithKey(withPubkey, withSignHash); + +// // obj = CGovernanceNode(json); +// // if(!obj.IsValid) +// // { +// // std::string strError = ""; +// // if(!obj.SignWithKeyByName(withPubkey, strError)) +// // { +// // return obj.ToJson(); +// // } +// // } +// // } + +// // if(strCommand == "prepare") +// // { + +// // /* + +// // governance prepare new {parentHash: HASH, name:"proposal", sig1: sig1, sig2: sig2.. } + +// // */ + +// // string strCommand2 = param(1) +// // UniValue obj(VOBJ) = param(2); + + +// // // if (params.size() != 7) +// // // throw runtime_error("Correct usage is 'proposal prepare '"); + +// // // int nBlockMin = 0; +// // // LOCK(cs_main); +// // // CBlockIndex* pindex = chainActive.Tip(); + +// // // std::vector mnEntries; +// // // mnEntries = masternodeConfig.getEntries(); + +// // // std::string strName = SanitizeString(params[1].get_str()); +// // // std::string strURL = SanitizeString(params[2].get_str()); +// // // int nPaymentCount = params[3].get_int(); +// // // int nBlockStart = params[4].get_int(); + +// // // //set block min +// // // if(pindex != NULL) nBlockMin = pindex->nHeight; + +// // // if(nBlockStart < nBlockMin) +// // // return "Invalid block start, must be more than current height."; + +// // // CBitcoinAddress address(params[5].get_str()); +// // // if (!address.IsValid()) +// // // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); + +// // // // Parse Dash address +// // // CScript scriptPubKey = GetScriptForDestination(address.Get()); +// // // CAmount nAmount = AmountFromValue(params[6]); + +// // // //************************************************************************* + +// // // // create transaction 15 minutes into the future, to allow for confirmation time +// // // CGovernanceNodeBroadcast budgetProposalBroadcast; +// // // budgetProposalBroadcast.CreateProposal(strName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, uint256()); + +// // // std::string strError = ""; +// // // if(!budgetProposalBroadcast.IsValid(pindex, strError, false)) +// // // return "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError; + +// // // bool useIX = false; //true; +// // // // if (params.size() > 7) { +// // // // if(params[7].get_str() != "false" && params[7].get_str() != "true") +// // // // return "Invalid use_ix, must be true or false"; +// // // // useIX = params[7].get_str() == "true" ? true : false; +// // // // } + +// // // CWalletTx wtx; +// // // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, budgetProposalBroadcast.GetHash(), useIX)){ +// // // return "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."; +// // // } + +// // // // make our change address +// // // CReserveKey reservekey(pwalletMain); +// // // //send the tx to the network +// // // pwalletMain->CommitTransaction(wtx, reservekey, useIX ? NetMsgType::IX : NetMsgType::TX); + +// // // return wtx.GetHash().ToString(); +// // } + +// // if(strCommand == "submit") +// // { +// // if (params.size() != 8) +// // throw runtime_error("Correct usage is 'proposal submit '"); + +// // if(!masternodeSync.IsBlockchainSynced()){ +// // return "Must wait for client to sync with masternode network. Try again in a minute or so."; +// // } + +// // int nBlockMin = 0; +// // LOCK(cs_main); +// // CBlockIndex* pindex = chainActive.Tip(); + +// // std::vector mnEntries; +// // mnEntries = masternodeConfig.getEntries(); + +// // std::string strName = SanitizeString(params[1].get_str()); +// // std::string strURL = SanitizeString(params[2].get_str()); +// // int nPaymentCount = params[3].get_int(); +// // int nBlockStart = params[4].get_int(); + +// // //set block min +// // if(pindex != NULL) nBlockMin = pindex->nHeight; + +// // if(nBlockStart < nBlockMin) +// // return "Invalid payment count, must be more than current height."; + +// // CBitcoinAddress address(params[5].get_str()); +// // if (!address.IsValid()) +// // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); + +// // // Parse Dash address +// // CScript scriptPubKey = GetScriptForDestination(address.Get()); +// // CAmount nAmount = AmountFromValue(params[6]); +// // uint256 hash = ParseHashV(params[7], "Proposal hash"); + +// // //create the proposal incase we're the first to make it +// // CGovernanceNodeBroadcast budgetProposalBroadcast; +// // budgetProposalBroadcast.CreateProposal(strName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash); + +// // std::string strError = ""; + +// // if(!budgetProposalBroadcast.IsValid(pindex, strError)){ +// // return "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError; +// // } + +// // int nConf = 0; +// // if(!IsCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf, GOVERNANCE_FEE_TX)){ +// // return "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError; +// // } + +// // govman.mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast)); +// // budgetProposalBroadcast.Relay(); +// // govman.AddGovernanceObject(budgetProposalBroadcast); + +// // return budgetProposalBroadcast.GetHash().ToString(); + +// // } + +// // if(strCommand == "list") +// // { +// // if (params.size() > 2) +// // throw runtime_error("Correct usage is 'proposal list [valid|all|extended]'"); + +// // std::string strShow = "valid"; +// // if (params.size() == 2) strShow = params[1].get_str(); + +// // CBlockIndex* pindex; +// // { +// // LOCK(cs_main); +// // pindex = chainActive.Tip(); +// // } + +// // UniValue resultObj(UniValue::VOBJ); +// // int64_t nTotalAllotted = 0; + +// // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); +// // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) +// // { +// // if(strShow == "valid" && !pbudgetProposal->fValid) continue; + +// // nTotalAllotted += pbudgetProposal->GetAllotted(); + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // UniValue bObj(UniValue::VOBJ); +// // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); + +// // if(strShow == "extended") bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); +// // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); + +// // if(strShow == "extended") +// // { +// // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); +// // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); +// // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); +// // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); +// // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); +// // bObj.push_back(Pair("PaymentAddress", address2.ToString())); +// // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); +// // } + +// // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); +// // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); +// // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); + +// // if(strShow == "extended") +// // { +// // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); +// // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); +// // } + +// // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); + +// // if(strShow == "extended") +// // { +// // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); + +// // std::string strError = ""; +// // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); +// // bObj.push_back(Pair("IsValidReason", strError.c_str())); +// // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); +// // } + +// // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); +// // } + +// // return resultObj; +// // } + +// // if(strCommand == "get") +// // { +// // if (params.size() != 2) +// // throw runtime_error("Correct usage is 'proposal get '"); + +// // uint256 hash = ParseHashV(params[1], "Proposal hash"); + +// // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(hash); + +// // if(pbudgetProposal == NULL) return "Unknown proposal"; + +// // CBlockIndex* pindex; +// // { +// // LOCK(cs_main); +// // pindex = chainActive.Tip(); +// // } + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // LOCK(cs_main); +// // UniValue obj(UniValue::VOBJ); +// // obj.push_back(Pair("Name", pbudgetProposal->GetName())); +// // obj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); +// // obj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); +// // obj.push_back(Pair("URL", pbudgetProposal->GetURL())); +// // obj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); +// // obj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); +// // obj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); +// // obj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); +// // obj.push_back(Pair("PaymentAddress", address2.ToString())); +// // obj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); +// // obj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); +// // obj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); +// // obj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); +// // obj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); +// // obj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); +// // obj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); + +// // obj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); + +// // std::string strError = ""; +// // obj.push_back(Pair("IsValid", pbudgetProposal->IsValid(chainActive.Tip(), strError))); +// // obj.push_back(Pair("fValid", pbudgetProposal->fValid)); + +// // return obj; +// // } + + +// // if(strCommand == "gethash") +// // { +// // if (params.size() != 2) +// // throw runtime_error("Correct usage is 'proposal gethash '"); + +// // std::string strName = SanitizeString(params[1].get_str()); + +// // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(strName); + +// // if(pbudgetProposal == NULL) return "Unknown proposal"; + +// // UniValue resultObj(UniValue::VOBJ); + +// // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); +// // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) +// // { +// // if(pbudgetProposal->GetName() != strName) continue; +// // if(!pbudgetProposal->fValid) continue; + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // resultObj.push_back(Pair(pbudgetProposal->GetHash().ToString(), pbudgetProposal->GetHash().ToString())); +// // } + +// // if(resultObj.size() > 1) return resultObj; + +// // return pbudgetProposal->GetHash().ToString(); +// // } + +// return NullUniValue; +// } + +// UniValue contract(const UniValue& params, bool fHelp) +// { +// string strCommand; +// if (params.size() >= 1) +// strCommand = params[0].get_str(); + +// if (fHelp || +// (strCommand != "prepare" && strCommand != "submit" && +// strCommand != "get" && strCommand != "gethash" && strCommand != "list")) +// throw runtime_error( +// "contract \"command\"...\n" +// "Manage contracts\n" +// "\nAvailable commands:\n" +// " prepare - Prepare contract by signing and creating tx\n" +// " submit - Submit contract to network\n" +// " list - List all contracts\n" +// " get - get contract\n" +// " gethash - Get contract hash(es) by contract name\n" +// ); + +// // if(strCommand == "prepare") +// // { +// // if (params.size() != 7) +// // throw runtime_error("Correct usage is 'contract prepare '"); + +// // int nBlockMin = 0; +// // LOCK(cs_main); +// // CBlockIndex* pindex = chainActive.Tip(); + +// // std::vector mnEntries; +// // mnEntries = masternodeConfig.getEntries(); + +// // std::string strName = SanitizeString(params[1].get_str()); +// // std::string strURL = SanitizeString(params[2].get_str()); +// // int nMonthCount = params[3].get_int(); +// // int nBlockStart = params[4].get_int(); + +// // //set block min +// // if(pindex != NULL) nBlockMin = pindex->nHeight; + +// // if(nBlockStart < nBlockMin) +// // return "Invalid block start, must be more than current height."; + +// // CBitcoinAddress address(params[5].get_str()); +// // if (!address.IsValid()) +// // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); + +// // // Parse Dash address +// // CScript scriptPubKey = GetScriptForDestination(address.Get()); +// // CAmount nAmount = AmountFromValue(params[6]); + +// // //************************************************************************* + +// // // create transaction 15 minutes into the future, to allow for confirmation time +// // CGovernanceNodeBroadcast contract; +// // contract.CreateContract(strName, strURL, nMonthCount, scriptPubKey, nAmount, nBlockStart, uint256()); + +// // std::string strError = ""; +// // if(!contract.IsValid(pindex, strError, false)) +// // return "Contract is not valid - " + contract.GetHash().ToString() + " - " + strError; + +// // CWalletTx wtx; +// // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, contract.GetHash(), false)){ +// // return "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."; +// // } + +// // // make our change address +// // CReserveKey reservekey(pwalletMain); +// // //send the tx to the network +// // pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::TX); + +// // return wtx.GetHash().ToString(); +// // } + +// // if(strCommand == "submit") +// // { +// // if (params.size() != 8) +// // throw runtime_error("Correct usage is 'contract submit '"); + +// // if(!masternodeSync.IsBlockchainSynced()){ +// // return "Must wait for client to sync with masternode network. Try again in a minute or so."; +// // } + +// // int nBlockMin = 0; +// // LOCK(cs_main); +// // CBlockIndex* pindex = chainActive.Tip(); + +// // std::vector mnEntries; +// // mnEntries = masternodeConfig.getEntries(); + +// // std::string strName = SanitizeString(params[1].get_str()); +// // std::string strURL = SanitizeString(params[2].get_str()); +// // int nPaymentCount = params[3].get_int(); +// // int nBlockStart = params[4].get_int(); + +// // //set block min +// // if(pindex != NULL) nBlockMin = pindex->nHeight; + +// // if(nBlockStart < nBlockMin) +// // return "Invalid payment count, must be more than current height."; + +// // CBitcoinAddress address(params[5].get_str()); +// // if (!address.IsValid()) +// // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); + +// // // Parse Dash address +// // CScript scriptPubKey = GetScriptForDestination(address.Get()); +// // CAmount nAmount = AmountFromValue(params[6]); +// // uint256 hash = ParseHashV(params[7], "Contract hash"); + +// // //create the contract incase we're the first to make it +// // CGovernanceNodeBroadcast contractBroadcast; +// // contractBroadcast.CreateContract(strName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash); + +// // std::string strError = ""; + +// // if(!contractBroadcast.IsValid(pindex, strError)){ +// // return "Contract is not valid - " + contractBroadcast.GetHash().ToString() + " - " + strError; +// // } + +// // int nConf = 0; +// // if(!IsCollateralValid(hash, contractBroadcast.GetHash(), strError, contractBroadcast.nTime, nConf, GOVERNANCE_FEE_TX)){ +// // return "Contract FeeTX is not valid - " + hash.ToString() + " - " + strError; +// // } + +// // govman.mapSeenGovernanceObjects.insert(make_pair(contractBroadcast.GetHash(), contractBroadcast)); +// // contractBroadcast.Relay(); +// // govman.AddGovernanceObject(contractBroadcast); + +// // return contractBroadcast.GetHash().ToString(); + +// // } + +// // if(strCommand == "list") +// // { +// // if (params.size() > 2) +// // throw runtime_error("Correct usage is 'proposal list [valid]'"); + +// // std::string strShow = "valid"; +// // if (params.size() == 2) strShow = params[1].get_str(); + +// // CBlockIndex* pindex; +// // { +// // LOCK(cs_main); +// // pindex = chainActive.Tip(); +// // } + +// // UniValue resultObj(UniValue::VOBJ); +// // int64_t nTotalAllotted = 0; + +// // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); +// // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) +// // { +// // if(strShow == "valid" && !pbudgetProposal->fValid) continue; + +// // nTotalAllotted += pbudgetProposal->GetAllotted(); + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // UniValue bObj(UniValue::VOBJ); +// // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); +// // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); +// // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); +// // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); +// // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); +// // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); +// // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); +// // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); +// // bObj.push_back(Pair("PaymentAddress", address2.ToString())); +// // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); +// // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); +// // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); +// // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); +// // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); +// // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); +// // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); + +// // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); + +// // std::string strError = ""; +// // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); +// // bObj.push_back(Pair("IsValidReason", strError.c_str())); +// // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); + +// // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); +// // } + +// // return resultObj; +// // } + +// // if(strCommand == "get") +// // { +// // if (params.size() != 2) +// // throw runtime_error("Correct usage is 'proposal get '"); + +// // uint256 hash = ParseHashV(params[1], "Proposal hash"); + +// // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(hash); + +// // if(pbudgetProposal == NULL) return "Unknown proposal"; + +// // CBlockIndex* pindex; +// // { +// // LOCK(cs_main); +// // pindex = chainActive.Tip(); +// // } + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // LOCK(cs_main); +// // UniValue obj(UniValue::VOBJ); +// // obj.push_back(Pair("Name", pbudgetProposal->GetName())); +// // obj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); +// // obj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); +// // obj.push_back(Pair("URL", pbudgetProposal->GetURL())); +// // obj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); +// // obj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); +// // obj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); +// // obj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); +// // obj.push_back(Pair("PaymentAddress", address2.ToString())); +// // obj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); +// // obj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); +// // obj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); +// // obj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); +// // obj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); +// // obj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); +// // obj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); + +// // obj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); + +// // std::string strError = ""; +// // obj.push_back(Pair("IsValid", pbudgetProposal->IsValid(chainActive.Tip(), strError))); +// // obj.push_back(Pair("fValid", pbudgetProposal->fValid)); + +// // return obj; +// // } + + +// // if(strCommand == "gethash") +// // { +// // if (params.size() != 2) +// // throw runtime_error("Correct usage is 'proposal gethash '"); + +// // std::string strName = SanitizeString(params[1].get_str()); + +// // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(strName); + +// // if(pbudgetProposal == NULL) return "Unknown proposal"; + +// // UniValue resultObj(UniValue::VOBJ); + +// // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); +// // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) +// // { +// // if(pbudgetProposal->GetName() != strName) continue; +// // if(!pbudgetProposal->fValid) continue; + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // resultObj.push_back(Pair(pbudgetProposal->GetHash().ToString(), pbudgetProposal->GetHash().ToString())); +// // } + +// // if(resultObj.size() > 1) return resultObj; + +// // return pbudgetProposal->GetHash().ToString(); +// // } + +// return NullUniValue; +// } + +// UniValue budget(const UniValue& params, bool fHelp) +// { +// string strCommand; +// if (params.size() >= 1) +// strCommand = params[0].get_str(); +// string strSubCommand; +// if (params.size() >= 2) +// strSubCommand = params[1].get_str(); + +// if (fHelp || +// (strCommand != "check" && strCommand != "get" && strCommand != "all" && +// strCommand != "valid" && strCommand != "extended" && strCommand != "projection")) +// throw runtime_error( +// "budget \"command\"...\n" +// "Manage proposals\n" +// "\nAvailable commands:\n" +// " check - Scan proposals and remove invalid from proposals list\n" +// " get - Get a proposals|contract by hash\n" +// " list - Get all proposals (all|valid|extended)\n" +// " projection - Show the projection of which proposals will be paid the next superblocks\n" +// ); + +// // help messages +// if(strSubCommand == "help") +// { +// if(strCommand == "list") +// { +// throw runtime_error( +// "budget \"list\"...\n" +// "List all budgets in various configurations\n" +// "\nAvailable commands:\n" +// " all - Show all proposed settings for the network\n" +// " valid - Show only valid settings for the network\n" +// " extended - Show extended information about all settings\n" +// " active - Show active values for each network setting\n" +// ); +// } +// } + +// // if(strCommand == "check") +// // { +// // govman.CheckAndRemove(); + +// // return "Success"; +// // } + +// // if(strCommand == "projection") +// // { +// // CBlockIndex* pindex; +// // { +// // LOCK(cs_main); +// // pindex = chainActive.Tip(); +// // } + +// // UniValue resultObj(UniValue::VOBJ); +// // CAmount nTotalAllotted = 0; + +// // std::vector winningProps = govman.GetBudget(); +// // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) +// // { +// // nTotalAllotted += pbudgetProposal->GetAllotted(); + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // UniValue bObj(UniValue::VOBJ); +// // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); +// // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); +// // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); +// // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); +// // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); +// // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); +// // bObj.push_back(Pair("PaymentAddress", address2.ToString())); +// // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); +// // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); +// // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); +// // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); +// // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); +// // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); +// // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); +// // bObj.push_back(Pair("Alloted", ValueFromAmount(pbudgetProposal->GetAllotted()))); + +// // std::string strError = ""; +// // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); +// // bObj.push_back(Pair("IsValidReason", strError.c_str())); +// // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); + +// // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); +// // } +// // resultObj.push_back(Pair("TotalBudgetAlloted", ValueFromAmount(nTotalAllotted))); + +// // return resultObj; +// // } + +// // if(strCommand == "get") +// // { +// // uint256 nMatchHash = uint256(); +// // std::string strMatchName = ""; + +// // if (IsHex(params[1].get_str())) +// // { +// // nMatchHash = ParseHashV(params[1], "GovObj hash"); +// // } else { +// // strMatchName = params[1].get_str(); +// // } + +// // CBlockIndex* pindex; +// // { +// // LOCK(cs_main); +// // pindex = chainActive.Tip(); +// // } + +// // UniValue resultObj(UniValue::VOBJ); +// // int64_t nTotalAllotted = 0; + +// // std::vector winningProps = govman.FindMatchingGovernanceObjects(AllTypes); + +// // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) +// // { +// // if(pbudgetProposal->GetName() != strMatchName && pbudgetProposal->GetHash() != nMatchHash) continue; + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // UniValue bObj(UniValue::VOBJ); +// // bObj.push_back(Pair("Type", pbudgetProposal->GetGovernanceTypeAsString())); +// // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); +// // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); +// // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); +// // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); +// // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); +// // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); +// // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); +// // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); +// // bObj.push_back(Pair("PaymentAddress", address2.ToString())); +// // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); +// // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); +// // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); +// // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); + +// // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); +// // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); + +// // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); +// // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); + +// // std::string strError = ""; +// // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); +// // bObj.push_back(Pair("IsValidReason", strError.c_str())); +// // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); + +// // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); +// // } + +// // return resultObj; +// // } + +// // if(strCommand == "all" || strCommand == "valid" || strCommand == "extended") +// // { + +// // CBlockIndex* pindex; +// // { +// // LOCK(cs_main); +// // pindex = chainActive.Tip(); +// // } + +// // UniValue resultObj(UniValue::VOBJ); +// // int64_t nTotalAllotted = 0; + +// // std::vector winningProps = govman.FindMatchingGovernanceObjects(AllTypes); + +// // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) +// // { +// // if(strCommand == "valid" && !pbudgetProposal->fValid) continue; + +// // nTotalAllotted += pbudgetProposal->GetAllotted(); + +// // CTxDestination address1; +// // ExtractDestination(pbudgetProposal->GetPayee(), address1); +// // CBitcoinAddress address2(address1); + +// // UniValue bObj(UniValue::VOBJ); +// // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); + +// // if(strCommand == "extended") +// // { +// // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); +// // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); +// // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); +// // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); +// // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); +// // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); +// // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); +// // bObj.push_back(Pair("PaymentAddress", address2.ToString())); +// // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); +// // } + +// // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); +// // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); +// // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); + +// // if(strCommand == "extended") +// // { +// // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); +// // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); +// // } + +// // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); +// // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); + +// // if(strCommand == "extended") +// // { +// // std::string strError = ""; +// // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); +// // bObj.push_back(Pair("IsValidReason", strError.c_str())); +// // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); +// // } + +// // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); +// // } + +// // return resultObj; +// // } + +// return NullUniValue; +// } + +// UniValue superblock(const UniValue& params, bool fHelp) +// { +// string strCommand; +// if (params.size() >= 1) +// strCommand = params[0].get_str(); + +// if (fHelp || +// (strCommand != "vote-many" && strCommand != "vote" && strCommand != "show" && strCommand != "getvotes" && strCommand != "prepare" && strCommand != "submit")) +// throw runtime_error( +// "superblock \"command\"...\n" +// "Get information about the next superblocks\n" +// "\nAvailable commands:\n" +// " info - Get info about the next superblock\n" +// " getvotes - Get vote information for each finalized budget\n" +// " prepare - Manually prepare a finalized budget\n" +// " submit - Manually submit a finalized budget\n" +// ); + + +// // if(strCommand == "nextblock") +// // { +// // LOCK(cs_main); +// // CBlockIndex* pindex = chainActive.Tip(); +// // if(!pindex) return "unknown"; + +// // int nNext = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; +// // return nNext; +// // } + +// // if(strCommand == "nextsuperblocksize") +// // { +// // LOCK(cs_main); +// // CBlockIndex* pindex = chainActive.Tip(); +// // if(!pindex) return "unknown"; + +// // int nHeight = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; + +// // CAmount nTotal = govman.GetTotalBudget(nHeight); +// // return nTotal; +// // } + +// // if(strCommand == "get") +// // { +// // UniValue resultObj(UniValue::VOBJ); + +// // std::vector winningFbs = govman.GetFinalizedBudgets(); +// // LOCK(cs_main); +// // BOOST_FOREACH(CFinalizedBudget* finalizedBudget, winningFbs) +// // { +// // UniValue bObj(UniValue::VOBJ); +// // bObj.push_back(Pair("FeeTX", finalizedBudget->nFeeTXHash.ToString())); +// // bObj.push_back(Pair("Hash", finalizedBudget->GetHash().ToString())); +// // bObj.push_back(Pair("BlockStart", (int64_t)finalizedBudget->GetBlockStart())); +// // bObj.push_back(Pair("BlockEnd", (int64_t)finalizedBudget->GetBlockEnd())); +// // bObj.push_back(Pair("Proposals", finalizedBudget->GetProposals())); +// // bObj.push_back(Pair("VoteCount", (int64_t)finalizedBudget->GetVoteCount())); +// // bObj.push_back(Pair("Status", finalizedBudget->GetStatus())); + +// // std::string strError = ""; +// // bObj.push_back(Pair("IsValid", finalizedBudget->IsValid(chainActive.Tip(), strError))); +// // bObj.push_back(Pair("IsValidReason", strError.c_str())); + +// // resultObj.push_back(Pair(finalizedBudget->GetName(), bObj)); +// // } + +// // return resultObj; + +// // } + +// // /* TODO +// // Switch the preparation to a public key which the core team has +// // The budget should be able to be created by any high up core team member then voted on by the network separately. +// // */ + +// // if(strCommand == "prepare") +// // { +// // if (params.size() != 2) +// // throw runtime_error("Correct usage is 'mnfinalbudget prepare comma-separated-hashes'"); + +// // std::string strHashes = params[1].get_str(); +// // std::istringstream ss(strHashes); +// // std::string token; + +// // std::vector vecTxBudgetPayments; + +// // while(std::getline(ss, token, ',')) { +// // uint256 nHash = uint256S(token); +// // CGovernanceNode* prop = govman.FindGovernanceObject(nHash); + +// // CTxBudgetPayment txBudgetPayment; +// // txBudgetPayment.nProposalHash = prop->GetHash(); +// // txBudgetPayment.payee = prop->GetPayee(); +// // txBudgetPayment.nAmount = prop->GetAllotted(); +// // vecTxBudgetPayments.push_back(txBudgetPayment); +// // } + +// // if(vecTxBudgetPayments.size() < 1) { +// // return "Invalid finalized proposal"; +// // } + +// // LOCK(cs_main); +// // CBlockIndex* pindex = chainActive.Tip(); +// // if(!pindex) return "invalid chaintip"; + +// // int nBlockStart = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; + +// // CFinalizedBudget tempBudget("main", nBlockStart, vecTxBudgetPayments, uint256()); +// // // if(mapSeenFinalizedBudgets.count(tempBudget.GetHash())) { +// // // return "already exists"; //already exists +// // // } + +// // //create fee tx +// // CTransaction tx; + +// // CWalletTx wtx; +// // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, tempBudget.GetHash(), false)){ +// // printf("Can't make collateral transaction\n"); +// // return "can't make colateral tx"; +// // } + +// // // make our change address +// // CReserveKey reservekey(pwalletMain); +// // //send the tx to the network +// // pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::IX); + +// // return wtx.GetHash().ToString(); +// // } + +// // if(strCommand == "submit") +// // { +// // if (params.size() != 3) +// // throw runtime_error("Correct usage is 'mnfinalbudget submit comma-separated-hashes collateralhash'"); + +// // std::string strHashes = params[1].get_str(); +// // std::istringstream ss(strHashes); +// // std::string token; + +// // std::vector vecTxBudgetPayments; + +// // uint256 nColHash = uint256S(params[2].get_str()); + +// // while(std::getline(ss, token, ',')) { +// // uint256 nHash = uint256S(token); +// // CGovernanceNode* prop = govman.FindGovernanceObject(nHash); + +// // CTxBudgetPayment txBudgetPayment; +// // txBudgetPayment.nProposalHash = prop->GetHash(); +// // txBudgetPayment.payee = prop->GetPayee(); +// // txBudgetPayment.nAmount = prop->GetAllotted(); +// // vecTxBudgetPayments.push_back(txBudgetPayment); + +// // printf("%lld\n", txBudgetPayment.nAmount); +// // } + +// // if(vecTxBudgetPayments.size() < 1) { +// // return "Invalid finalized proposal"; +// // } + +// // LOCK(cs_main); +// // CBlockIndex* pindex = chainActive.Tip(); +// // if(!pindex) return "invalid chaintip"; + +// // int nBlockStart = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; + +// // // CTxIn in(COutPoint(nColHash, 0)); +// // // int conf = GetInputAgeIX(nColHash, in); + +// // // Wait will we have 1 extra confirmation, otherwise some clients might reject this feeTX +// // // -- This function is tied to NewBlock, so we will propagate this budget while the block is also propagating + +// // // if(conf < BUDGET_FEE_CONFIRMATIONS+1){ +// // // printf ("Collateral requires at least %d confirmations - %s - %d confirmations\n", BUDGET_FEE_CONFIRMATIONS, nColHash.ToString().c_str(), conf); +// // // return "invalid collateral"; +// // // } + +// // //create the proposal incase we're the first to make it +// // CFinalizedBudget finalizedBudgetBroadcast("main", nBlockStart, vecTxBudgetPayments, nColHash); + +// // std::string strError = ""; +// // if(!finalizedBudgetBroadcast.IsValid(pindex, strError)){ +// // printf("CGovernanceManager::SubmitFinalBudget - Invalid finalized budget - %s \n", strError.c_str()); +// // return "invalid finalized budget"; +// // } + +// // finalizedBudgetBroadcast.Relay(); +// // govman.AddFinalizedBudget(finalizedBudgetBroadcast); + +// // return finalizedBudgetBroadcast.GetHash().ToString(); +// // } + +// return NullUniValue; +// } diff --git a/src/governance.cpp b/src/governance.cpp index fc8088e6e..623bf0910 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -529,8 +529,8 @@ bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strErro CBudgetProposal::CBudgetProposal() { strProposalName = "unknown"; - nBlockStart = 0; - nBlockEnd = 0; + nStartTime = 0; + nEndTime = 0; nAmount = 0; nTime = 0; fValid = true; @@ -540,8 +540,8 @@ CBudgetProposal::CBudgetProposal(const CBudgetProposal& other) { strProposalName = other.strProposalName; strURL = other.strURL; - nBlockStart = other.nBlockStart; - nBlockEnd = other.nBlockEnd; + nStartTime = other.nStartTime; + nEndTime = other.nEndTime; address = other.address; nAmount = other.nAmount; nTime = other.nTime; @@ -549,20 +549,14 @@ 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) +CBudgetProposal::CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn) { strProposalName = strProposalNameIn; strURL = strURLIn; - - nBlockStart = nBlockStartIn; - - int nPaymentsStart = nBlockStart - nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks; - //calculate the end of the cycle for this vote, add half a cycle (vote will be deleted after that block) - nBlockEnd = nPaymentsStart + Params().GetConsensus().nBudgetPaymentsCycleBlocks * nPaymentCount; - + nStartTime = nStartTimeIn; + nEndTime = nEndTimeIn; address = addressIn; nAmount = nAmountIn; - nFeeTXHash = nFeeTXHashIn; } @@ -573,8 +567,8 @@ bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError, return false; } - if(nBlockStart < 0) { - strError = "Invalid Proposal"; + if(nEndTime < GetTime()) { + strError = "Expired Proposal"; return false; } @@ -583,24 +577,8 @@ bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError, return true; } - if(nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks != 0){ - int nNext = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - strError = strprintf("Invalid block start - must be a budget cycle block. Next valid block: %d", nNext); - return false; - } - - if(nBlockEnd % Params().GetConsensus().nBudgetPaymentsCycleBlocks != Params().GetConsensus().nBudgetPaymentsCycleBlocks/2){ - strError = "Invalid block end"; - return false; - } - - if(nBlockEnd < nBlockStart) { - strError = "Invalid block end - must be greater then block start."; - return false; - } - - if(nAmount < 1*COIN) { - strError = "Invalid proposal amount"; + if(nAmount < 10000) { + strError = "Invalid proposal amount (minimum 10000)"; return false; } @@ -614,7 +592,7 @@ bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError, return false; } - if(strURL.size() > 64) { + if(strURL.size() > 100) { strError = "Invalid proposal url, limit of 64 characters."; return false; } @@ -659,18 +637,12 @@ bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError, return false; } - // todo 12.1 - setup a hard limit via spork or something? Maybe up to 1/4 of the total budget? - //can only pay out 10% of the possible coins (min value of coins) - if(nAmount > budget.GetTotalBudget(nBlockStart)) { - strError = "Payment more than max"; - return false; - } - - //* - //nAmount can be - and +, allows increasing budget dynamically. This is R&D mode - //* - - if(GetBlockEnd() + Params().GetConsensus().nBudgetPaymentsWindowBlocks < pindex->nHeight) return false; + // 12.1 move to pybrain + // //can only pay out 10% of the possible coins (min value of coins) + // if(nAmount > budget.GetTotalBudget(nBlockStart)) { + // strError = "Payment more than max"; + // return false; + // } return true; } @@ -731,7 +703,7 @@ void CGovernanceManager::CleanAndRemove(bool fSignatureCheck) int CBudgetProposal::GetAbsoluteYesCount() { - return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_YES) - governance.governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_NO); + return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_YES) - governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_NO); } int CBudgetProposal::GetYesCount() @@ -749,22 +721,6 @@ int CBudgetProposal::GetAbstainCount() return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_ABSTAIN); } -int CBudgetProposal::GetBlockStartCycle() -{ - //end block is half way through the next cycle (so the proposal will be removed much after the payment is sent) - - return nBlockStart - nBlockStart % Params().GetConsensus().nBudgetPaymentsCycleBlocks; -} - -int CBudgetProposal::GetBlockCurrentCycle(const CBlockIndex* pindex) -{ - if(!pindex) return -1; - - if(pindex->nHeight >= GetBlockEndCycle()) return -1; - - return pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks; -} - void CBudgetProposal::Relay() { CInv inv(MSG_BUDGET_PROPOSAL, GetHash()); @@ -791,76 +747,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex) NewBlock(); } -// 12.1 - add Priority sorting, add NetworkWillPay -std::vector CBudgetManager::GetBudget() -{ - LOCK(cs); - - // ------- Sort budgets by Yes Count - - std::vector > vBudgetPorposalsSort; - - std::map::iterator it = governance.mapProposals.begin(); - while(it != governance.mapProposals.end()){ - (*it).second.CleanAndRemove(false); - vBudgetPorposalsSort.push_back(make_pair(&((*it).second), (*it).second.GetYesCount()-(*it).second.GetNoCount())); - ++it; - } - - // 12.1 -- add priority - std::sort(vBudgetPorposalsSort.begin(), vBudgetPorposalsSort.end(), sortProposalsByVotes()); - - // ------- Grab The Budgets In Order - - std::vector vBudgetProposalsRet; - - CAmount nBudgetAllocated = 0; - if(!pCurrentBlockIndex) return vBudgetProposalsRet; - - int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - int nBlockEnd = nBlockStart + Params().GetConsensus().nBudgetPaymentsWindowBlocks; - CAmount nTotalBudget = GetTotalBudget(nBlockStart); - - - std::vector >::iterator it2 = vBudgetPorposalsSort.begin(); - while(it2 != vBudgetPorposalsSort.end()) - { - CBudgetProposal* pbudgetProposal = (*it2).first; - - // 12.1 - skip if NetworkWillPay == false - - - printf("-> Budget Name : %s\n", pbudgetProposal->strProposalName.c_str()); - printf("------- 1 : %d\n", pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart); - printf("------- 2 : %d\n", pbudgetProposal->nBlockEnd >= nBlockEnd); - printf("------- 3 : %d\n", pbudgetProposal->GetYesCount() - pbudgetProposal->GetNoCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10); - printf("------- 4 : %d\n", pbudgetProposal->IsEstablished()); - - //prop start/end should be inside this period - if(pbudgetProposal->fValid && pbudgetProposal->nBlockStart <= nBlockStart && - pbudgetProposal->nBlockEnd >= nBlockEnd && - pbudgetProposal->GetYesCount() - pbudgetProposal->GetNoCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10 && - pbudgetProposal->IsEstablished()) - { - printf("------- In range \n"); - - if(pbudgetProposal->GetAmount() + nBudgetAllocated <= nTotalBudget) { - pbudgetProposal->SetAllotted(pbudgetProposal->GetAmount()); - nBudgetAllocated += pbudgetProposal->GetAmount(); - vBudgetProposalsRet.push_back(pbudgetProposal); - printf("------- YES \n"); - } else { - pbudgetProposal->SetAllotted(0); - } - } - - ++it2; - } - - return vBudgetProposalsRet; -} - -int CBudgetManager::CountMatchingVotes(int nVoteTypeIn, int nVoteOutcomeIn) +int CGovernanceManager::CountMatchingVotes(int nVoteTypeIn, int nVoteOutcomeIn) { /* * @@ -875,7 +762,7 @@ int CBudgetManager::CountMatchingVotes(int nVoteTypeIn, int nVoteOutcomeIn) std::map::iterator it3 = mapVotes[(*it2).first].begin(); while(it3 != mapVotes[(*it2).first].end()) { - if(!(*it3).second.IsValid(fSignatureCheck)) + if(!(*it3).second.IsValid(true)) { if((*it3).second.nVoteType == nVoteTypeIn && (*it3).second.nVoteOutcome == nVoteOutcomeIn) diff --git a/src/governance.h b/src/governance.h index e8880e803..b5f21cb8e 100644 --- a/src/governance.h +++ b/src/governance.h @@ -93,12 +93,10 @@ public: CBudgetProposal *FindProposal(const std::string &strProposalName); CBudgetProposal *FindProposal(uint256 nHash); - std::vector GetBudget(); std::vector GetAllProposals(); bool IsBudgetPaymentBlock(int nBlockHeight); bool AddProposal(CBudgetProposal& budgetProposal); - bool UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::string& strError); bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError); bool PropExists(uint256 nHash); @@ -201,10 +199,9 @@ public: CBudgetProposal(); CBudgetProposal(const CBudgetProposal& other); - CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn); + CBudgetProposal(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn); bool HasMinimumRequiredSupport(); - bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true); bool IsEstablished(); bool NetworkWillPay(); @@ -214,7 +211,7 @@ public: int GetStartTime() {return nStartTime;} int GetEndTime() {return nEndTime;} CScript GetPayee() {return address;} - int IsActive() {return GetTime() > nStartTime && GetTime() < nEndTime;} + int IsActive(int64_t nTime) {return nTime > nStartTime && nTime < nEndTime;} int GetAbsoluteYesCount(); int GetYesCount(); int GetNoCount(); diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index 94c322cc3..3397a4438 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -386,86 +386,6 @@ bool CBudgetManager::AddFinalizedBudget(CFinalizedBudget& finalizedBudget) return true; } -void CBudgetManager::SubmitFinalBudget() -{ - if(!pCurrentBlockIndex) return; - - int nBlockStart = pCurrentBlockIndex->nHeight - pCurrentBlockIndex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - if(nSubmittedFinalBudget >= nBlockStart) return; - if(nBlockStart - pCurrentBlockIndex->nHeight > 576*2) return; //submit final budget 2 days before payment - - std::vector vBudgetProposals = budget.GetBudget(); - std::string strBudgetName = "main"; - std::vector vecTxBudgetPayments; - - for(unsigned int i = 0; i < vBudgetProposals.size(); i++){ - CTxBudgetPayment txBudgetPayment; - txBudgetPayment.nProposalHash = vBudgetProposals[i]->GetHash(); - txBudgetPayment.payee = vBudgetProposals[i]->GetPayee(); - txBudgetPayment.nAmount = vBudgetProposals[i]->GetAllotted(); - vecTxBudgetPayments.push_back(txBudgetPayment); - } - - if(vecTxBudgetPayments.size() < 1) { - LogPrintf("CBudgetManager::SubmitFinalBudget - Found No Proposals For Period\n"); - return; - } - - CFinalizedBudget tempBudget(strBudgetName, nBlockStart, vecTxBudgetPayments, uint256()); - if(mapSeenFinalizedBudgets.count(tempBudget.GetHash())) { - LogPrintf("CBudgetManager::SubmitFinalBudget - Budget already exists - %s\n", tempBudget.GetHash().ToString()); - nSubmittedFinalBudget = pCurrentBlockIndex->nHeight; - return; //already exists - } - - //create fee tx - CTransaction tx; - if(!mapCollateral.count(tempBudget.GetHash())){ - CWalletTx wtx; - if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, tempBudget.GetHash(), false)){ - LogPrintf("CBudgetManager::SubmitFinalBudget - Can't make collateral transaction\n"); - return; - } - - // make our change address - CReserveKey reservekey(pwalletMain); - //send the tx to the network - pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::IX); - - mapCollateral.insert(make_pair(tempBudget.GetHash(), (CTransaction)wtx)); - tx = (CTransaction)wtx; - } else { - tx = mapCollateral[tempBudget.GetHash()]; - } - - CTxIn in(COutPoint(tx.GetHash(), 0)); - int conf = GetInputAgeIX(tx.GetHash(), in); - /* - Wait will we have 1 extra confirmation, otherwise some clients might reject this feeTX - -- This function is tied to NewBlock, so we will propagate this budget while the block is also propagating - */ - if(conf < BUDGET_FEE_CONFIRMATIONS+1){ - LogPrintf ("CBudgetManager::SubmitFinalBudget - Collateral requires at least %d confirmations - %s - %d confirmations\n", BUDGET_FEE_CONFIRMATIONS, tx.GetHash().ToString(), conf); - return; - } - - nSubmittedFinalBudget = nBlockStart; - - //create the proposal incase we're the first to make it - CFinalizedBudget finalizedBudgetBroadcast(strBudgetName, nBlockStart, vecTxBudgetPayments, tx.GetHash()); - - std::string strError = ""; - if(!finalizedBudgetBroadcast.IsValid(pCurrentBlockIndex, strError)){ - LogPrintf("CBudgetManager::SubmitFinalBudget - Invalid finalized budget - %s \n", strError); - return; - } - - LOCK(cs); - mapSeenFinalizedBudgets.insert(make_pair(finalizedBudgetBroadcast.GetHash(), finalizedBudgetBroadcast)); - finalizedBudgetBroadcast.Relay(); - AddFinalizedBudget(finalizedBudgetBroadcast); -} - bool CBudgetManager::HasNextFinalizedBudget() { if(!pCurrentBlockIndex) return false; diff --git a/src/rpcgovernance.cpp b/src/rpcgovernance.cpp deleted file mode 100644 index a7e73c5ef..000000000 --- a/src/rpcgovernance.cpp +++ /dev/null @@ -1,1167 +0,0 @@ -// Copyright (c) 2014-2016 The Dash Core developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "main.h" -#include "db.h" -#include "init.h" -#include "activemasternode.h" -#include "governance.h" -#include "masternode-payments.h" -#include "masternode-sync.h" -#include "masternodeconfig.h" -#include "masternodeman.h" -#include "governance.h" -#include "governance-classes.h" -#include "governance-types.h" -#include "rpcserver.h" -#include "utilmoneystr.h" -#include - -#include -#include -#include -#include - -using namespace std; - -UniValue governance(const UniValue& params, bool fHelp) -{ - string strCommand; - if (params.size() >= 1) - strCommand = params[0].get_str(); - - if (fHelp || - (strCommand != "sign" && strCommand != "create" && strCommand != "vote-once" && - strCommand != "vote-many" && strCommand != "vote-alias" && strCommand != "list")) - throw runtime_error( - "governance \"command1\",\"command2\",\"command3\" ...\n" - "Manage governance system\n" - "\n See online documentation at http://govman.dash.org/\n" - ); - - - /* - -governance sign {WITH-PUBKEY : pubkey, HASH: SIGN-HASH} // Sign a key as a company, user, group, etc - - => {result = "success", "sig" : "SIGNATURE1", "signature-type": "user"} - -governance create {parentHash: HASH, name:"proposal", sig1: SIGNATURE1, sig2: sig2.. } - - => {result = "success", "hash" : "HASH1", "proposal-type": "generic", ...} - -// WAIT 30 MINUTES - -governance create {FEEHASH: HASH, parentHash: HASH, name:"proposal", sig1: sig1, sig2: sig2.. } - - => {result = "success", "hash" : "HASH2", "proposal-type": "generic", ...} - -governance (vote-once|vote-many) GOV_HASH_1 yes -governance vote-alias MASTERNODE_NAME GOV_HASH_1 yes - -// this is not meant to be readable, see http://www.github.com/dashpay/fetch for more info -governance list - - */ - - -/* - - { - 'proof-of-destruction' : 'create', //or HASH - 'valid' : true, - 'name' : "Evan Duffield", - - -- - - 'type' : "proposal", - // see governances-classes for mapping - // CProposal lvl, proposal-type, status, status-error - 'level' : "I", - 'proposal-type' : "generic", - 'status' : "ok", - 'status-error' : "none", - - 'time' : "now", - 'fee-hash' : "hash1", - 'parent-hash' : "hash2", - - 'url' : "dashwhale.org/blah" - 'when' : 'nextsuperblock+3 ? blockheight ?' - - months - amount - payuser-by-name - - } - - CGovernanceObj obj(json); - - if json['proof-of-destruction'] == "create": - - // CWalletTx wtx; - // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, budgetProposalBroadcast.GetHash(), useIX)){ - // return "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."; - // } - - // // make our change address - // CReserveKey reservekey(pwalletMain); - // //send the tx to the network - // pwalletMain->CommitTransaction(wtx, reservekey, useIX ? NetMsgType::IX : NetMsgType::TX); - - // return wtx.GetHash().ToString(); - - else: - - if obj.IsValid() ? - obj.Relay(); - - - -*/ - // TODO: 12.1, organize these in order - - - if(strCommand == "create") - { - UniValue govObjJson = params[1].get_obj(); - - CGovernanceNode govObj; - GovernanceObjectType govType = GovernanceStringToType(govObjJson["type"].get_str()); - std::string strError = ""; - - if(!CreateNewGovernanceObject(govObjJson, govObj, govType, strError)) - { - return strError; - } - - - if(govObjJson["create"].get_int() == 1) - { - - } else { - - // if(govObj.IsCollateralValid()) - // { - // //Relay - // } - - // if(govObj.IsValid()) - // { - // //Relay - // } - } - - } - - // TODO: 12.1 - // if(strCommand == "list") - // { - // return full json; //use fetch! - // } - - // if(strCommand == "sign") - // { - // string withPubkey = param(1); - // string withSignHash = param(2); - - // // option 1 - // // return CGovernanceMananger::SignHashWithKey(withPubkey, withSignHash); - - // obj = CGovernanceNode(json); - // if(!obj.IsValid) - // { - // std::string strError = ""; - // if(!obj.SignWithKeyByName(withPubkey, strError)) - // { - // return obj.ToJson(); - // } - // } - // } - - // if(strCommand == "prepare") - // { - - // /* - - // governance prepare new {parentHash: HASH, name:"proposal", sig1: sig1, sig2: sig2.. } - - // */ - - // string strCommand2 = param(1) - // UniValue obj(VOBJ) = param(2); - - - // // if (params.size() != 7) - // // throw runtime_error("Correct usage is 'proposal prepare '"); - - // // int nBlockMin = 0; - // // LOCK(cs_main); - // // CBlockIndex* pindex = chainActive.Tip(); - - // // std::vector mnEntries; - // // mnEntries = masternodeConfig.getEntries(); - - // // std::string strName = SanitizeString(params[1].get_str()); - // // std::string strURL = SanitizeString(params[2].get_str()); - // // int nPaymentCount = params[3].get_int(); - // // int nBlockStart = params[4].get_int(); - - // // //set block min - // // if(pindex != NULL) nBlockMin = pindex->nHeight; - - // // if(nBlockStart < nBlockMin) - // // return "Invalid block start, must be more than current height."; - - // // CBitcoinAddress address(params[5].get_str()); - // // if (!address.IsValid()) - // // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); - - // // // Parse Dash address - // // CScript scriptPubKey = GetScriptForDestination(address.Get()); - // // CAmount nAmount = AmountFromValue(params[6]); - - // // //************************************************************************* - - // // // create transaction 15 minutes into the future, to allow for confirmation time - // // CGovernanceNodeBroadcast budgetProposalBroadcast; - // // budgetProposalBroadcast.CreateProposal(strName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, uint256()); - - // // std::string strError = ""; - // // if(!budgetProposalBroadcast.IsValid(pindex, strError, false)) - // // return "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError; - - // // bool useIX = false; //true; - // // // if (params.size() > 7) { - // // // if(params[7].get_str() != "false" && params[7].get_str() != "true") - // // // return "Invalid use_ix, must be true or false"; - // // // useIX = params[7].get_str() == "true" ? true : false; - // // // } - - // // CWalletTx wtx; - // // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, budgetProposalBroadcast.GetHash(), useIX)){ - // // return "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."; - // // } - - // // // make our change address - // // CReserveKey reservekey(pwalletMain); - // // //send the tx to the network - // // pwalletMain->CommitTransaction(wtx, reservekey, useIX ? NetMsgType::IX : NetMsgType::TX); - - // // return wtx.GetHash().ToString(); - // } - - // if(strCommand == "submit") - // { - // if (params.size() != 8) - // throw runtime_error("Correct usage is 'proposal submit '"); - - // if(!masternodeSync.IsBlockchainSynced()){ - // return "Must wait for client to sync with masternode network. Try again in a minute or so."; - // } - - // int nBlockMin = 0; - // LOCK(cs_main); - // CBlockIndex* pindex = chainActive.Tip(); - - // std::vector mnEntries; - // mnEntries = masternodeConfig.getEntries(); - - // std::string strName = SanitizeString(params[1].get_str()); - // std::string strURL = SanitizeString(params[2].get_str()); - // int nPaymentCount = params[3].get_int(); - // int nBlockStart = params[4].get_int(); - - // //set block min - // if(pindex != NULL) nBlockMin = pindex->nHeight; - - // if(nBlockStart < nBlockMin) - // return "Invalid payment count, must be more than current height."; - - // CBitcoinAddress address(params[5].get_str()); - // if (!address.IsValid()) - // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); - - // // Parse Dash address - // CScript scriptPubKey = GetScriptForDestination(address.Get()); - // CAmount nAmount = AmountFromValue(params[6]); - // uint256 hash = ParseHashV(params[7], "Proposal hash"); - - // //create the proposal incase we're the first to make it - // CGovernanceNodeBroadcast budgetProposalBroadcast; - // budgetProposalBroadcast.CreateProposal(strName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash); - - // std::string strError = ""; - - // if(!budgetProposalBroadcast.IsValid(pindex, strError)){ - // return "Proposal is not valid - " + budgetProposalBroadcast.GetHash().ToString() + " - " + strError; - // } - - // int nConf = 0; - // if(!IsCollateralValid(hash, budgetProposalBroadcast.GetHash(), strError, budgetProposalBroadcast.nTime, nConf, GOVERNANCE_FEE_TX)){ - // return "Proposal FeeTX is not valid - " + hash.ToString() + " - " + strError; - // } - - // govman.mapSeenGovernanceObjects.insert(make_pair(budgetProposalBroadcast.GetHash(), budgetProposalBroadcast)); - // budgetProposalBroadcast.Relay(); - // govman.AddGovernanceObject(budgetProposalBroadcast); - - // return budgetProposalBroadcast.GetHash().ToString(); - - // } - - // if(strCommand == "list") - // { - // if (params.size() > 2) - // throw runtime_error("Correct usage is 'proposal list [valid|all|extended]'"); - - // std::string strShow = "valid"; - // if (params.size() == 2) strShow = params[1].get_str(); - - // CBlockIndex* pindex; - // { - // LOCK(cs_main); - // pindex = chainActive.Tip(); - // } - - // UniValue resultObj(UniValue::VOBJ); - // int64_t nTotalAllotted = 0; - - // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); - // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) - // { - // if(strShow == "valid" && !pbudgetProposal->fValid) continue; - - // nTotalAllotted += pbudgetProposal->GetAllotted(); - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // UniValue bObj(UniValue::VOBJ); - // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); - - // if(strShow == "extended") bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); - // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - - // if(strShow == "extended") - // { - // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); - // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - // bObj.push_back(Pair("PaymentAddress", address2.ToString())); - // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - // } - - // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - - // if(strShow == "extended") - // { - // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - // } - - // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - - // if(strShow == "extended") - // { - // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); - - // std::string strError = ""; - // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); - // bObj.push_back(Pair("IsValidReason", strError.c_str())); - // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); - // } - - // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); - // } - - // return resultObj; - // } - - // if(strCommand == "get") - // { - // if (params.size() != 2) - // throw runtime_error("Correct usage is 'proposal get '"); - - // uint256 hash = ParseHashV(params[1], "Proposal hash"); - - // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(hash); - - // if(pbudgetProposal == NULL) return "Unknown proposal"; - - // CBlockIndex* pindex; - // { - // LOCK(cs_main); - // pindex = chainActive.Tip(); - // } - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // LOCK(cs_main); - // UniValue obj(UniValue::VOBJ); - // obj.push_back(Pair("Name", pbudgetProposal->GetName())); - // obj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - // obj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); - // obj.push_back(Pair("URL", pbudgetProposal->GetURL())); - // obj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - // obj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - // obj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - // obj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - // obj.push_back(Pair("PaymentAddress", address2.ToString())); - // obj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - // obj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - // obj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - // obj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - // obj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - // obj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - // obj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - - // obj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); - - // std::string strError = ""; - // obj.push_back(Pair("IsValid", pbudgetProposal->IsValid(chainActive.Tip(), strError))); - // obj.push_back(Pair("fValid", pbudgetProposal->fValid)); - - // return obj; - // } - - - // if(strCommand == "gethash") - // { - // if (params.size() != 2) - // throw runtime_error("Correct usage is 'proposal gethash '"); - - // std::string strName = SanitizeString(params[1].get_str()); - - // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(strName); - - // if(pbudgetProposal == NULL) return "Unknown proposal"; - - // UniValue resultObj(UniValue::VOBJ); - - // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); - // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) - // { - // if(pbudgetProposal->GetName() != strName) continue; - // if(!pbudgetProposal->fValid) continue; - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // resultObj.push_back(Pair(pbudgetProposal->GetHash().ToString(), pbudgetProposal->GetHash().ToString())); - // } - - // if(resultObj.size() > 1) return resultObj; - - // return pbudgetProposal->GetHash().ToString(); - // } - - return NullUniValue; -} - -UniValue contract(const UniValue& params, bool fHelp) -{ - string strCommand; - if (params.size() >= 1) - strCommand = params[0].get_str(); - - if (fHelp || - (strCommand != "prepare" && strCommand != "submit" && - strCommand != "get" && strCommand != "gethash" && strCommand != "list")) - throw runtime_error( - "contract \"command\"...\n" - "Manage contracts\n" - "\nAvailable commands:\n" - " prepare - Prepare contract by signing and creating tx\n" - " submit - Submit contract to network\n" - " list - List all contracts\n" - " get - get contract\n" - " gethash - Get contract hash(es) by contract name\n" - ); - - // if(strCommand == "prepare") - // { - // if (params.size() != 7) - // throw runtime_error("Correct usage is 'contract prepare '"); - - // int nBlockMin = 0; - // LOCK(cs_main); - // CBlockIndex* pindex = chainActive.Tip(); - - // std::vector mnEntries; - // mnEntries = masternodeConfig.getEntries(); - - // std::string strName = SanitizeString(params[1].get_str()); - // std::string strURL = SanitizeString(params[2].get_str()); - // int nMonthCount = params[3].get_int(); - // int nBlockStart = params[4].get_int(); - - // //set block min - // if(pindex != NULL) nBlockMin = pindex->nHeight; - - // if(nBlockStart < nBlockMin) - // return "Invalid block start, must be more than current height."; - - // CBitcoinAddress address(params[5].get_str()); - // if (!address.IsValid()) - // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); - - // // Parse Dash address - // CScript scriptPubKey = GetScriptForDestination(address.Get()); - // CAmount nAmount = AmountFromValue(params[6]); - - // //************************************************************************* - - // // create transaction 15 minutes into the future, to allow for confirmation time - // CGovernanceNodeBroadcast contract; - // contract.CreateContract(strName, strURL, nMonthCount, scriptPubKey, nAmount, nBlockStart, uint256()); - - // std::string strError = ""; - // if(!contract.IsValid(pindex, strError, false)) - // return "Contract is not valid - " + contract.GetHash().ToString() + " - " + strError; - - // CWalletTx wtx; - // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, contract.GetHash(), false)){ - // return "Error making collateral transaction for proposal. Please check your wallet balance and make sure your wallet is unlocked."; - // } - - // // make our change address - // CReserveKey reservekey(pwalletMain); - // //send the tx to the network - // pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::TX); - - // return wtx.GetHash().ToString(); - // } - - // if(strCommand == "submit") - // { - // if (params.size() != 8) - // throw runtime_error("Correct usage is 'contract submit '"); - - // if(!masternodeSync.IsBlockchainSynced()){ - // return "Must wait for client to sync with masternode network. Try again in a minute or so."; - // } - - // int nBlockMin = 0; - // LOCK(cs_main); - // CBlockIndex* pindex = chainActive.Tip(); - - // std::vector mnEntries; - // mnEntries = masternodeConfig.getEntries(); - - // std::string strName = SanitizeString(params[1].get_str()); - // std::string strURL = SanitizeString(params[2].get_str()); - // int nPaymentCount = params[3].get_int(); - // int nBlockStart = params[4].get_int(); - - // //set block min - // if(pindex != NULL) nBlockMin = pindex->nHeight; - - // if(nBlockStart < nBlockMin) - // return "Invalid payment count, must be more than current height."; - - // CBitcoinAddress address(params[5].get_str()); - // if (!address.IsValid()) - // throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Dash address"); - - // // Parse Dash address - // CScript scriptPubKey = GetScriptForDestination(address.Get()); - // CAmount nAmount = AmountFromValue(params[6]); - // uint256 hash = ParseHashV(params[7], "Contract hash"); - - // //create the contract incase we're the first to make it - // CGovernanceNodeBroadcast contractBroadcast; - // contractBroadcast.CreateContract(strName, strURL, nPaymentCount, scriptPubKey, nAmount, nBlockStart, hash); - - // std::string strError = ""; - - // if(!contractBroadcast.IsValid(pindex, strError)){ - // return "Contract is not valid - " + contractBroadcast.GetHash().ToString() + " - " + strError; - // } - - // int nConf = 0; - // if(!IsCollateralValid(hash, contractBroadcast.GetHash(), strError, contractBroadcast.nTime, nConf, GOVERNANCE_FEE_TX)){ - // return "Contract FeeTX is not valid - " + hash.ToString() + " - " + strError; - // } - - // govman.mapSeenGovernanceObjects.insert(make_pair(contractBroadcast.GetHash(), contractBroadcast)); - // contractBroadcast.Relay(); - // govman.AddGovernanceObject(contractBroadcast); - - // return contractBroadcast.GetHash().ToString(); - - // } - - // if(strCommand == "list") - // { - // if (params.size() > 2) - // throw runtime_error("Correct usage is 'proposal list [valid]'"); - - // std::string strShow = "valid"; - // if (params.size() == 2) strShow = params[1].get_str(); - - // CBlockIndex* pindex; - // { - // LOCK(cs_main); - // pindex = chainActive.Tip(); - // } - - // UniValue resultObj(UniValue::VOBJ); - // int64_t nTotalAllotted = 0; - - // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); - // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) - // { - // if(strShow == "valid" && !pbudgetProposal->fValid) continue; - - // nTotalAllotted += pbudgetProposal->GetAllotted(); - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // UniValue bObj(UniValue::VOBJ); - // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); - // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); - // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); - // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - // bObj.push_back(Pair("PaymentAddress", address2.ToString())); - // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - - // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); - - // std::string strError = ""; - // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); - // bObj.push_back(Pair("IsValidReason", strError.c_str())); - // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); - - // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); - // } - - // return resultObj; - // } - - // if(strCommand == "get") - // { - // if (params.size() != 2) - // throw runtime_error("Correct usage is 'proposal get '"); - - // uint256 hash = ParseHashV(params[1], "Proposal hash"); - - // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(hash); - - // if(pbudgetProposal == NULL) return "Unknown proposal"; - - // CBlockIndex* pindex; - // { - // LOCK(cs_main); - // pindex = chainActive.Tip(); - // } - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // LOCK(cs_main); - // UniValue obj(UniValue::VOBJ); - // obj.push_back(Pair("Name", pbudgetProposal->GetName())); - // obj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - // obj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); - // obj.push_back(Pair("URL", pbudgetProposal->GetURL())); - // obj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - // obj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - // obj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - // obj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - // obj.push_back(Pair("PaymentAddress", address2.ToString())); - // obj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - // obj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - // obj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - // obj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - // obj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - // obj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - // obj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - - // obj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); - - // std::string strError = ""; - // obj.push_back(Pair("IsValid", pbudgetProposal->IsValid(chainActive.Tip(), strError))); - // obj.push_back(Pair("fValid", pbudgetProposal->fValid)); - - // return obj; - // } - - - // if(strCommand == "gethash") - // { - // if (params.size() != 2) - // throw runtime_error("Correct usage is 'proposal gethash '"); - - // std::string strName = SanitizeString(params[1].get_str()); - - // CGovernanceNode* pbudgetProposal = govman.FindGovernanceObject(strName); - - // if(pbudgetProposal == NULL) return "Unknown proposal"; - - // UniValue resultObj(UniValue::VOBJ); - - // std::vector winningProps = govman.FindMatchingGovernanceObjects(Proposal); - // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) - // { - // if(pbudgetProposal->GetName() != strName) continue; - // if(!pbudgetProposal->fValid) continue; - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // resultObj.push_back(Pair(pbudgetProposal->GetHash().ToString(), pbudgetProposal->GetHash().ToString())); - // } - - // if(resultObj.size() > 1) return resultObj; - - // return pbudgetProposal->GetHash().ToString(); - // } - - return NullUniValue; -} - -UniValue budget(const UniValue& params, bool fHelp) -{ - string strCommand; - if (params.size() >= 1) - strCommand = params[0].get_str(); - string strSubCommand; - if (params.size() >= 2) - strSubCommand = params[1].get_str(); - - if (fHelp || - (strCommand != "check" && strCommand != "get" && strCommand != "all" && - strCommand != "valid" && strCommand != "extended" && strCommand != "projection")) - throw runtime_error( - "budget \"command\"...\n" - "Manage proposals\n" - "\nAvailable commands:\n" - " check - Scan proposals and remove invalid from proposals list\n" - " get - Get a proposals|contract by hash\n" - " list - Get all proposals (all|valid|extended)\n" - " projection - Show the projection of which proposals will be paid the next superblocks\n" - ); - - // help messages - if(strSubCommand == "help") - { - if(strCommand == "list") - { - throw runtime_error( - "budget \"list\"...\n" - "List all budgets in various configurations\n" - "\nAvailable commands:\n" - " all - Show all proposed settings for the network\n" - " valid - Show only valid settings for the network\n" - " extended - Show extended information about all settings\n" - " active - Show active values for each network setting\n" - ); - } - } - - // if(strCommand == "check") - // { - // govman.CheckAndRemove(); - - // return "Success"; - // } - - // if(strCommand == "projection") - // { - // CBlockIndex* pindex; - // { - // LOCK(cs_main); - // pindex = chainActive.Tip(); - // } - - // UniValue resultObj(UniValue::VOBJ); - // CAmount nTotalAllotted = 0; - - // std::vector winningProps = govman.GetBudget(); - // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) - // { - // nTotalAllotted += pbudgetProposal->GetAllotted(); - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // UniValue bObj(UniValue::VOBJ); - // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); - // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - // bObj.push_back(Pair("PaymentAddress", address2.ToString())); - // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - // bObj.push_back(Pair("Alloted", ValueFromAmount(pbudgetProposal->GetAllotted()))); - - // std::string strError = ""; - // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); - // bObj.push_back(Pair("IsValidReason", strError.c_str())); - // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); - - // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); - // } - // resultObj.push_back(Pair("TotalBudgetAlloted", ValueFromAmount(nTotalAllotted))); - - // return resultObj; - // } - - // if(strCommand == "get") - // { - // uint256 nMatchHash = uint256(); - // std::string strMatchName = ""; - - // if (IsHex(params[1].get_str())) - // { - // nMatchHash = ParseHashV(params[1], "GovObj hash"); - // } else { - // strMatchName = params[1].get_str(); - // } - - // CBlockIndex* pindex; - // { - // LOCK(cs_main); - // pindex = chainActive.Tip(); - // } - - // UniValue resultObj(UniValue::VOBJ); - // int64_t nTotalAllotted = 0; - - // std::vector winningProps = govman.FindMatchingGovernanceObjects(AllTypes); - - // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) - // { - // if(pbudgetProposal->GetName() != strMatchName && pbudgetProposal->GetHash() != nMatchHash) continue; - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // UniValue bObj(UniValue::VOBJ); - // bObj.push_back(Pair("Type", pbudgetProposal->GetGovernanceTypeAsString())); - // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); - // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); - // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); - // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - // bObj.push_back(Pair("PaymentAddress", address2.ToString())); - // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - - // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - - // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); - - // std::string strError = ""; - // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); - // bObj.push_back(Pair("IsValidReason", strError.c_str())); - // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); - - // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); - // } - - // return resultObj; - // } - - // if(strCommand == "all" || strCommand == "valid" || strCommand == "extended") - // { - - // CBlockIndex* pindex; - // { - // LOCK(cs_main); - // pindex = chainActive.Tip(); - // } - - // UniValue resultObj(UniValue::VOBJ); - // int64_t nTotalAllotted = 0; - - // std::vector winningProps = govman.FindMatchingGovernanceObjects(AllTypes); - - // BOOST_FOREACH(CGovernanceNode* pbudgetProposal, winningProps) - // { - // if(strCommand == "valid" && !pbudgetProposal->fValid) continue; - - // nTotalAllotted += pbudgetProposal->GetAllotted(); - - // CTxDestination address1; - // ExtractDestination(pbudgetProposal->GetPayee(), address1); - // CBitcoinAddress address2(address1); - - // UniValue bObj(UniValue::VOBJ); - // bObj.push_back(Pair("Name", pbudgetProposal->GetName())); - - // if(strCommand == "extended") - // { - // bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); - // bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - // bObj.push_back(Pair("FeeHash", pbudgetProposal->nFeeTXHash.ToString())); - // bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - // bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - // bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - // bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - // bObj.push_back(Pair("PaymentAddress", address2.ToString())); - // bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - // } - - // bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - // bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - // bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - - // if(strCommand == "extended") - // { - // bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - // bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - // } - - // bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - // bObj.push_back(Pair("IsEstablished", pbudgetProposal->IsEstablished())); - - // if(strCommand == "extended") - // { - // std::string strError = ""; - // bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); - // bObj.push_back(Pair("IsValidReason", strError.c_str())); - // bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); - // } - - // resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); - // } - - // return resultObj; - // } - - return NullUniValue; -} - -UniValue superblock(const UniValue& params, bool fHelp) -{ - string strCommand; - if (params.size() >= 1) - strCommand = params[0].get_str(); - - if (fHelp || - (strCommand != "vote-many" && strCommand != "vote" && strCommand != "show" && strCommand != "getvotes" && strCommand != "prepare" && strCommand != "submit")) - throw runtime_error( - "superblock \"command\"...\n" - "Get information about the next superblocks\n" - "\nAvailable commands:\n" - " info - Get info about the next superblock\n" - " getvotes - Get vote information for each finalized budget\n" - " prepare - Manually prepare a finalized budget\n" - " submit - Manually submit a finalized budget\n" - ); - - - // if(strCommand == "nextblock") - // { - // LOCK(cs_main); - // CBlockIndex* pindex = chainActive.Tip(); - // if(!pindex) return "unknown"; - - // int nNext = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - // return nNext; - // } - - // if(strCommand == "nextsuperblocksize") - // { - // LOCK(cs_main); - // CBlockIndex* pindex = chainActive.Tip(); - // if(!pindex) return "unknown"; - - // int nHeight = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - - // CAmount nTotal = govman.GetTotalBudget(nHeight); - // return nTotal; - // } - - // if(strCommand == "get") - // { - // UniValue resultObj(UniValue::VOBJ); - - // std::vector winningFbs = govman.GetFinalizedBudgets(); - // LOCK(cs_main); - // BOOST_FOREACH(CFinalizedBudget* finalizedBudget, winningFbs) - // { - // UniValue bObj(UniValue::VOBJ); - // bObj.push_back(Pair("FeeTX", finalizedBudget->nFeeTXHash.ToString())); - // bObj.push_back(Pair("Hash", finalizedBudget->GetHash().ToString())); - // bObj.push_back(Pair("BlockStart", (int64_t)finalizedBudget->GetBlockStart())); - // bObj.push_back(Pair("BlockEnd", (int64_t)finalizedBudget->GetBlockEnd())); - // bObj.push_back(Pair("Proposals", finalizedBudget->GetProposals())); - // bObj.push_back(Pair("VoteCount", (int64_t)finalizedBudget->GetVoteCount())); - // bObj.push_back(Pair("Status", finalizedBudget->GetStatus())); - - // std::string strError = ""; - // bObj.push_back(Pair("IsValid", finalizedBudget->IsValid(chainActive.Tip(), strError))); - // bObj.push_back(Pair("IsValidReason", strError.c_str())); - - // resultObj.push_back(Pair(finalizedBudget->GetName(), bObj)); - // } - - // return resultObj; - - // } - - // /* TODO - // Switch the preparation to a public key which the core team has - // The budget should be able to be created by any high up core team member then voted on by the network separately. - // */ - - // if(strCommand == "prepare") - // { - // if (params.size() != 2) - // throw runtime_error("Correct usage is 'mnfinalbudget prepare comma-separated-hashes'"); - - // std::string strHashes = params[1].get_str(); - // std::istringstream ss(strHashes); - // std::string token; - - // std::vector vecTxBudgetPayments; - - // while(std::getline(ss, token, ',')) { - // uint256 nHash = uint256S(token); - // CGovernanceNode* prop = govman.FindGovernanceObject(nHash); - - // CTxBudgetPayment txBudgetPayment; - // txBudgetPayment.nProposalHash = prop->GetHash(); - // txBudgetPayment.payee = prop->GetPayee(); - // txBudgetPayment.nAmount = prop->GetAllotted(); - // vecTxBudgetPayments.push_back(txBudgetPayment); - // } - - // if(vecTxBudgetPayments.size() < 1) { - // return "Invalid finalized proposal"; - // } - - // LOCK(cs_main); - // CBlockIndex* pindex = chainActive.Tip(); - // if(!pindex) return "invalid chaintip"; - - // int nBlockStart = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - - // CFinalizedBudget tempBudget("main", nBlockStart, vecTxBudgetPayments, uint256()); - // // if(mapSeenFinalizedBudgets.count(tempBudget.GetHash())) { - // // return "already exists"; //already exists - // // } - - // //create fee tx - // CTransaction tx; - - // CWalletTx wtx; - // if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, tempBudget.GetHash(), false)){ - // printf("Can't make collateral transaction\n"); - // return "can't make colateral tx"; - // } - - // // make our change address - // CReserveKey reservekey(pwalletMain); - // //send the tx to the network - // pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::IX); - - // return wtx.GetHash().ToString(); - // } - - // if(strCommand == "submit") - // { - // if (params.size() != 3) - // throw runtime_error("Correct usage is 'mnfinalbudget submit comma-separated-hashes collateralhash'"); - - // std::string strHashes = params[1].get_str(); - // std::istringstream ss(strHashes); - // std::string token; - - // std::vector vecTxBudgetPayments; - - // uint256 nColHash = uint256S(params[2].get_str()); - - // while(std::getline(ss, token, ',')) { - // uint256 nHash = uint256S(token); - // CGovernanceNode* prop = govman.FindGovernanceObject(nHash); - - // CTxBudgetPayment txBudgetPayment; - // txBudgetPayment.nProposalHash = prop->GetHash(); - // txBudgetPayment.payee = prop->GetPayee(); - // txBudgetPayment.nAmount = prop->GetAllotted(); - // vecTxBudgetPayments.push_back(txBudgetPayment); - - // printf("%lld\n", txBudgetPayment.nAmount); - // } - - // if(vecTxBudgetPayments.size() < 1) { - // return "Invalid finalized proposal"; - // } - - // LOCK(cs_main); - // CBlockIndex* pindex = chainActive.Tip(); - // if(!pindex) return "invalid chaintip"; - - // int nBlockStart = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - - // // CTxIn in(COutPoint(nColHash, 0)); - // // int conf = GetInputAgeIX(nColHash, in); - - // // Wait will we have 1 extra confirmation, otherwise some clients might reject this feeTX - // // -- This function is tied to NewBlock, so we will propagate this budget while the block is also propagating - - // // if(conf < BUDGET_FEE_CONFIRMATIONS+1){ - // // printf ("Collateral requires at least %d confirmations - %s - %d confirmations\n", BUDGET_FEE_CONFIRMATIONS, nColHash.ToString().c_str(), conf); - // // return "invalid collateral"; - // // } - - // //create the proposal incase we're the first to make it - // CFinalizedBudget finalizedBudgetBroadcast("main", nBlockStart, vecTxBudgetPayments, nColHash); - - // std::string strError = ""; - // if(!finalizedBudgetBroadcast.IsValid(pindex, strError)){ - // printf("CGovernanceManager::SubmitFinalBudget - Invalid finalized budget - %s \n", strError.c_str()); - // return "invalid finalized budget"; - // } - - // finalizedBudgetBroadcast.Relay(); - // govman.AddFinalizedBudget(finalizedBudgetBroadcast); - - // return finalizedBudgetBroadcast.GetHash().ToString(); - // } - - return NullUniValue; -} diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index 7fc8d002f..33f8d487d 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -409,56 +409,6 @@ UniValue mnbudget(const UniValue& params, bool fHelp) } } - if(strCommand == "projection") - { - CBlockIndex* pindex; - { - LOCK(cs_main); - pindex = chainActive.Tip(); - } - - UniValue resultObj(UniValue::VOBJ); - CAmount nTotalAllotted = 0; - - std::vector winningProps = budget.GetBudget(); - BOOST_FOREACH(CBudgetProposal* pbudgetProposal, winningProps) - { - nTotalAllotted += pbudgetProposal->GetAllotted(); - - CTxDestination address1; - ExtractDestination(pbudgetProposal->GetPayee(), address1); - CBitcoinAddress address2(address1); - - UniValue bObj(UniValue::VOBJ); - bObj.push_back(Pair("URL", pbudgetProposal->GetURL())); - bObj.push_back(Pair("Hash", pbudgetProposal->GetHash().ToString())); - bObj.push_back(Pair("FeeTXHash", pbudgetProposal->nFeeTXHash.ToString())); - bObj.push_back(Pair("BlockStart", (int64_t)pbudgetProposal->GetBlockStart())); - bObj.push_back(Pair("BlockEnd", (int64_t)pbudgetProposal->GetBlockEnd())); - bObj.push_back(Pair("TotalPaymentCount", (int64_t)pbudgetProposal->GetTotalPaymentCount())); - bObj.push_back(Pair("RemainingPaymentCount", (int64_t)pbudgetProposal->GetRemainingPaymentCount(pindex->nHeight))); - bObj.push_back(Pair("PaymentAddress", address2.ToString())); - bObj.push_back(Pair("Ratio", pbudgetProposal->GetRatio())); - bObj.push_back(Pair("AbsoluteYesCount", (int64_t)pbudgetProposal->GetYesCount()-(int64_t)pbudgetProposal->GetNoCount())); - bObj.push_back(Pair("YesCount", (int64_t)pbudgetProposal->GetYesCount())); - bObj.push_back(Pair("NoCount", (int64_t)pbudgetProposal->GetNoCount())); - bObj.push_back(Pair("AbstainCount", (int64_t)pbudgetProposal->GetAbstainCount())); - bObj.push_back(Pair("TotalPayment", ValueFromAmount(pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount()))); - bObj.push_back(Pair("MonthlyPayment", ValueFromAmount(pbudgetProposal->GetAmount()))); - bObj.push_back(Pair("Alloted", ValueFromAmount(pbudgetProposal->GetAllotted()))); - - std::string strError = ""; - bObj.push_back(Pair("IsValid", pbudgetProposal->IsValid(pindex, strError))); - bObj.push_back(Pair("IsValidReason", strError.c_str())); - bObj.push_back(Pair("fValid", pbudgetProposal->fValid)); - - resultObj.push_back(Pair(pbudgetProposal->GetName(), bObj)); - } - resultObj.push_back(Pair("TotalBudgetAlloted", ValueFromAmount(nTotalAllotted))); - - return resultObj; - } - if(strCommand == "list") { if (params.size() > 2) @@ -693,324 +643,4 @@ UniValue mnbudgetvoteraw(const UniValue& params, bool fHelp) } else { throw JSONRPCError(RPC_INTERNAL_ERROR, "Error voting : " + strError); } -} - -UniValue mnfinalbudget(const UniValue& params, bool fHelp) -{ - string strCommand; - if (params.size() >= 1) - strCommand = params[0].get_str(); - - if (fHelp || - (strCommand != "vote-many" && strCommand != "vote" && strCommand != "show" && strCommand != "getvotes" && strCommand != "prepare" && strCommand != "submit")) - throw runtime_error( - "mnfinalbudget \"command\"...\n" - "Manage current budgets\n" - "\nAvailable commands:\n" - " vote-many - Vote on a finalized budget\n" - " vote - Vote on a finalized budget\n" - " show - Show existing finalized budgets\n" - " getvotes - Get vote information for each finalized budget\n" - " prepare - Manually prepare a finalized budget\n" - " submit - Manually submit a finalized budget\n" - ); - - if(strCommand == "vote-many") - { - if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnfinalbudget vote-many '"); - - std::string strHash = params[1].get_str(); - uint256 hash = uint256S(strHash); - - int success = 0; - int failed = 0; - - std::vector mnEntries; - mnEntries = masternodeConfig.getEntries(); - - UniValue resultsObj(UniValue::VOBJ); - - BOOST_FOREACH(CMasternodeConfig::CMasternodeEntry mne, masternodeConfig.getEntries()) { - std::string errorMessage; - std::vector vchMasterNodeSignature; - std::string strMasterNodeSignMessage; - - CPubKey pubKeyCollateralAddress; - CKey keyCollateralAddress; - CPubKey pubKeyMasternode; - CKey keyMasternode; - - UniValue statusObj(UniValue::VOBJ); - - if(!darkSendSigner.SetKey(mne.getPrivKey(), errorMessage, keyMasternode, pubKeyMasternode)){ - failed++; - statusObj.push_back(Pair("result", "failed")); - statusObj.push_back(Pair("errorMessage", "Masternode signing error, could not set key correctly: " + errorMessage)); - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - continue; - } - - CMasternode* pmn = mnodeman.Find(pubKeyMasternode); - if(pmn == NULL) - { - failed++; - statusObj.push_back(Pair("result", "failed")); - statusObj.push_back(Pair("errorMessage", "Can't find masternode by pubkey")); - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - continue; - } - - - CBudgetVote vote(pmn->vin, hash); - if(!vote.Sign(keyMasternode, pubKeyMasternode)){ - failed++; - statusObj.push_back(Pair("result", "failed")); - statusObj.push_back(Pair("errorMessage", "Failure to sign.")); - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - continue; - } - - std::string strError = ""; - if(budget.UpdateFinalizedBudget(vote, NULL, strError)){ - budget.mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); - vote.Relay(); - success++; - statusObj.push_back(Pair("result", "success")); - } else { - failed++; - statusObj.push_back(Pair("result", strError.c_str())); - } - - resultsObj.push_back(Pair(mne.getAlias(), statusObj)); - } - - UniValue returnObj(UniValue::VOBJ); - returnObj.push_back(Pair("overall", strprintf("Voted successfully %d time(s) and failed %d time(s).", success, failed))); - returnObj.push_back(Pair("detail", resultsObj)); - - return returnObj; - } - - if(strCommand == "vote") - { - if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnfinalbudget vote '"); - - std::string strHash = params[1].get_str(); - uint256 hash = uint256S(strHash); - - CPubKey pubKeyMasternode; - CKey keyMasternode; - std::string errorMessage; - - if(!darkSendSigner.SetKey(strMasterNodePrivKey, errorMessage, keyMasternode, pubKeyMasternode)) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Error upon calling SetKey"); - - CMasternode* pmn = mnodeman.Find(activeMasternode.vin); - if(pmn == NULL) - { - throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to find masternode in list : " + activeMasternode.vin.ToString()); - } - - CBudgetVote vote(activeMasternode.vin, hash); - if(!vote.Sign(keyMasternode, pubKeyMasternode)){ - throw JSONRPCError(RPC_INTERNAL_ERROR, "Failure to sign."); - } - - std::string strError = ""; - if(budget.UpdateFinalizedBudget(vote, NULL, strError)){ - budget.mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote)); - vote.Relay(); - return "success"; - } else { - throw JSONRPCError(RPC_INTERNAL_ERROR, "Error voting : " + strError); - } - - } - - if(strCommand == "list") - { - UniValue resultObj(UniValue::VOBJ); - - std::vector winningFbs = budget.GetFinalizedBudgets(); - LOCK(cs_main); - BOOST_FOREACH(CFinalizedBudget* finalizedBudget, winningFbs) - { - UniValue bObj(UniValue::VOBJ); - bObj.push_back(Pair("Hash", finalizedBudget->GetHash().ToString())); - bObj.push_back(Pair("FeeTXHash", finalizedBudget->nFeeTXHash.ToString())); - bObj.push_back(Pair("BlockStart", (int64_t)finalizedBudget->GetBlockStart())); - bObj.push_back(Pair("BlockEnd", (int64_t)finalizedBudget->GetBlockEnd())); - bObj.push_back(Pair("Proposals", finalizedBudget->GetProposals())); - bObj.push_back(Pair("VoteCount", (int64_t)finalizedBudget->GetVoteCount())); - bObj.push_back(Pair("Status", finalizedBudget->GetStatus())); - - std::string strError = ""; - bObj.push_back(Pair("IsValid", finalizedBudget->IsValid(chainActive.Tip(), strError))); - bObj.push_back(Pair("IsValidReason", strError.c_str())); - - resultObj.push_back(Pair(finalizedBudget->GetName(), bObj)); - } - - return resultObj; - - } - - if(strCommand == "getvotes") - { - if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnfinalbudget getvotes budget-hash'"); - - std::string strHash = params[1].get_str(); - uint256 hash = uint256S(strHash); - - UniValue obj(UniValue::VOBJ); - - CFinalizedBudget* pfinalBudget = budget.FindFinalizedBudget(hash); - - if(pfinalBudget == NULL) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown budget hash"); - - std::map::iterator it = pfinalBudget->mapVotes.begin(); - while(it != pfinalBudget->mapVotes.end()){ - - UniValue bObj(UniValue::VOBJ); - bObj.push_back(Pair("nHash", (*it).first.ToString().c_str())); - bObj.push_back(Pair("nTime", (int64_t)(*it).second.nTime)); - bObj.push_back(Pair("fValid", (*it).second.fValid)); - - obj.push_back(Pair((*it).second.vin.prevout.ToStringShort(), bObj)); - - it++; - } - - - return obj; - } - - /* TODO - Switch the preparation to a public key which the core team has - The budget should be able to be created by any high up core team member then voted on by the network separately. - */ - - if(strCommand == "prepare") - { - if (params.size() != 2) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnfinalbudget prepare comma-separated-hashes'"); - - std::string strHashes = params[1].get_str(); - std::istringstream ss(strHashes); - std::string token; - - std::vector vecTxBudgetPayments; - - while(std::getline(ss, token, ',')) { - uint256 nHash = uint256S(token); - CBudgetProposal* prop = governance.FindProposal(nHash); - - CTxBudgetPayment txBudgetPayment; - txBudgetPayment.nProposalHash = prop->GetHash(); - txBudgetPayment.payee = prop->GetPayee(); - txBudgetPayment.nAmount = prop->GetAllotted(); - vecTxBudgetPayments.push_back(txBudgetPayment); - } - - if(vecTxBudgetPayments.size() < 1) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "Invalid finalized proposal"); - } - - LOCK(cs_main); - CBlockIndex* pindex = chainActive.Tip(); - if(!pindex) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Invalid chaintip"); - - int nBlockStart = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - - CFinalizedBudgetBroadcast tempBudget("main", nBlockStart, vecTxBudgetPayments, uint256()); - // if(mapSeenFinalizedBudgets.count(tempBudget.GetHash())) { - // return "already exists"; //already exists - // } - - //create fee tx - CTransaction tx; - - CWalletTx wtx; - if(!pwalletMain->GetBudgetSystemCollateralTX(wtx, tempBudget.GetHash(), false)){ - // printf("Can't make collateral transaction\n"); - throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't make colateral tx"); - } - - // make our change address - CReserveKey reservekey(pwalletMain); - //send the tx to the network - pwalletMain->CommitTransaction(wtx, reservekey, NetMsgType::IX); - - return wtx.GetHash().ToString(); - } - - if(strCommand == "submit") - { - if (params.size() != 3) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'mnfinalbudget submit comma-separated-hashes collateralhash'"); - - std::string strHashes = params[1].get_str(); - std::istringstream ss(strHashes); - std::string token; - - std::vector vecTxBudgetPayments; - - uint256 nColHash = uint256S(params[2].get_str()); - - while(std::getline(ss, token, ',')) { - uint256 nHash = uint256S(token); - CBudgetProposal* prop = governance.FindProposal(nHash); - - CTxBudgetPayment txBudgetPayment; - txBudgetPayment.nProposalHash = prop->GetHash(); - txBudgetPayment.payee = prop->GetPayee(); - txBudgetPayment.nAmount = prop->GetAllotted(); - vecTxBudgetPayments.push_back(txBudgetPayment); - - // printf("%lld\n", txBudgetPayment.nAmount); - } - - if(vecTxBudgetPayments.size() < 1) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "Invalid finalized proposal"); - } - - LOCK(cs_main); - CBlockIndex* pindex = chainActive.Tip(); - if(!pindex) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Invalid chaintip"); - - int nBlockStart = pindex->nHeight - pindex->nHeight % Params().GetConsensus().nBudgetPaymentsCycleBlocks + Params().GetConsensus().nBudgetPaymentsCycleBlocks; - - // CTxIn in(COutPoint(nColHash, 0)); - // int conf = GetInputAgeIX(nColHash, in); - - // Wait will we have 1 extra confirmation, otherwise some clients might reject this feeTX - // -- This function is tied to NewBlock, so we will propagate this budget while the block is also propagating - - // if(conf < BUDGET_FEE_CONFIRMATIONS+1){ - // printf ("Collateral requires at least %d confirmations - %s - %d confirmations\n", BUDGET_FEE_CONFIRMATIONS, nColHash.ToString().c_str(), conf); - // return "invalid collateral"; - // } - - //create the proposal incase we're the first to make it - CFinalizedBudgetBroadcast finalizedBudgetBroadcast("main", nBlockStart, vecTxBudgetPayments, nColHash); - - std::string strError = ""; - if(!finalizedBudgetBroadcast.IsValid(pindex, strError)){ - // printf("CBudgetManager::SubmitFinalBudget - Invalid finalized budget - %s \n", strError.c_str()); - throw JSONRPCError(RPC_INTERNAL_ERROR, "Invalid finalized budget"); - } - - finalizedBudgetBroadcast.Relay(); - budget.AddFinalizedBudget(finalizedBudgetBroadcast); - - return finalizedBudgetBroadcast.GetHash().ToString(); - } - - return NullUniValue; -} +} \ No newline at end of file diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index bd0f65196..cab88b9f1 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -340,7 +340,6 @@ static const CRPCCommand vRPCCommands[] = { "dash", "masternodebroadcast", &masternodebroadcast, true }, { "dash", "mnbudget", &mnbudget, true }, { "dash", "mnbudgetvoteraw", &mnbudgetvoteraw, true }, - { "dash", "mnfinalbudget", &mnfinalbudget, true }, { "dash", "mnsync", &mnsync, true }, { "dash", "spork", &spork, true }, { "dash", "getpoolinfo", &getpoolinfo, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index e6498dd10..210c9c008 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -266,7 +266,6 @@ extern UniValue masternodelist(const UniValue& params, bool fHelp); extern UniValue masternodebroadcast(const UniValue& params, bool fHelp); extern UniValue mnbudget(const UniValue& params, bool fHelp); extern UniValue mnbudgetvoteraw(const UniValue& params, bool fHelp); -extern UniValue mnfinalbudget(const UniValue& params, bool fHelp); extern UniValue mnsync(const UniValue& params, bool fHelp); extern UniValue getblockcount(const UniValue& params, bool fHelp); // in rpcblockchain.cpp diff --git a/src/sync.h b/src/sync.h index 34dd8c228..393a66906 100644 --- a/src/sync.h +++ b/src/sync.h @@ -14,11 +14,11 @@ #include -//////////////////////////////////////////////// -// // +///////////////////////////////////////////////// +// // // THE SIMPLE DEFINITION, EXCLUDING DEBUG CODE // -// // -//////////////////////////////////////////////// +// // +///////////////////////////////////////////////// /* CCriticalSection mutex;