From 40adfbf2c9620c35d25c08734e73b0bf90622cb0 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Thu, 30 Apr 2015 12:54:34 -0700 Subject: [PATCH] fixed --- src/masternode-budget.cpp | 94 +++++++++++++++++++----------------- src/masternode-budget.h | 4 +- src/rpcmasternode-budget.cpp | 18 +++---- 3 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index e84fd1b5e5..88a34f1cf6 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -375,10 +375,9 @@ std::string CBudgetProposal::GetName() } int CBudgetProposal::GetBlockStart() -{ +{ std::map mapList; - std::map::iterator it = mapVotes.begin(); while(it != mapVotes.end()) { @@ -391,11 +390,10 @@ int CBudgetProposal::GetBlockStart() } } - - //sort(mapList.begin(), mapList.end()); - //return myMap.begin()->second; - - return 0; + //sort the map and grab the highest count item + std::vector > vecList(mapList.begin(), mapList.end()); + std::sort(vecList.begin(),vecList.end()); + return vecList.begin()->second; } int CBudgetProposal::GetBlockEnd() @@ -414,9 +412,10 @@ int CBudgetProposal::GetBlockEnd() } } - // sort(mapList.begin(), mapList.end()); - // return myMap.begin()->first; - return 0; + //sort the map and grab the highest count item + std::vector > vecList(mapList.begin(), mapList.end()); + std::sort(vecList.begin(),vecList.end()); + return vecList.begin()->second; } int64_t CBudgetProposal::GetAmount() @@ -435,9 +434,10 @@ int64_t CBudgetProposal::GetAmount() } } - // sort(mapList.begin(), mapList.end()); - // return myMap.begin()->first; - return 0; + //sort the map and grab the highest count item + std::vector > vecList(mapList.begin(), mapList.end()); + std::sort(vecList.begin(),vecList.end()); + return vecList.begin()->second; } CScript CBudgetProposal::GetPayee() @@ -461,9 +461,10 @@ CScript CBudgetProposal::GetPayee() } - // sort(mapList.begin(), mapList.end()); - // return myMap.begin()->first; - return CScript(); + //sort the map and grab the highest count item + std::vector > vecList(mapList.begin(), mapList.end()); + std::sort(vecList.begin(),vecList.end()); + return vecList.begin()->second; } double CBudgetProposal::GetRatio() @@ -536,39 +537,44 @@ int64_t CBudgetManager::GetTotalBudget() //Need to review this function std::vector CBudgetManager::GetBudget() { + // ------- Sort budgets by Yes Count + std::map mapList; -/* std::map::iterator it = mapProposals.begin(); - while(it != mapProposals.end()) - uint256 hash = GetBudgetProposalHash((*it).second.strProposalName); - mapList[hash] = (*it).second.GetYeas(); - } - - //sort by yeas - sort(mapList.begin(), mapList.end()); - - */ - std::vector ret; - /* - int64_t nBudgetAllocated = 0; - int64_t nTotalBudget = GetTotalBudget(); - std::map::iterator it = mapProposals.begin(); while(it != mapProposals.end()) - { - if(nTotalBudget == nBudgetAllocated){ - (*it).second.SetAllotted(0); - } else if((*it).second.GetAmount() + nBudgetAllocated <= nTotalBudget()) { - (*it).second..SetAllotted((*it).GetAmount()); - nBudgetAllocated += (*it).second.GetAmount(); - } else { - //couldn't pay for the entire budget, so it'll be partially paid. - (*it).second.SetAllotted(nTotalBudget - nBudgetAllocated); - nBudgetAllocated = nTotalBudget; - } + mapList[GetBudgetProposalHash((*it).second.strProposalName)] = (*it).second.GetYeas(); + + //sort the map and grab the highest count item + std::vector > vecList(mapList.begin(), mapList.end()); + std::sort(vecList.begin(),vecList.end()); + + // ------- Grab The Budgets In Order + + std::vector ret; + + int64_t nBudgetAllocated = 0; + int64_t nTotalBudget = GetTotalBudget(); + + std::map::iterator it2 = mapProposals.begin(); + while(it2 != mapProposals.end()) + { + CBudgetProposal prop = (*it2).second; + + if(nTotalBudget == nBudgetAllocated){ + prop.SetAllotted(0); + } else if(prop.GetAmount() + nBudgetAllocated <= nTotalBudget) { + prop.SetAllotted(prop.GetAmount()); + nBudgetAllocated += prop.GetAmount(); + } else { + //couldn't pay for the entire budget, so it'll be partially paid. + prop.SetAllotted(nTotalBudget - nBudgetAllocated); + nBudgetAllocated = nTotalBudget; + } + + ret.push_back(&prop); + } - ret.insert(make_pair((*it).second.strProposalName, &(*it))) - }*/ return ret; } diff --git a/src/masternode-budget.h b/src/masternode-budget.h index f5f5b8bdc0..09fee9c390 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -143,8 +143,8 @@ public: int GetAbstains(); int64_t GetAmount(); - void SetAlloted(int64_t nAllotedIn) {nAlloted = nAllotedIn;} - int64_t GetAlloted() {return nAlloted;} + void SetAllotted(int64_t nAllotedIn) {nAlloted = nAllotedIn;} + int64_t GetAllotted() {return nAlloted;} ADD_SERIALIZE_METHODS; diff --git a/src/rpcmasternode-budget.cpp b/src/rpcmasternode-budget.cpp index e141f2120b..03679342b2 100644 --- a/src/rpcmasternode-budget.cpp +++ b/src/rpcmasternode-budget.cpp @@ -159,12 +159,12 @@ Value mnbudget(const Array& params, bool fHelp) if(prop == NULL) return "Unknown proposal name"; Object resultObj; - int64_t nTotalAlloted = 0; + int64_t nTotalAllotted = 0; std::vector winningProps = budget.GetBudget(); BOOST_FOREACH(CBudgetProposal* prop, winningProps) { - nTotalAlloted += prop->GetAlloted(); + nTotalAllotted += prop->GetAllotted(); CTxDestination address1; ExtractDestination(prop->GetPayee(), address1); @@ -179,8 +179,8 @@ Value mnbudget(const Array& params, bool fHelp) 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("Alloted", (int64_t)prop->GetAlloted())); - bObj.push_back(Pair("TotalBudgetAlloted", nTotalAlloted)); + bObj.push_back(Pair("Alloted", (int64_t)prop->GetAllotted())); + bObj.push_back(Pair("TotalBudgetAlloted", nTotalAllotted)); resultObj.push_back(Pair("masternode", bObj)); } @@ -211,7 +211,7 @@ Value mnbudget(const Array& params, bool fHelp) obj.push_back(Pair("Yeas", (int64_t)prop->GetYeas())); obj.push_back(Pair("Nays", (int64_t)prop->GetNays())); obj.push_back(Pair("Abstains", (int64_t)prop->GetAbstains())); - obj.push_back(Pair("Alloted", (int64_t)prop->GetAlloted())); + obj.push_back(Pair("Alloted", (int64_t)prop->GetAllotted())); return obj; } @@ -232,10 +232,10 @@ Value mnbudget(const Array& params, bool fHelp) int c = 0; - /* map::iterator it = prop->mapVotes.begin(); - for(it != prop->mapVotes.end()){ - obj.push_back(Pair((*it).second.nProposalName.c_str(), (*it).second.GetVoteString().c_str())); - }*/ + std::map::iterator it = prop->mapVotes.begin(); + while(it != prop->mapVotes.end()) + obj.push_back(Pair((*it).second.strProposalName.c_str(), (*it).second.GetVoteString().c_str())); + return obj; }