This commit is contained in:
Evan Duffield 2015-04-30 12:54:34 -07:00
parent b02d5260fd
commit 40adfbf2c9
3 changed files with 61 additions and 55 deletions

View File

@ -378,7 +378,6 @@ int CBudgetProposal::GetBlockStart()
{ {
std::map<int, int> mapList; std::map<int, int> mapList;
std::map<uint256, CBudgetVote>::iterator it = mapVotes.begin(); std::map<uint256, CBudgetVote>::iterator it = mapVotes.begin();
while(it != mapVotes.end()) { while(it != mapVotes.end()) {
@ -391,11 +390,10 @@ int CBudgetProposal::GetBlockStart()
} }
} }
//sort the map and grab the highest count item
//sort(mapList.begin(), mapList.end()); std::vector<std::pair<int,int> > vecList(mapList.begin(), mapList.end());
//return myMap.begin()->second; std::sort(vecList.begin(),vecList.end());
return vecList.begin()->second;
return 0;
} }
int CBudgetProposal::GetBlockEnd() int CBudgetProposal::GetBlockEnd()
@ -414,9 +412,10 @@ int CBudgetProposal::GetBlockEnd()
} }
} }
// sort(mapList.begin(), mapList.end()); //sort the map and grab the highest count item
// return myMap.begin()->first; std::vector<std::pair<int,int> > vecList(mapList.begin(), mapList.end());
return 0; std::sort(vecList.begin(),vecList.end());
return vecList.begin()->second;
} }
int64_t CBudgetProposal::GetAmount() int64_t CBudgetProposal::GetAmount()
@ -435,9 +434,10 @@ int64_t CBudgetProposal::GetAmount()
} }
} }
// sort(mapList.begin(), mapList.end()); //sort the map and grab the highest count item
// return myMap.begin()->first; std::vector<std::pair<int64_t,int> > vecList(mapList.begin(), mapList.end());
return 0; std::sort(vecList.begin(),vecList.end());
return vecList.begin()->second;
} }
CScript CBudgetProposal::GetPayee() CScript CBudgetProposal::GetPayee()
@ -461,9 +461,10 @@ CScript CBudgetProposal::GetPayee()
} }
// sort(mapList.begin(), mapList.end()); //sort the map and grab the highest count item
// return myMap.begin()->first; std::vector<std::pair<CScript,int> > vecList(mapList.begin(), mapList.end());
return CScript(); std::sort(vecList.begin(),vecList.end());
return vecList.begin()->second;
} }
double CBudgetProposal::GetRatio() double CBudgetProposal::GetRatio()
@ -536,39 +537,44 @@ int64_t CBudgetManager::GetTotalBudget()
//Need to review this function //Need to review this function
std::vector<CBudgetProposal*> CBudgetManager::GetBudget() std::vector<CBudgetProposal*> CBudgetManager::GetBudget()
{ {
// ------- Sort budgets by Yes Count
std::map<uint256, int> mapList; std::map<uint256, int> mapList;
/* std::map<uint256, CBudgetProposal>::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<CBudgetProposal*> ret;
/*
int64_t nBudgetAllocated = 0;
int64_t nTotalBudget = GetTotalBudget();
std::map<uint256, CBudgetProposal>::iterator it = mapProposals.begin(); std::map<uint256, CBudgetProposal>::iterator it = mapProposals.begin();
while(it != mapProposals.end()) while(it != mapProposals.end())
{ mapList[GetBudgetProposalHash((*it).second.strProposalName)] = (*it).second.GetYeas();
if(nTotalBudget == nBudgetAllocated){
(*it).second.SetAllotted(0); //sort the map and grab the highest count item
} else if((*it).second.GetAmount() + nBudgetAllocated <= nTotalBudget()) { std::vector<std::pair<uint256,int> > vecList(mapList.begin(), mapList.end());
(*it).second..SetAllotted((*it).GetAmount()); std::sort(vecList.begin(),vecList.end());
nBudgetAllocated += (*it).second.GetAmount();
} else { // ------- Grab The Budgets In Order
//couldn't pay for the entire budget, so it'll be partially paid.
(*it).second.SetAllotted(nTotalBudget - nBudgetAllocated); std::vector<CBudgetProposal*> ret;
nBudgetAllocated = nTotalBudget;
} int64_t nBudgetAllocated = 0;
int64_t nTotalBudget = GetTotalBudget();
std::map<uint256, CBudgetProposal>::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; return ret;
} }

View File

@ -143,8 +143,8 @@ public:
int GetAbstains(); int GetAbstains();
int64_t GetAmount(); int64_t GetAmount();
void SetAlloted(int64_t nAllotedIn) {nAlloted = nAllotedIn;} void SetAllotted(int64_t nAllotedIn) {nAlloted = nAllotedIn;}
int64_t GetAlloted() {return nAlloted;} int64_t GetAllotted() {return nAlloted;}
ADD_SERIALIZE_METHODS; ADD_SERIALIZE_METHODS;

View File

@ -159,12 +159,12 @@ Value mnbudget(const Array& params, bool fHelp)
if(prop == NULL) return "Unknown proposal name"; if(prop == NULL) return "Unknown proposal name";
Object resultObj; Object resultObj;
int64_t nTotalAlloted = 0; int64_t nTotalAllotted = 0;
std::vector<CBudgetProposal*> winningProps = budget.GetBudget(); std::vector<CBudgetProposal*> winningProps = budget.GetBudget();
BOOST_FOREACH(CBudgetProposal* prop, winningProps) BOOST_FOREACH(CBudgetProposal* prop, winningProps)
{ {
nTotalAlloted += prop->GetAlloted(); nTotalAllotted += prop->GetAllotted();
CTxDestination address1; CTxDestination address1;
ExtractDestination(prop->GetPayee(), 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("Yeas", (int64_t)prop->GetYeas()));
bObj.push_back(Pair("Nays", (int64_t)prop->GetNays())); bObj.push_back(Pair("Nays", (int64_t)prop->GetNays()));
bObj.push_back(Pair("Abstains", (int64_t)prop->GetAbstains())); bObj.push_back(Pair("Abstains", (int64_t)prop->GetAbstains()));
bObj.push_back(Pair("Alloted", (int64_t)prop->GetAlloted())); bObj.push_back(Pair("Alloted", (int64_t)prop->GetAllotted()));
bObj.push_back(Pair("TotalBudgetAlloted", nTotalAlloted)); bObj.push_back(Pair("TotalBudgetAlloted", nTotalAllotted));
resultObj.push_back(Pair("masternode", bObj)); 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("Yeas", (int64_t)prop->GetYeas()));
obj.push_back(Pair("Nays", (int64_t)prop->GetNays())); obj.push_back(Pair("Nays", (int64_t)prop->GetNays()));
obj.push_back(Pair("Abstains", (int64_t)prop->GetAbstains())); 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; return obj;
} }
@ -232,10 +232,10 @@ Value mnbudget(const Array& params, bool fHelp)
int c = 0; int c = 0;
/* map<uint256, CBudgetVote>::iterator it = prop->mapVotes.begin(); std::map<uint256, CBudgetVote>::iterator it = prop->mapVotes.begin();
for(it != prop->mapVotes.end()){ while(it != prop->mapVotes.end())
obj.push_back(Pair((*it).second.nProposalName.c_str(), (*it).second.GetVoteString().c_str())); obj.push_back(Pair((*it).second.strProposalName.c_str(), (*it).second.GetVoteString().c_str()));
}*/
return obj; return obj;
} }