Dash Core  0.12.2.1
P2P Digital Currency
governance-vote.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2017 The Dash Core developers
2 
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef GOVERNANCE_VOTE_H
6 #define GOVERNANCE_VOTE_H
7 
8 #include "key.h"
10 
11 #include <boost/lexical_cast.hpp>
12 
13 using namespace std;
14 
15 class CGovernanceVote;
16 class CConnman;
17 
18 // INTENTION OF MASTERNODES REGARDING ITEM
24 };
25 
26 
27 // SIGNAL VARIOUS THINGS TO HAPPEN:
30  VOTE_SIGNAL_FUNDING = 1, // -- fund this object for it's stated amount
31  VOTE_SIGNAL_VALID = 2, // -- this object checks out in sentinel engine
32  VOTE_SIGNAL_DELETE = 3, // -- this object should be deleted from memory entirely
33  VOTE_SIGNAL_ENDORSED = 4, // -- officially endorsed by the network somehow (delegation)
34  VOTE_SIGNAL_NOOP1 = 5, // FOR FURTHER EXPANSION
45  VOTE_SIGNAL_CUSTOM1 = 16, // SENTINEL CUSTOM ACTIONS
46  VOTE_SIGNAL_CUSTOM2 = 17, // 16-35
65 };
66 
68 
76 {
77 public:
78  static vote_outcome_enum_t ConvertVoteOutcome(std::string strVoteOutcome);
79  static vote_signal_enum_t ConvertVoteSignal(std::string strVoteSignal);
80  static std::string ConvertOutcomeToString(vote_outcome_enum_t nOutcome);
81  static std::string ConvertSignalToString(vote_signal_enum_t nSignal);
82 };
83 
84 //
85 // CGovernanceVote - Allow a masternode node to vote and broadcast throughout the network
86 //
87 
89 {
90  friend bool operator==(const CGovernanceVote& vote1, const CGovernanceVote& vote2);
91 
92  friend bool operator<(const CGovernanceVote& vote1, const CGovernanceVote& vote2);
93 
94 private:
95  bool fValid; //if the vote is currently valid / counted
96  bool fSynced; //if we've sent this to our peers
97  int nVoteSignal; // see VOTE_ACTIONS above
100  int nVoteOutcome; // see VOTE_OUTCOMES above
101  int64_t nTime;
102  std::vector<unsigned char> vchSig;
103 
104 public:
105  CGovernanceVote();
106  CGovernanceVote(COutPoint outpointMasternodeIn, uint256 nParentHashIn, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn);
107 
108  bool IsValid() const { return fValid; }
109 
110  bool IsSynced() const { return fSynced; }
111 
112  int64_t GetTimestamp() const { return nTime; }
113 
114  vote_signal_enum_t GetSignal() const { return vote_signal_enum_t(nVoteSignal); }
115 
116  vote_outcome_enum_t GetOutcome() const { return vote_outcome_enum_t(nVoteOutcome); }
117 
118  const uint256& GetParentHash() const { return nParentHash; }
119 
120  void SetTime(int64_t nTimeIn) { nTime = nTimeIn; }
121 
122  void SetSignature(const std::vector<unsigned char>& vchSigIn) { vchSig = vchSigIn; }
123 
124  bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
125  bool IsValid(bool fSignatureCheck) const;
126  void Relay(CConnman& connman) const;
127 
128  std::string GetVoteString() const {
129  return CGovernanceVoting::ConvertOutcomeToString(GetOutcome());
130  }
131 
132  const COutPoint& GetMasternodeOutpoint() const { return vinMasternode.prevout; }
133 
140  uint256 GetHash() const
141  {
143  ss << vinMasternode;
144  ss << nParentHash;
145  ss << nVoteSignal;
146  ss << nVoteOutcome;
147  ss << nTime;
148  return ss.GetHash();
149  }
150 
151  std::string ToString() const
152  {
153  std::ostringstream ostr;
154  ostr << vinMasternode.ToString() << ":"
155  << nTime << ":"
156  << CGovernanceVoting::ConvertOutcomeToString(GetOutcome()) << ":"
158  return ostr.str();
159  }
160 
177  {
178  // CALCULATE HOW TO STORE VOTE IN governance.mapVotes
179 
181  ss << vinMasternode;
182  ss << nParentHash;
183  ss << nVoteSignal;
184  // -- no outcome
185  // -- timeless
186  return ss.GetHash();
187  }
188 
190 
191  template <typename Stream, typename Operation>
192  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
193  READWRITE(vinMasternode);
194  READWRITE(nParentHash);
195  READWRITE(nVoteOutcome);
196  READWRITE(nVoteSignal);
197  READWRITE(nTime);
198  READWRITE(vchSig);
199  }
200 
201 };
202 
203 
204 
222 #endif
bool IsSynced() const
int64_t GetTimestamp() const
#define READWRITE(obj)
Definition: serialize.h:175
uint256 GetTypeHash() const
Definition: net.h:108
vote_outcome_enum_t GetOutcome() const
std::string GetVoteString() const
uint256 GetHash() const
uint256 GetHash()
Definition: hash.h:254
vote_signal_enum_t GetSignal() const
void SetTime(int64_t nTimeIn)
COutPoint prevout
Definition: transaction.h:61
std::string ToString() const
Definition: transaction.cpp:36
const COutPoint & GetMasternodeOutpoint() const
std::string ToString() const
bool operator==(const CGovernanceVote &vote1, const CGovernanceVote &vote2)
bool IsValid() const
void SetSignature(const std::vector< unsigned char > &vchSigIn)
std::vector< unsigned char > vchSig
const uint256 & GetParentHash() const
static const int PROTOCOL_VERSION
Definition: version.h:13
vote_outcome_enum_t
vote_signal_enum_t
static std::string ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
static std::string ConvertSignalToString(vote_signal_enum_t nSignal)
Definition: pubkey.h:37
Definition: key.h:35
static const int MAX_SUPPORTED_VOTE_SIGNAL
bool operator<(const vote_time_pair_t &p1, const vote_time_pair_t &p2)
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)