Added CleanAndRemove for Proposal votes

This commit is contained in:
Evan Duffield 2015-07-04 15:49:42 -07:00
parent 2b949e08a8
commit edaf479063
2 changed files with 21 additions and 1 deletions

View File

@ -465,6 +465,8 @@ std::vector<CBudgetProposal*> CBudgetManager::GetAllProposals()
std::map<uint256, CBudgetProposal>::iterator it2 = mapProposals.begin();
while(it2 != mapProposals.end())
{
(*it).second.CleanAndRemove();
CBudgetProposal* prop = &((*it2).second);
ret.push_back(prop);
@ -483,6 +485,7 @@ std::vector<CBudgetProposal*> CBudgetManager::GetBudget()
std::map<uint256, CBudgetProposal>::iterator it = mapProposals.begin();
while(it != mapProposals.end()){
(*it).second.CleanAndRemove();
mapList.insert(make_pair((*it).second.GetHash(), (*it).second.GetYeas()));
++it;
}
@ -953,6 +956,21 @@ void CBudgetProposal::AddOrUpdateVote(CBudgetVote& vote)
mapVotes[hash] = vote;
}
// If masternode voted for a proposal, but is now invalid -- remove the vote
void CBudgetProposal::CleanAndRemove()
{
std::map<uint256, CBudgetVote>::iterator it = mapVotes.begin();
while(it != mapVotes.end()) {
if ((*it).second.SignatureValid())
{
++it;
} else {
mapVotes.erase(it++);
}
}
}
double CBudgetProposal::GetRatio()
{
int yeas = 0;

View File

@ -385,6 +385,8 @@ public:
void SetAllotted(int64_t nAllotedIn) {nAlloted = nAllotedIn;}
int64_t GetAllotted() {return nAlloted;}
void CleanAndRemove();
uint256 GetHash(){
/*
vin is not included on purpose