2019-06-11 13:46:07 +02:00
|
|
|
// Copyright (c) 2014-2019 The Dash Core developers
|
2016-04-08 19:47:00 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2018-09-28 09:56:17 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
#ifndef GOVERNANCE_VOTE_H
|
|
|
|
#define GOVERNANCE_VOTE_H
|
2016-04-08 19:47:00 +02:00
|
|
|
|
|
|
|
#include "key.h"
|
2016-12-20 14:27:59 +01:00
|
|
|
#include "primitives/transaction.h"
|
2018-10-21 21:45:16 +02:00
|
|
|
#include "bls/bls.h"
|
2016-12-20 14:27:59 +01:00
|
|
|
|
2016-05-23 19:53:05 +02:00
|
|
|
class CGovernanceVote;
|
2017-09-19 16:51:38 +02:00
|
|
|
class CConnman;
|
2016-04-08 19:47:00 +02:00
|
|
|
|
2016-04-14 22:01:15 +02:00
|
|
|
// INTENTION OF MASTERNODES REGARDING ITEM
|
2018-09-28 09:56:17 +02:00
|
|
|
enum vote_outcome_enum_t {
|
2016-09-08 13:40:19 +02:00
|
|
|
VOTE_OUTCOME_NONE = 0,
|
|
|
|
VOTE_OUTCOME_YES = 1,
|
|
|
|
VOTE_OUTCOME_NO = 2,
|
|
|
|
VOTE_OUTCOME_ABSTAIN = 3
|
|
|
|
};
|
2016-04-14 22:01:15 +02:00
|
|
|
|
2016-04-08 19:47:00 +02:00
|
|
|
|
2016-09-08 13:40:19 +02:00
|
|
|
// SIGNAL VARIOUS THINGS TO HAPPEN:
|
2018-09-28 09:56:17 +02:00
|
|
|
enum vote_signal_enum_t {
|
2016-09-08 13:40:19 +02:00
|
|
|
VOTE_SIGNAL_NONE = 0,
|
|
|
|
VOTE_SIGNAL_FUNDING = 1, // -- fund this object for it's stated amount
|
|
|
|
VOTE_SIGNAL_VALID = 2, // -- this object checks out in sentinel engine
|
|
|
|
VOTE_SIGNAL_DELETE = 3, // -- this object should be deleted from memory entirely
|
|
|
|
VOTE_SIGNAL_ENDORSED = 4, // -- officially endorsed by the network somehow (delegation)
|
|
|
|
};
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
static const int MAX_SUPPORTED_VOTE_SIGNAL = VOTE_SIGNAL_ENDORSED;
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
/**
|
|
|
|
* Governance Voting
|
|
|
|
*
|
|
|
|
* Static class for accessing governance data
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CGovernanceVoting
|
|
|
|
{
|
|
|
|
public:
|
2018-02-12 13:49:00 +01:00
|
|
|
static vote_outcome_enum_t ConvertVoteOutcome(const std::string& strVoteOutcome);
|
|
|
|
static vote_signal_enum_t ConvertVoteSignal(const std::string& strVoteSignal);
|
2016-09-08 13:40:19 +02:00
|
|
|
static std::string ConvertOutcomeToString(vote_outcome_enum_t nOutcome);
|
|
|
|
static std::string ConvertSignalToString(vote_signal_enum_t nSignal);
|
2016-08-17 09:08:25 +02:00
|
|
|
};
|
|
|
|
|
2016-04-08 19:47:00 +02:00
|
|
|
//
|
2018-08-31 15:31:59 +02:00
|
|
|
// CGovernanceVote - Allow a masternode to vote and broadcast throughout the network
|
2016-04-08 19:47:00 +02:00
|
|
|
//
|
|
|
|
|
2016-05-23 19:53:05 +02:00
|
|
|
class CGovernanceVote
|
2016-04-14 00:41:40 +02:00
|
|
|
{
|
2016-11-13 18:52:34 +01:00
|
|
|
friend bool operator==(const CGovernanceVote& vote1, const CGovernanceVote& vote2);
|
|
|
|
|
|
|
|
friend bool operator<(const CGovernanceVote& vote1, const CGovernanceVote& vote2);
|
|
|
|
|
2016-09-08 13:40:19 +02:00
|
|
|
private:
|
2018-09-28 09:56:17 +02:00
|
|
|
bool fValid; //if the vote is currently valid / counted
|
|
|
|
bool fSynced; //if we've sent this to our peers
|
2016-05-23 19:53:05 +02:00
|
|
|
int nVoteSignal; // see VOTE_ACTIONS above
|
2018-02-15 08:29:44 +01:00
|
|
|
COutPoint masternodeOutpoint;
|
2016-04-14 22:01:15 +02:00
|
|
|
uint256 nParentHash;
|
2016-04-26 06:08:36 +02:00
|
|
|
int nVoteOutcome; // see VOTE_OUTCOMES above
|
2016-04-08 19:47:00 +02:00
|
|
|
int64_t nTime;
|
|
|
|
std::vector<unsigned char> vchSig;
|
|
|
|
|
2018-02-21 17:35:37 +01:00
|
|
|
/** Memory only. */
|
|
|
|
const uint256 hash;
|
|
|
|
void UpdateHash() const;
|
|
|
|
|
2016-09-08 13:40:19 +02:00
|
|
|
public:
|
2016-05-23 19:53:05 +02:00
|
|
|
CGovernanceVote();
|
2018-02-21 17:35:37 +01:00
|
|
|
CGovernanceVote(const COutPoint& outpointMasternodeIn, const uint256& nParentHashIn, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn);
|
2016-09-08 13:40:19 +02:00
|
|
|
|
|
|
|
bool IsValid() const { return fValid; }
|
|
|
|
|
|
|
|
bool IsSynced() const { return fSynced; }
|
|
|
|
|
|
|
|
int64_t GetTimestamp() const { return nTime; }
|
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
vote_signal_enum_t GetSignal() const { return vote_signal_enum_t(nVoteSignal); }
|
2016-09-08 13:40:19 +02:00
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
vote_outcome_enum_t GetOutcome() const { return vote_outcome_enum_t(nVoteOutcome); }
|
2016-09-08 13:40:19 +02:00
|
|
|
|
|
|
|
const uint256& GetParentHash() const { return nParentHash; }
|
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
void SetTime(int64_t nTimeIn)
|
|
|
|
{
|
|
|
|
nTime = nTimeIn;
|
|
|
|
UpdateHash();
|
|
|
|
}
|
2016-09-08 13:40:19 +02:00
|
|
|
|
|
|
|
void SetSignature(const std::vector<unsigned char>& vchSigIn) { vchSig = vchSigIn; }
|
2016-04-08 19:47:00 +02:00
|
|
|
|
2018-08-31 15:31:59 +02:00
|
|
|
bool Sign(const CKey& key, const CKeyID& keyID);
|
|
|
|
bool CheckSignature(const CKeyID& keyID) const;
|
2018-10-21 21:45:16 +02:00
|
|
|
bool Sign(const CBLSSecretKey& key);
|
|
|
|
bool CheckSignature(const CBLSPublicKey& pubKey) const;
|
2018-08-31 15:31:59 +02:00
|
|
|
bool IsValid(bool useVotingKey) const;
|
2017-09-19 16:51:38 +02:00
|
|
|
void Relay(CConnman& connman) const;
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2018-02-15 08:29:44 +01:00
|
|
|
const COutPoint& GetMasternodeOutpoint() const { return masternodeOutpoint; }
|
2016-10-17 20:54:28 +02:00
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
/**
|
|
|
|
* GetHash()
|
|
|
|
*
|
|
|
|
* GET UNIQUE HASH WITH DETERMINISTIC VALUE OF THIS SPECIFIC VOTE
|
|
|
|
*/
|
|
|
|
|
2018-02-16 15:54:53 +01:00
|
|
|
uint256 GetHash() const;
|
|
|
|
uint256 GetSignatureHash() const;
|
2016-04-08 19:47:00 +02:00
|
|
|
|
2018-04-20 12:53:23 +02:00
|
|
|
std::string ToString() const;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-04-08 19:47:00 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2018-09-28 09:56:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action)
|
|
|
|
{
|
2018-09-15 12:19:31 +02:00
|
|
|
READWRITE(masternodeOutpoint);
|
2016-04-14 22:01:15 +02:00
|
|
|
READWRITE(nParentHash);
|
|
|
|
READWRITE(nVoteOutcome);
|
2016-05-23 19:53:05 +02:00
|
|
|
READWRITE(nVoteSignal);
|
2016-04-08 19:47:00 +02:00
|
|
|
READWRITE(nTime);
|
2018-02-16 15:54:53 +01:00
|
|
|
if (!(s.GetType() & SER_GETHASH)) {
|
|
|
|
READWRITE(vchSig);
|
|
|
|
}
|
2018-02-21 17:35:37 +01:00
|
|
|
if (ser_action.ForRead())
|
|
|
|
UpdateHash();
|
2016-04-08 19:47:00 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-14 00:41:40 +02:00
|
|
|
#endif
|