2016-12-20 14:26:45 +01:00
|
|
|
// Copyright (c) 2014-2017 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.
|
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"
|
|
|
|
|
2016-04-08 19:47:00 +02:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2016-05-23 19:53:05 +02:00
|
|
|
class CGovernanceVote;
|
2016-04-08 19:47:00 +02:00
|
|
|
|
2016-04-14 22:01:15 +02:00
|
|
|
// INTENTION OF MASTERNODES REGARDING ITEM
|
2016-09-08 13:40:19 +02:00
|
|
|
enum vote_outcome_enum_t {
|
|
|
|
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:
|
|
|
|
enum vote_signal_enum_t {
|
|
|
|
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)
|
|
|
|
VOTE_SIGNAL_NOOP1 =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VOTE_SIGNAL_CUSTOM20 = 35
|
|
|
|
};
|
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:
|
2016-09-08 13:40:19 +02:00
|
|
|
static vote_outcome_enum_t ConvertVoteOutcome(std::string strVoteOutcome);
|
|
|
|
static vote_signal_enum_t ConvertVoteSignal(std::string strVoteSignal);
|
|
|
|
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
|
|
|
//
|
2016-05-23 19:53:05 +02:00
|
|
|
// CGovernanceVote - Allow a masternode node 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:
|
2016-04-08 19:47:00 +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
|
2016-04-14 22:01:15 +02:00
|
|
|
CTxIn vinMasternode;
|
|
|
|
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;
|
|
|
|
|
2016-09-08 13:40:19 +02:00
|
|
|
public:
|
2016-05-23 19:53:05 +02:00
|
|
|
CGovernanceVote();
|
2017-09-11 16:13:48 +02:00
|
|
|
CGovernanceVote(COutPoint outpointMasternodeIn, 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; }
|
|
|
|
|
2016-10-17 20:54:28 +02:00
|
|
|
vote_signal_enum_t GetSignal() const { return vote_signal_enum_t(nVoteSignal); }
|
2016-09-08 13:40:19 +02:00
|
|
|
|
2016-10-17 20:54:28 +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; }
|
|
|
|
|
|
|
|
void SetTime(int64_t nTimeIn) { nTime = nTimeIn; }
|
|
|
|
|
|
|
|
void SetSignature(const std::vector<unsigned char>& vchSigIn) { vchSig = vchSigIn; }
|
2016-04-08 19:47:00 +02:00
|
|
|
|
|
|
|
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
|
2016-11-13 18:52:34 +01:00
|
|
|
bool IsValid(bool fSignatureCheck) const;
|
|
|
|
void Relay() const;
|
|
|
|
|
|
|
|
std::string GetVoteString() const {
|
|
|
|
return CGovernanceVoting::ConvertOutcomeToString(GetOutcome());
|
|
|
|
}
|
2016-04-08 19:47:00 +02:00
|
|
|
|
2017-09-11 16:13:48 +02:00
|
|
|
const COutPoint& GetMasternodeOutpoint() const { return vinMasternode.prevout; }
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint256 GetHash() const
|
|
|
|
{
|
2016-04-08 19:47:00 +02:00
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
2016-04-14 22:01:15 +02:00
|
|
|
ss << vinMasternode;
|
|
|
|
ss << nParentHash;
|
2016-05-23 19:53:05 +02:00
|
|
|
ss << nVoteSignal;
|
2016-04-14 22:01:15 +02:00
|
|
|
ss << nVoteOutcome;
|
2016-04-08 19:47:00 +02:00
|
|
|
ss << nTime;
|
|
|
|
return ss.GetHash();
|
|
|
|
}
|
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
std::string ToString() const
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2016-10-17 20:54:28 +02:00
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << vinMasternode.ToString() << ":"
|
|
|
|
<< nTime << ":"
|
|
|
|
<< CGovernanceVoting::ConvertOutcomeToString(GetOutcome()) << ":"
|
|
|
|
<< CGovernanceVoting::ConvertSignalToString(GetSignal());
|
|
|
|
return ostr.str();
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 08:57:16 +02:00
|
|
|
/**
|
|
|
|
* GetTypeHash()
|
|
|
|
*
|
|
|
|
* GET HASH WITH DETERMINISTIC VALUE OF MASTERNODE-VIN/PARENT-HASH/VOTE-SIGNAL
|
|
|
|
*
|
2016-09-12 09:40:00 +02:00
|
|
|
* This hash collides with previous masternode votes when they update their votes on governance objects.
|
|
|
|
* With 12.1 there's various types of votes (funding, valid, delete, etc), so this is the deterministic hash
|
2016-06-08 08:57:16 +02:00
|
|
|
* that will collide with the previous vote and allow the system to update.
|
2016-09-12 09:40:00 +02:00
|
|
|
*
|
2016-06-08 08:57:16 +02:00
|
|
|
* --
|
|
|
|
*
|
|
|
|
* We do not include an outcome, because that can change when a masternode updates their vote from yes to no
|
2016-09-12 09:40:00 +02:00
|
|
|
* on funding a specific project for example.
|
2016-06-08 08:57:16 +02:00
|
|
|
* We do not include a time because it will be updated each time the vote is updated, changing the hash
|
|
|
|
*/
|
|
|
|
uint256 GetTypeHash() const
|
2016-09-12 09:40:00 +02:00
|
|
|
{
|
2016-06-08 08:57:16 +02:00
|
|
|
// CALCULATE HOW TO STORE VOTE IN governance.mapVotes
|
|
|
|
|
|
|
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
|
|
|
ss << vinMasternode;
|
|
|
|
ss << nParentHash;
|
|
|
|
ss << nVoteSignal;
|
2016-09-12 09:40:00 +02:00
|
|
|
// -- no outcome
|
2016-06-08 08:57:16 +02:00
|
|
|
// -- timeless
|
|
|
|
return ss.GetHash();
|
|
|
|
}
|
|
|
|
|
2016-04-08 19:47:00 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2016-04-14 22:01:15 +02:00
|
|
|
READWRITE(vinMasternode);
|
|
|
|
READWRITE(nParentHash);
|
|
|
|
READWRITE(nVoteOutcome);
|
2016-05-23 19:53:05 +02:00
|
|
|
READWRITE(nVoteSignal);
|
2016-04-08 19:47:00 +02:00
|
|
|
READWRITE(nTime);
|
|
|
|
READWRITE(vchSig);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-14 20:53:46 +02:00
|
|
|
|
2016-11-13 18:52:34 +01:00
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
/**
|
2016-04-14 20:53:46 +02:00
|
|
|
* 12.1.1 - CGovernanceVoteManager
|
|
|
|
* -------------------------------
|
|
|
|
*
|
|
|
|
|
|
|
|
GetVote(name, yes_no):
|
|
|
|
- caching function
|
|
|
|
- mark last accessed votes
|
|
|
|
- load serialized files from filesystem if needed
|
|
|
|
- calc answer
|
|
|
|
- return result
|
2016-09-12 09:40:00 +02:00
|
|
|
|
2016-04-14 20:53:46 +02:00
|
|
|
CacheUnused():
|
|
|
|
- Cache votes if lastused > 12h/24/48/etc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2016-04-14 00:41:40 +02:00
|
|
|
#endif
|