Dash Core  0.12.2.1
P2P Digital Currency
governance-votedb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2017 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "governance-votedb.h"
6 
8  : nMemoryVotes(0),
9  listVotes(),
10  mapVoteIndex()
11 {}
12 
14  : nMemoryVotes(other.nMemoryVotes),
15  listVotes(other.listVotes),
16  mapVoteIndex()
17 {
18  RebuildIndex();
19 }
20 
22 {
23  listVotes.push_front(vote);
24  mapVoteIndex[vote.GetHash()] = listVotes.begin();
25  ++nMemoryVotes;
26 }
27 
29 {
30  vote_m_cit it = mapVoteIndex.find(nHash);
31  if(it == mapVoteIndex.end()) {
32  return false;
33  }
34  return true;
35 }
36 
38 {
39  vote_m_cit it = mapVoteIndex.find(nHash);
40  if(it == mapVoteIndex.end()) {
41  return false;
42  }
43  vote = *(it->second);
44  return true;
45 }
46 
47 std::vector<CGovernanceVote> CGovernanceObjectVoteFile::GetVotes() const
48 {
49  std::vector<CGovernanceVote> vecResult;
50  for(vote_l_cit it = listVotes.begin(); it != listVotes.end(); ++it) {
51  vecResult.push_back(*it);
52  }
53  return vecResult;
54 }
55 
57 {
58  vote_l_it it = listVotes.begin();
59  while(it != listVotes.end()) {
60  if(it->GetMasternodeOutpoint() == outpointMasternode) {
61  --nMemoryVotes;
62  mapVoteIndex.erase(it->GetHash());
63  listVotes.erase(it++);
64  }
65  else {
66  ++it;
67  }
68  }
69 }
70 
72 {
73  nMemoryVotes = other.nMemoryVotes;
74  listVotes = other.listVotes;
75  RebuildIndex();
76  return *this;
77 }
78 
80 {
81  mapVoteIndex.clear();
82  nMemoryVotes = 0;
83  vote_l_it it = listVotes.begin();
84  while(it != listVotes.end()) {
85  CGovernanceVote& vote = *it;
86  uint256 nHash = vote.GetHash();
87  if(mapVoteIndex.find(nHash) == mapVoteIndex.end()) {
88  mapVoteIndex[nHash] = it;
89  ++nMemoryVotes;
90  ++it;
91  }
92  else {
93  listVotes.erase(it++);
94  }
95  }
96 }
vote_l_t::iterator vote_l_it
std::vector< CGovernanceVote > GetVotes() const
void AddVote(const CGovernanceVote &vote)
bool GetVote(const uint256 &nHash, CGovernanceVote &vote) const
uint256 GetHash() const
void RemoveVotesFromMasternode(const COutPoint &outpointMasternode)
bool HasVote(const uint256 &nHash) const
CGovernanceObjectVoteFile & operator=(const CGovernanceObjectVoteFile &other)
vote_m_t::const_iterator vote_m_cit
vote_l_t::const_iterator vote_l_cit