mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
refactor: more CGovernanceVote
cleanups
This commit is contained in:
parent
efc8c99139
commit
c32fac079f
@ -548,14 +548,10 @@ std::vector<CGovernanceVote> CGovernanceManager::GetCurrentVotes(const uint256&
|
||||
vote_rec_t voteRecord;
|
||||
if (!govobj.GetCurrentMNVotes(mnpair.first, voteRecord)) continue;
|
||||
|
||||
for (const auto& voteInstancePair : voteRecord.mapInstances) {
|
||||
int signal = voteInstancePair.first;
|
||||
int outcome = voteInstancePair.second.eOutcome;
|
||||
int64_t nCreationTime = voteInstancePair.second.nCreationTime;
|
||||
|
||||
CGovernanceVote vote = CGovernanceVote(mnpair.first, nParentHash, (vote_signal_enum_t)signal, (vote_outcome_enum_t)outcome);
|
||||
vote.SetTime(nCreationTime);
|
||||
|
||||
for (const auto& [signal, vote_instance] : voteRecord.mapInstances) {
|
||||
CGovernanceVote vote = CGovernanceVote(mnpair.first, nParentHash, (vote_signal_enum_t)signal,
|
||||
vote_instance.eOutcome);
|
||||
vote.SetTime(vote_instance.nCreationTime);
|
||||
vecResult.push_back(vote);
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceM
|
||||
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
|
||||
return false;
|
||||
}
|
||||
if (eSignal > MAX_SUPPORTED_VOTE_SIGNAL) {
|
||||
if (eSignal < VOTE_SIGNAL_NONE || eSignal >= VOTE_SIGNAL_UNKNOWN) {
|
||||
std::ostringstream ostr;
|
||||
ostr << "CGovernanceObject::ProcessVote -- Unsupported vote signal: " << CGovernanceVoting::ConvertSignalToString(vote.GetSignal());
|
||||
LogPrintf("%s\n", ostr.str());
|
||||
|
@ -87,10 +87,10 @@ vote_signal_enum_t CGovernanceVoting::ConvertVoteSignal(const std::string& strVo
|
||||
|
||||
CGovernanceVote::CGovernanceVote(const COutPoint& outpointMasternodeIn, const uint256& nParentHashIn,
|
||||
vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) :
|
||||
nVoteSignal(eVoteSignalIn),
|
||||
masternodeOutpoint(outpointMasternodeIn),
|
||||
nParentHash(nParentHashIn),
|
||||
nVoteOutcome(eVoteOutcomeIn),
|
||||
nVoteSignal(eVoteSignalIn),
|
||||
nTime(GetAdjustedTime())
|
||||
{
|
||||
UpdateHash();
|
||||
@ -197,15 +197,15 @@ bool CGovernanceVote::IsValid(const CDeterministicMNList& tip_mn_list, bool useV
|
||||
return false;
|
||||
}
|
||||
|
||||
// support up to MAX_SUPPORTED_VOTE_SIGNAL, can be extended
|
||||
if (nVoteSignal > MAX_SUPPORTED_VOTE_SIGNAL) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid signal(%d) - %s\n", nVoteSignal, GetHash().ToString());
|
||||
if (nVoteSignal < VOTE_SIGNAL_NONE || nVoteSignal >= VOTE_SIGNAL_UNKNOWN) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid signal(%d) - %s\n",
|
||||
nVoteSignal, GetHash().ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 0=none, 1=yes, 2=no, 3=abstain. Beyond that reject votes
|
||||
if (nVoteOutcome > 3) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid outcome(%d) - %s\n", nVoteSignal, GetHash().ToString());
|
||||
if (nVoteOutcome < VOTE_OUTCOME_NONE || nVoteOutcome >= VOTE_OUTCOME_UNKNOWN) {
|
||||
LogPrint(BCLog::GOBJECT, "CGovernanceVote::IsValid -- Client attempted to vote on invalid outcome(%d) - %s\n",
|
||||
nVoteOutcome, GetHash().ToString());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -18,24 +18,25 @@ class CKeyID;
|
||||
class PeerManager;
|
||||
|
||||
// INTENTION OF MASTERNODES REGARDING ITEM
|
||||
enum vote_outcome_enum_t : uint8_t {
|
||||
enum vote_outcome_enum_t : int {
|
||||
VOTE_OUTCOME_NONE = 0,
|
||||
VOTE_OUTCOME_YES = 1,
|
||||
VOTE_OUTCOME_NO = 2,
|
||||
VOTE_OUTCOME_ABSTAIN = 3
|
||||
VOTE_OUTCOME_YES,
|
||||
VOTE_OUTCOME_NO,
|
||||
VOTE_OUTCOME_ABSTAIN,
|
||||
VOTE_OUTCOME_UNKNOWN
|
||||
};
|
||||
|
||||
template<> struct is_serializable_enum<vote_outcome_enum_t> : std::true_type {};
|
||||
|
||||
// SIGNAL VARIOUS THINGS TO HAPPEN:
|
||||
enum vote_signal_enum_t : uint8_t {
|
||||
enum vote_signal_enum_t : int {
|
||||
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_FUNDING, // -- fund this object for it's stated amount
|
||||
VOTE_SIGNAL_VALID, // -- this object checks out in sentinel engine
|
||||
VOTE_SIGNAL_DELETE, // -- this object should be deleted from memory entirely
|
||||
VOTE_SIGNAL_ENDORSED, // -- officially endorsed by the network somehow (delegation)
|
||||
VOTE_SIGNAL_UNKNOWN
|
||||
};
|
||||
|
||||
static constexpr int MAX_SUPPORTED_VOTE_SIGNAL = VOTE_SIGNAL_ENDORSED;
|
||||
template<> struct is_serializable_enum<vote_signal_enum_t> : std::true_type {};
|
||||
|
||||
/**
|
||||
* Governance Voting
|
||||
@ -63,10 +64,10 @@ class CGovernanceVote
|
||||
friend bool operator<(const CGovernanceVote& vote1, const CGovernanceVote& vote2);
|
||||
|
||||
private:
|
||||
int nVoteSignal{VOTE_SIGNAL_NONE}; // see VOTE_ACTIONS above
|
||||
COutPoint masternodeOutpoint;
|
||||
uint256 nParentHash;
|
||||
int nVoteOutcome{VOTE_OUTCOME_NONE}; // see VOTE_OUTCOMES above
|
||||
vote_outcome_enum_t nVoteOutcome{VOTE_OUTCOME_NONE};
|
||||
vote_signal_enum_t nVoteSignal{VOTE_SIGNAL_NONE};
|
||||
int64_t nTime{0};
|
||||
std::vector<unsigned char> vchSig;
|
||||
|
||||
@ -80,9 +81,9 @@ public:
|
||||
|
||||
int64_t GetTimestamp() const { return nTime; }
|
||||
|
||||
vote_signal_enum_t GetSignal() const { return vote_signal_enum_t(nVoteSignal); }
|
||||
vote_signal_enum_t GetSignal() const { return nVoteSignal; }
|
||||
|
||||
vote_outcome_enum_t GetOutcome() const { return vote_outcome_enum_t(nVoteOutcome); }
|
||||
vote_outcome_enum_t GetOutcome() const { return nVoteOutcome; }
|
||||
|
||||
const uint256& GetParentHash() const { return nParentHash; }
|
||||
|
||||
|
@ -39,7 +39,7 @@ enum class TransactionError;
|
||||
struct CNodeStateStats;
|
||||
struct NodeContext;
|
||||
|
||||
enum vote_signal_enum_t : uint8_t;
|
||||
enum vote_signal_enum_t : int;
|
||||
|
||||
namespace interfaces {
|
||||
class Handler;
|
||||
|
Loading…
Reference in New Issue
Block a user