Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

governance-vote.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2019 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 #ifndef GOVERNANCE_VOTE_H
6 #define GOVERNANCE_VOTE_H
7 
8 #include <key.h>
10 #include <bls/bls.h>
11 
12 class CGovernanceVote;
13 class CConnman;
14 
15 // INTENTION OF MASTERNODES REGARDING ITEM
21 };
22 
23 
24 // SIGNAL VARIOUS THINGS TO HAPPEN:
27  VOTE_SIGNAL_FUNDING = 1, // -- fund this object for it's stated amount
28  VOTE_SIGNAL_VALID = 2, // -- this object checks out in sentinel engine
29  VOTE_SIGNAL_DELETE = 3, // -- this object should be deleted from memory entirely
30  VOTE_SIGNAL_ENDORSED = 4, // -- officially endorsed by the network somehow (delegation)
31 };
32 
34 
42 {
43 public:
44  static vote_outcome_enum_t ConvertVoteOutcome(const std::string& strVoteOutcome);
45  static vote_signal_enum_t ConvertVoteSignal(const std::string& strVoteSignal);
46  static std::string ConvertOutcomeToString(vote_outcome_enum_t nOutcome);
47  static std::string ConvertSignalToString(vote_signal_enum_t nSignal);
48 };
49 
50 //
51 // CGovernanceVote - Allow a masternode to vote and broadcast throughout the network
52 //
53 
55 {
56  friend bool operator==(const CGovernanceVote& vote1, const CGovernanceVote& vote2);
57 
58  friend bool operator<(const CGovernanceVote& vote1, const CGovernanceVote& vote2);
59 
60 private:
61  bool fValid; //if the vote is currently valid / counted
62  bool fSynced; //if we've sent this to our peers
63  int nVoteSignal; // see VOTE_ACTIONS above
66  int nVoteOutcome; // see VOTE_OUTCOMES above
67  int64_t nTime;
68  std::vector<unsigned char> vchSig;
69 
71  const uint256 hash;
72  void UpdateHash() const;
73 
74 public:
76  CGovernanceVote(const COutPoint& outpointMasternodeIn, const uint256& nParentHashIn, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn);
77 
78  bool IsValid() const { return fValid; }
79 
80  bool IsSynced() const { return fSynced; }
81 
82  int64_t GetTimestamp() const { return nTime; }
83 
85 
87 
88  const uint256& GetParentHash() const { return nParentHash; }
89 
90  void SetTime(int64_t nTimeIn)
91  {
92  nTime = nTimeIn;
93  UpdateHash();
94  }
95 
96  void SetSignature(const std::vector<unsigned char>& vchSigIn) { vchSig = vchSigIn; }
97 
98  bool Sign(const CKey& key, const CKeyID& keyID);
99  bool CheckSignature(const CKeyID& keyID) const;
100  bool Sign(const CBLSSecretKey& key);
101  bool CheckSignature(const CBLSPublicKey& pubKey) const;
102  bool IsValid(bool useVotingKey) const;
103  void Relay(CConnman& connman) const;
104 
106 
113  uint256 GetHash() const;
114  uint256 GetSignatureHash() const;
115 
116  std::string ToString() const;
117 
119 
120  template <typename Stream, typename Operation>
121  inline void SerializationOp(Stream& s, Operation ser_action)
122  {
127  READWRITE(nTime);
128  if (!(s.GetType() & SER_GETHASH)) {
129  READWRITE(vchSig);
130  }
131  if (ser_action.ForRead())
132  UpdateHash();
133  }
134 };
135 
136 #endif
const uint256 & GetParentHash() const
uint256 GetHash() const
GetHash()
#define READWRITE(obj)
Definition: serialize.h:165
COutPoint masternodeOutpoint
std::vector< unsigned char > vchSig
vote_outcome_enum_t GetOutcome() const
static vote_signal_enum_t ConvertVoteSignal(const std::string &strVoteSignal)
bool IsSynced() const
static std::string ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
const uint256 hash
Memory only.
bool IsValid() const
const COutPoint & GetMasternodeOutpoint() const
uint256 GetSignatureHash() const
int64_t GetTimestamp() const
vote_signal_enum_t GetSignal() const
void SerializationOp(Stream &s, Operation ser_action)
bool CheckSignature(const CKeyID &keyID) const
Definition: net.h:136
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
friend bool operator==(const CGovernanceVote &vote1, const CGovernanceVote &vote2)
void SetTime(int64_t nTimeIn)
256-bit opaque blob.
Definition: uint256.h:123
void SetSignature(const std::vector< unsigned char > &vchSigIn)
friend bool operator<(const CGovernanceVote &vote1, const CGovernanceVote &vote2)
vote_outcome_enum_t
void Relay(CConnman &connman) const
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
vote_signal_enum_t
Governance Voting.
An encapsulated private key.
Definition: key.h:27
bool Sign(const CKey &key, const CKeyID &keyID)
static std::string ConvertSignalToString(vote_signal_enum_t nSignal)
void UpdateHash() const
static const int MAX_SUPPORTED_VOTE_SIGNAL
static vote_outcome_enum_t ConvertVoteOutcome(const std::string &strVoteOutcome)
std::string ToString() const
Released under the MIT license