From edaf4790632594533a2230e1e4fc0791d9e613a9 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Sat, 4 Jul 2015 15:49:42 -0700 Subject: [PATCH] Added CleanAndRemove for Proposal votes --- src/masternode-budget.cpp | 20 +++++++++++++++++++- src/masternode-budget.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index b6fc8f341..f10a1aeb0 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -465,8 +465,10 @@ std::vector CBudgetManager::GetAllProposals() std::map::iterator it2 = mapProposals.begin(); while(it2 != mapProposals.end()) { + (*it).second.CleanAndRemove(); + CBudgetProposal* prop = &((*it2).second); - ret.push_back(prop); + ret.push_back(prop); it2++; } @@ -483,6 +485,7 @@ std::vector CBudgetManager::GetBudget() std::map::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::iterator it = mapVotes.begin(); + + while(it != mapVotes.end()) { + if ((*it).second.SignatureValid()) + { + ++it; + } else { + mapVotes.erase(it++); + } + } +} + double CBudgetProposal::GetRatio() { int yeas = 0; diff --git a/src/masternode-budget.h b/src/masternode-budget.h index dcfd1f4c4..f9733a327 100644 --- a/src/masternode-budget.h +++ b/src/masternode-budget.h @@ -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