From 6becaf046230b106003d37e3f9a88562aeef8839 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Fri, 3 Jul 2015 10:54:10 -0700 Subject: [PATCH] Added mnbudget projection and changed "show" - Show now shows every proposal that is known, which seems to be the general expected behavior of the users - Added "projection" for showing what will end up in the budget if it was finalized currently --- configure.ac | 2 +- src/clientversion.h | 2 +- src/masternode-budget.cpp | 17 +++++++++++++++- src/masternode-budget.h | 1 + src/rpcmasternode-budget.cpp | 38 ++++++++++++++++++++++++++++++++++-- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index b4873074c..610d215eb 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 12) define(_CLIENT_VERSION_REVISION, 0) -define(_CLIENT_VERSION_BUILD, 7) +define(_CLIENT_VERSION_BUILD, 8) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2015) AC_INIT([Dash Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@dashpay.io],[dash]) diff --git a/src/clientversion.h b/src/clientversion.h index caaf788c3..5183a012d 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -17,7 +17,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 12 #define CLIENT_VERSION_REVISION 0 -#define CLIENT_VERSION_BUILD 7 +#define CLIENT_VERSION_BUILD 8 //! Set to true for release, false for prerelease or test build #define CLIENT_VERSION_IS_RELEASE true diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index b0bb25cc5..a8e93abfd 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -458,6 +458,22 @@ bool CBudgetManager::IsTransactionValid(const CTransaction& txNew, int nBlockHei return false; } +std::vector CBudgetManager::GetAllProposals() +{ + std::vector ret; + + std::map::iterator it2 = mapProposals.begin(); + while(it2 != mapProposals.end()) + { + CBudgetProposal* prop = &((*it2).second); + ret.push_back(prop); + + it2++; + } + + return ret; +} + //Need to review this function std::vector CBudgetManager::GetBudget() { @@ -496,7 +512,6 @@ std::vector CBudgetManager::GetBudget() //prop start/end should be inside this period if(prop->nBlockStart <= nBlockStart && prop->nBlockEnd >= nBlockEnd) { - if(nTotalBudget == nBudgetAllocated){ prop->SetAllotted(0); } else if(prop->GetAmount() + nBudgetAllocated <= nTotalBudget) { diff --git a/src/masternode-budget.h b/src/masternode-budget.h index 38aaafce6..c3f6f3f25 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -103,6 +103,7 @@ public: int64_t GetTotalBudget(int nHeight); std::vector GetBudget(); + std::vector GetAllProposals(); std::vector GetFinalizedBudgets(); bool IsBudgetPaymentBlock(int nBlockHeight); void AddProposal(CBudgetProposal& prop); diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index 85b487b37..66bffafcc 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -25,7 +25,7 @@ Value mnbudget(const Array& params, bool fHelp) strCommand = params[0].get_str(); if (fHelp || - (strCommand != "vote-many" && strCommand != "vote" && strCommand != "getvotes" && strCommand != "getinfo" && strCommand != "show")) + (strCommand != "vote-many" && strCommand != "vote" && strCommand != "getvotes" && strCommand != "getinfo" && strCommand != "show" && strCommand != "projection")) throw runtime_error( "mnbudget \"command\"... ( \"passphrase\" )\n" "Vote or show current budgets\n" @@ -36,6 +36,7 @@ Value mnbudget(const Array& params, bool fHelp) " getvotes - Show current masternode budgets\n" " getinfo - Show current masternode budgets\n" " show - Show all budgets\n" + " projection - Show the projection of which proposals will be paid the next cycle\n" ); if(strCommand == "vote-many") @@ -227,7 +228,7 @@ Value mnbudget(const Array& params, bool fHelp) } - if(strCommand == "show") + if(strCommand == "projection") { Object resultObj; int64_t nTotalAllotted = 0; @@ -261,6 +262,39 @@ Value mnbudget(const Array& params, bool fHelp) return resultObj; } + if(strCommand == "show") + { + Object resultObj; + int64_t nTotalAllotted = 0; + + std::vector winningProps = budget.GetAllProposals(); + BOOST_FOREACH(CBudgetProposal* prop, winningProps) + { + nTotalAllotted += prop->GetAllotted(); + + CTxDestination address1; + ExtractDestination(prop->GetPayee(), address1); + CBitcoinAddress address2(address1); + + Object bObj; + bObj.push_back(Pair("URL", prop->GetURL())); + bObj.push_back(Pair("Hash", prop->GetHash().ToString().c_str())); + bObj.push_back(Pair("BlockStart", (int64_t)prop->GetBlockStart())); + bObj.push_back(Pair("BlockEnd", (int64_t)prop->GetBlockEnd())); + bObj.push_back(Pair("TotalPaymentCount", (int64_t)prop->GetTotalPaymentCount())); + bObj.push_back(Pair("RemainingPaymentCount", (int64_t)prop->GetRemainingPaymentCount())); + bObj.push_back(Pair("PaymentAddress", address2.ToString().c_str())); + bObj.push_back(Pair("Ratio", prop->GetRatio())); + bObj.push_back(Pair("Yeas", (int64_t)prop->GetYeas())); + bObj.push_back(Pair("Nays", (int64_t)prop->GetNays())); + bObj.push_back(Pair("Abstains", (int64_t)prop->GetAbstains())); + bObj.push_back(Pair("Amount", (int64_t)prop->GetAmount())); + resultObj.push_back(Pair(prop->GetName().c_str(), bObj)); + } + + return resultObj; + } + if(strCommand == "getinfo") { if (params.size() != 2)