Modernize Gov Methods (#2326)
* governance.* formatting and copyright bump * manual changes gov.cpp * Modernize ConvertVoteOutcome, ConvertSignalToString and ConvertOutcomeToString * move breaks * add braces instead of inlining * Revert "Modernize ConvertVoteOutcome, ConvertSignalToString and ConvertOutcomeToString" This reverts commit 41bc3d3d863076cd5e6b10ca7706100963cd51b0. * Modernize ConvertVoteOutcome, ConvertSignalToString and ConvertOutcomeToString * fix bugs * make "NONE" lowercase * revert merge error * @InhumanPerfection comments fix * whoops
This commit is contained in:
parent
b3fc236af5
commit
8deb8e90f2
@ -11,59 +11,52 @@
|
|||||||
|
|
||||||
std::string CGovernanceVoting::ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
|
std::string CGovernanceVoting::ConvertOutcomeToString(vote_outcome_enum_t nOutcome)
|
||||||
{
|
{
|
||||||
switch (nOutcome) {
|
static const std::map<vote_outcome_enum_t, std::string> mapOutcomeString = {
|
||||||
case VOTE_OUTCOME_NONE:
|
{ VOTE_OUTCOME_NONE, "none" },
|
||||||
return "NONE";
|
{ VOTE_OUTCOME_YES, "yes" },
|
||||||
break;
|
{ VOTE_OUTCOME_NO, "no" },
|
||||||
case VOTE_OUTCOME_YES:
|
{ VOTE_OUTCOME_ABSTAIN, "abstain" } };
|
||||||
return "YES";
|
|
||||||
break;
|
const auto& it = mapOutcomeString.find(nOutcome);
|
||||||
case VOTE_OUTCOME_NO:
|
if (it == mapOutcomeString.end()) {
|
||||||
return "NO";
|
LogPrintf("CGovernanceVoting::%s -- ERROR: Unknown outcome %d\n", __func__, nOutcome);
|
||||||
break;
|
|
||||||
case VOTE_OUTCOME_ABSTAIN:
|
|
||||||
return "ABSTAIN";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
std::string CGovernanceVoting::ConvertSignalToString(vote_signal_enum_t nSignal)
|
std::string CGovernanceVoting::ConvertSignalToString(vote_signal_enum_t nSignal)
|
||||||
{
|
{
|
||||||
std::string strReturn = "NONE";
|
static const std::map<vote_signal_enum_t, std::string> mapSignalsString = {
|
||||||
switch (nSignal) {
|
{ VOTE_SIGNAL_FUNDING, "funding" },
|
||||||
case VOTE_SIGNAL_NONE:
|
{ VOTE_SIGNAL_VALID, "valid" },
|
||||||
strReturn = "NONE";
|
{ VOTE_SIGNAL_DELETE, "delete" },
|
||||||
break;
|
{ VOTE_SIGNAL_ENDORSED, "endorsed" } };
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return strReturn;
|
const auto& it = mapSignalsString.find(nSignal);
|
||||||
|
if (it == mapSignalsString.end()) {
|
||||||
|
LogPrintf("CGovernanceVoting::%s -- ERROR: Unknown signal %d\n", __func__, nSignal);
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vote_outcome_enum_t CGovernanceVoting::ConvertVoteOutcome(const std::string& strVoteOutcome)
|
vote_outcome_enum_t CGovernanceVoting::ConvertVoteOutcome(const std::string& strVoteOutcome)
|
||||||
{
|
{
|
||||||
vote_outcome_enum_t eVote = VOTE_OUTCOME_NONE;
|
static const std::map<std::string, vote_outcome_enum_t> mapStringOutcome = {
|
||||||
if (strVoteOutcome == "yes") {
|
{ "none", VOTE_OUTCOME_NONE },
|
||||||
eVote = VOTE_OUTCOME_YES;
|
{ "yes", VOTE_OUTCOME_YES },
|
||||||
} else if (strVoteOutcome == "no") {
|
{ "no", VOTE_OUTCOME_NO },
|
||||||
eVote = VOTE_OUTCOME_NO;
|
{ "abstain", VOTE_OUTCOME_ABSTAIN } };
|
||||||
} else if (strVoteOutcome == "abstain") {
|
|
||||||
eVote = VOTE_OUTCOME_ABSTAIN;
|
const auto& it = mapStringOutcome.find(strVoteOutcome);
|
||||||
|
if (it == mapStringOutcome.end()) {
|
||||||
|
LogPrintf("CGovernanceVoting::%s -- ERROR: Unknown outcome %s\n", __func__, strVoteOutcome);
|
||||||
|
return VOTE_OUTCOME_NONE;
|
||||||
}
|
}
|
||||||
return eVote;
|
return it->second;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vote_signal_enum_t CGovernanceVoting::ConvertVoteSignal(const std::string& strVoteSignal)
|
vote_signal_enum_t CGovernanceVoting::ConvertVoteSignal(const std::string& strVoteSignal)
|
||||||
|
Loading…
Reference in New Issue
Block a user