Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 7ba0e884a16bca4c56a544b8aa59bcefb976412e Mon Sep 17 00:00:00 2001
- From: UdjinM6 <UdjinM6@dash.org>
- Date: Mon, 19 Sep 2016 21:19:09 +0300
- Subject: [PATCH] generalize governance vote string/enum conversion/usage for
- (probable) future expansion
- use weighten vote count
- ---
- src/governance-vote.cpp | 304 +++++++++++++++++++++---------------------------
- src/governance-vote.h | 122 ++++++++++---------
- src/governance.cpp | 12 +-
- src/rpcgovernance.cpp | 81 +++++++------
- 4 files changed, 258 insertions(+), 261 deletions(-)
- diff --git a/src/governance-vote.cpp b/src/governance-vote.cpp
- index 7f5d710..5065b69 100644
- --- a/src/governance-vote.cpp
- +++ b/src/governance-vote.cpp
- @@ -2,213 +2,173 @@
- // Distributed under the MIT/X11 software license, see the accompanying
- // file COPYING or http://www.opensource.org/licenses/mit-license.php.
- -#include "core_io.h"
- -#include "main.h"
- -#include "init.h"
- -
- -#include "flat-database.h"
- -#include "governance.h"
- -#include "masternode.h"
- -#include "governance.h"
- #include "darksend.h"
- +#include "governance.h"
- +#include "governance-vote.h"
- #include "masternodeman.h"
- -#include "masternode-sync.h"
- #include "util.h"
- -#include "addrman.h"
- +
- #include <boost/lexical_cast.hpp>
- +#include <boost/algorithm/string.hpp>
- +// Note: keep this list sorted same way as vote_outcome_enum_t
- +const std::string CGovernanceVoting::vote_outcome_strings[] = {
- + "NONE", // the first item in this array must always indicate error
- + // "STRONG_NO",
- + // "WEAK_NO",
- + "NO",
- + "ABSTAIN",
- + "YES",
- + // "WEAK_YES",
- + // "STRONG_YES",
- +};
- +const std::string CGovernanceVoting::vote_signal_strings[] = {
- + "NONE", // the first item in this array must always indicate error
- + "FUNDING",
- + "VALID",
- + "DELETE",
- + "ENDORSED",
- + "NOOP1",
- + "NOOP2",
- + "NOOP3",
- + "NOOP4",
- + "NOOP5",
- + "NOOP6",
- + "NOOP7",
- + "NOOP8",
- + "NOOP9",
- + "NOOP10",
- + "NOOP11",
- + "CUSTOM1",
- + "CUSTOM2",
- + "CUSTOM3",
- + "CUSTOM4",
- + "CUSTOM5",
- + "CUSTOM6",
- + "CUSTOM7",
- + "CUSTOM8",
- + "CUSTOM9",
- + "CUSTOM10",
- + "CUSTOM11",
- + "CUSTOM12",
- + "CUSTOM13",
- + "CUSTOM14",
- + "CUSTOM15",
- + "CUSTOM16",
- + "CUSTOM17",
- + "CUSTOM18",
- + "CUSTOM19",
- + "CUSTOM20",
- +};
- -std::string CGovernanceVoting::ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
- +// Note: only valid outcomes here (no NONE)
- +const std::map<std::string, vote_outcome_enum_t> CGovernanceVoting::CreateVoteOutomeMap()
- {
- - switch(nOutcome)
- - {
- - case VOTE_OUTCOME_NONE:
- - return "NONE"; break;
- - case VOTE_OUTCOME_YES:
- - return "YES"; break;
- - case VOTE_OUTCOME_NO:
- - return "NO"; break;
- - case VOTE_OUTCOME_ABSTAIN:
- - return "ABSTAIN"; break;
- + std::map<std::string, vote_outcome_enum_t> map_temp;
- + // VOTE_OUTCOME_MIN is basically a negative shift from "ABSTAIN" in vote_outcome_strings list
- + // so by using "- VOTE_OUTCOME_MIN" we are going back to "ABSTAIN"
- + // and nOutcome acts as a shift from there ("+ 1" is used to skip "NONE")
- + for (int i = VOTE_OUTCOME_MIN; i <= VOTE_OUTCOME_MAX; ++i) {
- + map_temp[vote_outcome_strings[i - VOTE_OUTCOME_MIN + 1]] = vote_outcome_enum_t(i);
- }
- - return "error";
- + return map_temp;
- +};
- +const std::map<std::string, vote_outcome_enum_t> CGovernanceVoting::mapVoteOutcome_t = CGovernanceVoting::CreateVoteOutomeMap();
- +
- +
- +// Note: only valid explicitly defined signals here (no NONE, NOOP or CUSTOM)
- +const std::map<std::string, vote_signal_enum_t> CGovernanceVoting::CreateDefinedVoteSignalMap()
- +{
- + std::map<std::string, vote_signal_enum_t> map_temp;
- + for (int i = VOTE_SIGNAL_MIN; i <= VOTE_SIGNAL_MAX_DEFINED; ++i) {
- + map_temp[vote_signal_strings[i]] = vote_signal_enum_t(i);
- + }
- + return map_temp;
- +};
- +const std::map<std::string, vote_signal_enum_t> CGovernanceVoting::mapDefinedVoteSignal_t = CGovernanceVoting::CreateDefinedVoteSignalMap();
- +
- +
- +std::string CGovernanceVoting::ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
- +{
- + if(nOutcome < VOTE_OUTCOME_MIN || nOutcome > VOTE_OUTCOME_MAX)
- + return vote_outcome_strings[0];
- +
- + return vote_outcome_strings[nOutcome - VOTE_OUTCOME_MIN + 1];
- }
- std::string CGovernanceVoting::ConvertSignalToString(vote_signal_enum_t nSignal)
- {
- - string strReturn = "NONE";
- - switch(nSignal)
- - {
- - case VOTE_SIGNAL_NONE:
- - strReturn = "NONE";
- - break;
- - case VOTE_SIGNAL_FUNDING:
- - strReturn = "FUNDING";
- - break;
- - case VOTE_SIGNAL_VALID:
- - strReturn = "VALID";
- - break;
- - case VOTE_SIGNAL_DELETE:
- - strReturn = "DELETE";
- - break;
- - case VOTE_SIGNAL_ENDORSED:
- - strReturn = "ENDORSED";
- - break;
- - case VOTE_SIGNAL_NOOP1:
- - strReturn = "NOOP1";
- - break;
- - case VOTE_SIGNAL_NOOP2:
- - strReturn = "NOOP2";
- - break;
- - case VOTE_SIGNAL_NOOP3:
- - strReturn = "NOOP3";
- - break;
- - case VOTE_SIGNAL_NOOP4:
- - strReturn = "NOOP4";
- - break;
- - case VOTE_SIGNAL_NOOP5:
- - strReturn = "NOOP5";
- - break;
- - case VOTE_SIGNAL_NOOP6:
- - strReturn = "NOOP6";
- - break;
- - case VOTE_SIGNAL_NOOP7:
- - strReturn = "NOOP7";
- - break;
- - case VOTE_SIGNAL_NOOP8:
- - strReturn = "NOOP8";
- - break;
- - case VOTE_SIGNAL_NOOP9:
- - strReturn = "NOOP9";
- - break;
- - case VOTE_SIGNAL_NOOP10:
- - strReturn = "NOOP10";
- - break;
- - case VOTE_SIGNAL_NOOP11:
- - strReturn = "NOOP11";
- - break;
- - case VOTE_SIGNAL_CUSTOM1:
- - strReturn = "CUSTOM1";
- - break;
- - case VOTE_SIGNAL_CUSTOM2:
- - strReturn = "CUSTOM2";
- - break;
- - case VOTE_SIGNAL_CUSTOM3:
- - strReturn = "CUSTOM3";
- - break;
- - case VOTE_SIGNAL_CUSTOM4:
- - strReturn = "CUSTOM4";
- - break;
- - case VOTE_SIGNAL_CUSTOM5:
- - strReturn = "CUSTOM5";
- - break;
- - case VOTE_SIGNAL_CUSTOM6:
- - strReturn = "CUSTOM6";
- - break;
- - case VOTE_SIGNAL_CUSTOM7:
- - strReturn = "CUSTOM7";
- - break;
- - case VOTE_SIGNAL_CUSTOM8:
- - strReturn = "CUSTOM8";
- - break;
- - case VOTE_SIGNAL_CUSTOM9:
- - strReturn = "CUSTOM9";
- - break;
- - case VOTE_SIGNAL_CUSTOM10:
- - strReturn = "CUSTOM10";
- - break;
- - case VOTE_SIGNAL_CUSTOM11:
- - strReturn = "CUSTOM11";
- - break;
- - case VOTE_SIGNAL_CUSTOM12:
- - strReturn = "CUSTOM12";
- - break;
- - case VOTE_SIGNAL_CUSTOM13:
- - strReturn = "CUSTOM13";
- - break;
- - case VOTE_SIGNAL_CUSTOM14:
- - strReturn = "CUSTOM14";
- - break;
- - case VOTE_SIGNAL_CUSTOM15:
- - strReturn = "CUSTOM15";
- - break;
- - case VOTE_SIGNAL_CUSTOM16:
- - strReturn = "CUSTOM16";
- - break;
- - case VOTE_SIGNAL_CUSTOM17:
- - strReturn = "CUSTOM17";
- - break;
- - case VOTE_SIGNAL_CUSTOM18:
- - strReturn = "CUSTOM18";
- - break;
- - case VOTE_SIGNAL_CUSTOM19:
- - strReturn = "CUSTOM19";
- - break;
- - case VOTE_SIGNAL_CUSTOM20:
- - strReturn = "CUSTOM20";
- - break;
- - }
- + if(nSignal < VOTE_SIGNAL_MIN || nSignal > VOTE_SIGNAL_MAX)
- + return vote_signal_strings[0];
- - return strReturn;
- + return vote_signal_strings[nSignal];
- }
- -vote_outcome_enum_t CGovernanceVoting::ConvertVoteOutcome(std::string strVoteOutcome)
- +bool CGovernanceVoting::ConvertVoteOutcome(std::string strVoteOutcome, vote_outcome_enum_t &eVoteRet)
- {
- - vote_outcome_enum_t eVote = VOTE_OUTCOME_NONE;
- - if(strVoteOutcome == "yes") {
- - eVote = VOTE_OUTCOME_YES;
- - }
- - else if(strVoteOutcome == "no") {
- - eVote = VOTE_OUTCOME_NO;
- - }
- - else if(strVoteOutcome == "abstain") {
- - eVote = VOTE_OUTCOME_ABSTAIN;
- + boost::algorithm::to_upper(strVoteOutcome);
- + std::map<std::string, vote_outcome_enum_t>::const_iterator it = mapVoteOutcome_t.find(strVoteOutcome);
- + if(it == mapVoteOutcome_t.end()) {
- + eVoteRet = VOTE_OUTCOME_NONE;
- + return false;
- }
- - return eVote;
- +
- + eVoteRet = it->second;
- + return true;
- }
- -vote_signal_enum_t CGovernanceVoting::ConvertVoteSignal(std::string strVoteSignal)
- +bool CGovernanceVoting::ConvertVoteSignal(std::string strVoteSignal, vote_signal_enum_t &eSignalRet)
- {
- - vote_signal_enum_t eSignal = VOTE_SIGNAL_NONE;
- - if(strVoteSignal == "funding") {
- - eSignal = VOTE_SIGNAL_FUNDING;
- - }
- - else if(strVoteSignal == "valid") {
- - eSignal = VOTE_SIGNAL_VALID;
- - }
- - if(strVoteSignal == "delete") {
- - eSignal = VOTE_SIGNAL_DELETE;
- - }
- - if(strVoteSignal == "endorsed") {
- - eSignal = VOTE_SIGNAL_ENDORSED;
- - }
- + eSignalRet = VOTE_SIGNAL_NONE;
- - if(eSignal != VOTE_SIGNAL_NONE) {
- - return eSignal;
- + boost::algorithm::to_upper(strVoteSignal);
- + std::map<std::string, vote_signal_enum_t>::const_iterator it = mapDefinedVoteSignal_t.find(strVoteSignal);
- + if(it != mapDefinedVoteSignal_t.end()) {
- + eSignalRet = it->second;
- + return true;
- }
- // ID FIVE THROUGH CUSTOM_START ARE TO BE USED BY GOVERNANCE ENGINE / TRIGGER SYSTEM
- - // convert custom sentinel outcomes to integer and store
- + // convert custom sentinel signals to integer and store
- try {
- int i = boost::lexical_cast<int>(strVoteSignal);
- if(i < VOTE_SIGNAL_CUSTOM1 || i > VOTE_SIGNAL_CUSTOM20) {
- - eSignal = VOTE_SIGNAL_NONE;
- - }
- - else {
- - eSignal = vote_signal_enum_t(i);
- + return false;
- }
- + eSignalRet = vote_signal_enum_t(i);
- }
- catch(std::exception const & e)
- {
- std::ostringstream ostr;
- ostr << "CGovernanceVote::ConvertVoteSignal: error : " << e.what() << std::endl;
- LogPrintf(ostr.str().c_str());
- + return false;
- }
- - return eSignal;
- + return true;
- +}
- +
- +const std::string CGovernanceVoting::GetValidVoteOutcomeStrings()
- +{
- + std::string strRet = "";
- + for (int i = VOTE_OUTCOME_MIN; i <= VOTE_OUTCOME_MAX; ++i) {
- + strRet += ConvertOutcomeToString(vote_outcome_enum_t(i)) + (i < VOTE_OUTCOME_MAX ? "|" : "");
- + }
- + boost::algorithm::to_lower(strRet);
- + return strRet;
- +}
- +
- +const std::string CGovernanceVoting::GetValidVoteSignalStrings()
- +{
- + std::string strRet = "";
- + for (int i = VOTE_SIGNAL_MIN; i <= VOTE_SIGNAL_MAX_DEFINED; ++i) {
- + strRet += ConvertSignalToString(vote_signal_enum_t(i)) + (i < VOTE_SIGNAL_MAX_DEFINED ? "|" : "");
- + }
- + boost::algorithm::to_lower(strRet);
- + return strRet;
- }
- CGovernanceVote::CGovernanceVote()
- @@ -269,15 +229,15 @@ bool CGovernanceVote::IsValid(bool fSignatureCheck)
- return false;
- }
- - // support up to 50 actions (implemented in sentinel)
- - if(nVoteSignal > 50)
- + // Should be in range of valid vote_signal_enum_t values (actuall actions are implemented in sentinel).
- + if(nVoteSignal < VOTE_SIGNAL_MIN || (nVoteSignal > VOTE_SIGNAL_MAX_DEFINED && nVoteSignal < VOTE_SIGNAL_CUSTOM1) || nVoteSignal > VOTE_SIGNAL_MAX)
- {
- LogPrint("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)
- + // Should be in range of valid vote_outcome_enum_t values. Beyond that reject votes.
- + if(nVoteOutcome < VOTE_OUTCOME_MIN || nVoteOutcome > VOTE_OUTCOME_MAX)
- {
- LogPrint("gobject", "CGovernanceVote::IsValid -- Client attempted to vote on invalid outcome(%d) - %s\n", nVoteSignal, GetHash().ToString());
- return false;
- diff --git a/src/governance-vote.h b/src/governance-vote.h
- index 57aba35..fd2230e 100644
- --- a/src/governance-vote.h
- +++ b/src/governance-vote.h
- @@ -1,71 +1,73 @@
- // Copyright (c) 2014-2016 The Dash Core developers
- -
- // Distributed under the MIT/X11 software license, see the accompanying
- // file COPYING or http://www.opensource.org/licenses/mit-license.php.
- +
- #ifndef GOVERANCE_VOTE_H
- #define GOVERANCE_VOTE_H
- -#include "main.h"
- -#include "sync.h"
- -#include "net.h"
- #include "key.h"
- -#include "util.h"
- -#include "base58.h"
- -#include "masternode.h"
- -#include <boost/lexical_cast.hpp>
- -#include "init.h"
- -
- -using namespace std;
- +#include "primitives/transaction.h"
- class CGovernanceVote;
- // INTENTION OF MASTERNODES REGARDING ITEM
- +// Note: keep votes values in sequence from min to max (no void places)
- enum vote_outcome_enum_t {
- - VOTE_OUTCOME_NONE = 0,
- - VOTE_OUTCOME_YES = 1,
- - VOTE_OUTCOME_NO = 2,
- - VOTE_OUTCOME_ABSTAIN = 3
- + VOTE_OUTCOME_NONE = -9999,
- + // VOTE_OUTCOME_NO_STRONG = -2,
- + // VOTE_OUTCOME_NO_WEAK = -1,
- + VOTE_OUTCOME_NO = -1,
- + VOTE_OUTCOME_ABSTAIN = 0,
- + VOTE_OUTCOME_YES = 1,
- + // VOTE_OUTCOME_YES_WEAK = 1,
- + // VOTE_OUTCOME_YES_STRONG = 2,
- + // VOTE_OUTCOME_MIN = VOTE_OUTCOME_NO_STRONG,
- + // VOTE_OUTCOME_MAX = VOTE_OUTCOME_YES_STRONG,
- + VOTE_OUTCOME_MIN = VOTE_OUTCOME_NO, // adjust this if NO range is extended
- + VOTE_OUTCOME_MAX = VOTE_OUTCOME_YES, // adjust this if YES range is extended
- };
- -
- // 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 = 5, // FOR FURTHER EXPANSION
- - VOTE_SIGNAL_NOOP2 = 6,
- - VOTE_SIGNAL_NOOP3 = 7,
- - VOTE_SIGNAL_NOOP4 = 8,
- - VOTE_SIGNAL_NOOP5 = 9,
- - VOTE_SIGNAL_NOOP6 = 10,
- - VOTE_SIGNAL_NOOP7 = 11,
- - VOTE_SIGNAL_NOOP8 = 12,
- - VOTE_SIGNAL_NOOP9 = 13,
- - VOTE_SIGNAL_NOOP10 = 14,
- - VOTE_SIGNAL_NOOP11 = 15,
- - VOTE_SIGNAL_CUSTOM1 = 16, // SENTINEL CUSTOM ACTIONS
- - VOTE_SIGNAL_CUSTOM2 = 17, // 16-35
- - VOTE_SIGNAL_CUSTOM3 = 18,
- - VOTE_SIGNAL_CUSTOM4 = 19,
- - VOTE_SIGNAL_CUSTOM5 = 20,
- - VOTE_SIGNAL_CUSTOM6 = 21,
- - VOTE_SIGNAL_CUSTOM7 = 22,
- - VOTE_SIGNAL_CUSTOM8 = 23,
- - VOTE_SIGNAL_CUSTOM9 = 24,
- - VOTE_SIGNAL_CUSTOM10 = 25,
- - VOTE_SIGNAL_CUSTOM11 = 26,
- - VOTE_SIGNAL_CUSTOM12 = 27,
- - VOTE_SIGNAL_CUSTOM13 = 28,
- - VOTE_SIGNAL_CUSTOM14 = 29,
- - VOTE_SIGNAL_CUSTOM15 = 30,
- - VOTE_SIGNAL_CUSTOM16 = 31,
- - VOTE_SIGNAL_CUSTOM17 = 32,
- - VOTE_SIGNAL_CUSTOM18 = 33,
- - VOTE_SIGNAL_CUSTOM19 = 34,
- - VOTE_SIGNAL_CUSTOM20 = 35
- + VOTE_SIGNAL_NONE = -9999,
- + 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 = 5, // FOR FURTHER EXPANSION
- + VOTE_SIGNAL_NOOP2 = 6,
- + VOTE_SIGNAL_NOOP3 = 7,
- + VOTE_SIGNAL_NOOP4 = 8,
- + VOTE_SIGNAL_NOOP5 = 9,
- + VOTE_SIGNAL_NOOP6 = 10,
- + VOTE_SIGNAL_NOOP7 = 11,
- + VOTE_SIGNAL_NOOP8 = 12,
- + VOTE_SIGNAL_NOOP9 = 13,
- + VOTE_SIGNAL_NOOP10 = 14,
- + VOTE_SIGNAL_NOOP11 = 15,
- + VOTE_SIGNAL_CUSTOM1 = 16, // SENTINEL CUSTOM ACTIONS
- + VOTE_SIGNAL_CUSTOM2 = 17, // 16-35
- + VOTE_SIGNAL_CUSTOM3 = 18,
- + VOTE_SIGNAL_CUSTOM4 = 19,
- + VOTE_SIGNAL_CUSTOM5 = 20,
- + VOTE_SIGNAL_CUSTOM6 = 21,
- + VOTE_SIGNAL_CUSTOM7 = 22,
- + VOTE_SIGNAL_CUSTOM8 = 23,
- + VOTE_SIGNAL_CUSTOM9 = 24,
- + VOTE_SIGNAL_CUSTOM10 = 25,
- + VOTE_SIGNAL_CUSTOM11 = 26,
- + VOTE_SIGNAL_CUSTOM12 = 27,
- + VOTE_SIGNAL_CUSTOM13 = 28,
- + VOTE_SIGNAL_CUSTOM14 = 29,
- + VOTE_SIGNAL_CUSTOM15 = 30,
- + VOTE_SIGNAL_CUSTOM16 = 31,
- + VOTE_SIGNAL_CUSTOM17 = 32,
- + VOTE_SIGNAL_CUSTOM18 = 33,
- + VOTE_SIGNAL_CUSTOM19 = 34,
- + VOTE_SIGNAL_CUSTOM20 = 35,
- + VOTE_SIGNAL_MIN = VOTE_SIGNAL_FUNDING,
- + VOTE_SIGNAL_MAX_DEFINED = VOTE_SIGNAL_ENDORSED, // adjust this if more signals are defined i.e. next NOOP became smth meaningful
- + VOTE_SIGNAL_MAX = VOTE_SIGNAL_CUSTOM20, // adjust this if more custom signals are added
- };
- /**
- @@ -76,11 +78,23 @@ enum vote_signal_enum_t {
- class CGovernanceVoting
- {
- +private:
- + const static std::string vote_outcome_strings[];
- + const static std::map<std::string, vote_outcome_enum_t> CreateVoteOutomeMap();
- + const static std::map<std::string, vote_outcome_enum_t> mapVoteOutcome_t;
- +
- + const static std::string vote_signal_strings[];
- + const static std::map<std::string, vote_signal_enum_t> CreateDefinedVoteSignalMap();
- + const static std::map<std::string, vote_signal_enum_t> mapDefinedVoteSignal_t;
- +
- public:
- - static vote_outcome_enum_t ConvertVoteOutcome(std::string strVoteOutcome);
- - static vote_signal_enum_t ConvertVoteSignal(std::string strVoteSignal);
- + static bool ConvertVoteOutcome(std::string strVoteOutcome, vote_outcome_enum_t &eVoteRet);
- + static bool ConvertVoteSignal(std::string strVoteSignal, vote_signal_enum_t &eSignalRet);
- static std::string ConvertOutcomeToString(vote_outcome_enum_t nOutcome);
- static std::string ConvertSignalToString(vote_signal_enum_t nSignal);
- +
- + static const std::string GetValidVoteOutcomeStrings();
- + static const std::string GetValidVoteSignalStrings();
- };
- //
- diff --git a/src/governance.cpp b/src/governance.cpp
- index 8aa516e..46ed94c 100644
- --- a/src/governance.cpp
- +++ b/src/governance.cpp
- @@ -1060,12 +1060,20 @@ int CGovernanceObject::GetAbsoluteNoCount(vote_signal_enum_t eVoteSignalIn)
- int CGovernanceObject::GetYesCount(vote_signal_enum_t eVoteSignalIn)
- {
- - return governance.CountMatchingVotes((*this), eVoteSignalIn, VOTE_OUTCOME_YES);
- + int nCount = 0;
- + for (int i = VOTE_OUTCOME_MAX; i > VOTE_OUTCOME_ABSTAIN ; --i) {
- + nCount += governance.CountMatchingVotes((*this), eVoteSignalIn, vote_outcome_enum_t(i)) * i;
- + }
- + return nCount/VOTE_OUTCOME_MAX; // need to keep votes normalized
- }
- int CGovernanceObject::GetNoCount(vote_signal_enum_t eVoteSignalIn)
- {
- - return governance.CountMatchingVotes((*this), eVoteSignalIn, VOTE_OUTCOME_NO);
- + int nCount = 0;
- + for (int i = VOTE_OUTCOME_MIN; i < VOTE_OUTCOME_ABSTAIN ; ++i) {
- + nCount += governance.CountMatchingVotes((*this), eVoteSignalIn, vote_outcome_enum_t(i)) * i;
- + }
- + return nCount/VOTE_OUTCOME_MIN; // need to keep votes normalized
- }
- int CGovernanceObject::GetAbstainCount(vote_signal_enum_t eVoteSignalIn)
- diff --git a/src/rpcgovernance.cpp b/src/rpcgovernance.cpp
- index 1271701..1a674d6 100644
- --- a/src/rpcgovernance.cpp
- +++ b/src/rpcgovernance.cpp
- @@ -218,7 +218,9 @@ UniValue gobject(const UniValue& params, bool fHelp)
- if(strCommand == "vote-conf")
- {
- if(params.size() != 4)
- - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject vote-conf <governance-hash> [funding|valid|delete] [yes|no|abstain]'");
- + throw JSONRPCError(RPC_INVALID_PARAMETER,
- + strprintf("Correct usage is 'gobject vote-conf <governance-hash> [%s] [%s]'",
- + CGovernanceVoting::GetValidVoteSignalStrings(), CGovernanceVoting::GetValidVoteOutcomeStrings()));
- uint256 hash;
- std::string strVote;
- @@ -227,16 +229,18 @@ UniValue gobject(const UniValue& params, bool fHelp)
- std::string strVoteSignal = params[2].get_str();
- std::string strVoteOutcome = params[3].get_str();
- - vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal);
- - if(eVoteSignal == VOTE_SIGNAL_NONE) {
- + vote_signal_enum_t eVoteSignal;
- + if(!CGovernanceVoting::ConvertVoteSignal(strVoteSignal, eVoteSignal)) {
- throw JSONRPCError(RPC_INVALID_PARAMETER,
- - "Invalid vote signal. Please using one of the following: "
- - "(funding|valid|delete|endorsed) OR `custom sentinel code` ");
- + strprintf("Invalid vote signal. Please using one of the following: "
- + "(%s) OR `custom sentinel code`", CGovernanceVoting::GetValidVoteSignalStrings()));
- }
- - vote_outcome_enum_t eVoteOutcome = CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome);
- - if(eVoteOutcome == VOTE_OUTCOME_NONE) {
- - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
- + vote_outcome_enum_t eVoteOutcome;
- + if(!CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome, eVoteOutcome)) {
- + throw JSONRPCError(RPC_INVALID_PARAMETER,
- + strprintf("Invalid vote outcome. Please use one of the following: [%s]",
- + CGovernanceVoting::GetValidVoteOutcomeStrings()));
- }
- int success = 0;
- @@ -297,7 +301,9 @@ UniValue gobject(const UniValue& params, bool fHelp)
- if(strCommand == "vote-many")
- {
- if(params.size() != 4)
- - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject vote-many <governance-hash> [funding|valid|delete] [yes|no|abstain]'");
- + throw JSONRPCError(RPC_INVALID_PARAMETER,
- + strprintf("Correct usage is 'gobject vote-many <governance-hash> [%s] [%s]'",
- + CGovernanceVoting::GetValidVoteSignalStrings(), CGovernanceVoting::GetValidVoteOutcomeStrings()));
- uint256 hash;
- std::string strVote;
- @@ -307,16 +313,18 @@ UniValue gobject(const UniValue& params, bool fHelp)
- std::string strVoteOutcome = params[3].get_str();
- - vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal);
- - if(eVoteSignal == VOTE_SIGNAL_NONE) {
- + vote_signal_enum_t eVoteSignal;
- + if(!CGovernanceVoting::ConvertVoteSignal(strVoteSignal, eVoteSignal)) {
- throw JSONRPCError(RPC_INVALID_PARAMETER,
- - "Invalid vote signal. Please using one of the following: "
- - "(funding|valid|delete|endorsed) OR `custom sentinel code` ");
- + strprintf("Invalid vote signal. Please using one of the following: "
- + "(%s) OR `custom sentinel code`", CGovernanceVoting::GetValidVoteSignalStrings()));
- }
- - vote_outcome_enum_t eVoteOutcome = CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome);
- - if(eVoteOutcome == VOTE_OUTCOME_NONE) {
- - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
- + vote_outcome_enum_t eVoteOutcome;
- + if(!CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome, eVoteOutcome)) {
- + throw JSONRPCError(RPC_INVALID_PARAMETER,
- + strprintf("Invalid vote outcome. Please use one of the following: [%s]",
- + CGovernanceVoting::GetValidVoteOutcomeStrings()));
- }
- int success = 0;
- @@ -403,7 +411,9 @@ UniValue gobject(const UniValue& params, bool fHelp)
- if(strCommand == "vote-alias")
- {
- if(params.size() != 5)
- - throw JSONRPCError(RPC_INVALID_PARAMETER, "Correct usage is 'gobject vote-alias <governance-hash> [funding|valid|delete] [yes|no|abstain] <alias-name>'");
- + throw JSONRPCError(RPC_INVALID_PARAMETER,
- + strprintf("Correct usage is 'gobject vote-alias <governance-hash> [f%s] [%s] <alias-name>'",
- + CGovernanceVoting::GetValidVoteSignalStrings(), CGovernanceVoting::GetValidVoteOutcomeStrings()));
- uint256 hash;
- std::string strVote;
- @@ -417,16 +427,18 @@ UniValue gobject(const UniValue& params, bool fHelp)
- // CONVERT NAMED SIGNAL/ACTION AND CONVERT
- - vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal);
- - if(eVoteSignal == VOTE_SIGNAL_NONE) {
- + vote_signal_enum_t eVoteSignal;
- + if(!CGovernanceVoting::ConvertVoteSignal(strVoteSignal, eVoteSignal)) {
- throw JSONRPCError(RPC_INVALID_PARAMETER,
- - "Invalid vote signal. Please using one of the following: "
- - "(funding|valid|delete|endorsed) OR `custom sentinel code` ");
- + strprintf("Invalid vote signal. Please using one of the following: "
- + "(%s) OR `custom sentinel code`", CGovernanceVoting::GetValidVoteSignalStrings()));
- }
- - vote_outcome_enum_t eVoteOutcome = CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome);
- - if(eVoteOutcome == VOTE_OUTCOME_NONE) {
- - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
- + vote_outcome_enum_t eVoteOutcome;
- + if(!CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome, eVoteOutcome)) {
- + throw JSONRPCError(RPC_INVALID_PARAMETER,
- + strprintf("Invalid vote outcome. Please use one of the following: [%s]",
- + CGovernanceVoting::GetValidVoteOutcomeStrings()));
- }
- // EXECUTE VOTE FOR EACH MASTERNODE, COUNT SUCCESSES VS FAILURES
- @@ -701,8 +713,9 @@ UniValue voteraw(const UniValue& params, bool fHelp)
- {
- if (fHelp || params.size() != 6)
- throw std::runtime_error(
- - "voteraw <masternode-tx-hash> <masternode-tx-index> <governance-hash> <vote-signal> [yes|no|abstain] <time> <vote-sig>\n"
- - "Compile and relay a governance vote with provided external signature instead of signing vote internally\n"
- + strprintf("voteraw <masternode-tx-hash> <masternode-tx-index> <governance-hash> [%s] [%s] <time> <vote-sig>\n"
- + "Compile and relay a governance vote with provided external signature instead of signing vote internally\n",
- + CGovernanceVoting::GetValidVoteSignalStrings(), CGovernanceVoting::GetValidVoteOutcomeStrings())
- );
- uint256 hashMnTx = ParseHashV(params[0], "mn tx hash");
- @@ -713,16 +726,18 @@ UniValue voteraw(const UniValue& params, bool fHelp)
- std::string strVoteSignal = params[3].get_str();
- std::string strVoteOutcome = params[4].get_str();
- - vote_signal_enum_t eVoteSignal = CGovernanceVoting::ConvertVoteSignal(strVoteSignal);
- - if(eVoteSignal == VOTE_SIGNAL_NONE) {
- + vote_signal_enum_t eVoteSignal;
- + if(!CGovernanceVoting::ConvertVoteSignal(strVoteSignal, eVoteSignal)) {
- throw JSONRPCError(RPC_INVALID_PARAMETER,
- - "Invalid vote signal. Please using one of the following: "
- - "(funding|valid|delete|endorsed) OR `custom sentinel code` ");
- + strprintf("Invalid vote signal. Please using one of the following: "
- + "(%s) OR `custom sentinel code`", CGovernanceVoting::GetValidVoteSignalStrings()));
- }
- - vote_outcome_enum_t eVoteOutcome = CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome);
- - if(eVoteOutcome == VOTE_OUTCOME_NONE) {
- - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid vote outcome. Please use one of the following: 'yes', 'no' or 'abstain'");
- + vote_outcome_enum_t eVoteOutcome;
- + if(!CGovernanceVoting::ConvertVoteOutcome(strVoteOutcome, eVoteOutcome)) {
- + throw JSONRPCError(RPC_INVALID_PARAMETER,
- + strprintf("Invalid vote outcome. Please use one of the following: [%s]",
- + CGovernanceVoting::GetValidVoteOutcomeStrings()));
- }
- int64_t nTime = params[5].get_int64();
- --
- 2.9.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement