From 5fbcc726098d61bbb016d0ef0ca658adba89471e Mon Sep 17 00:00:00 2001 From: Barry Deeney Date: Wed, 24 Nov 2021 14:13:41 +0800 Subject: [PATCH] GUI for combined consensus feature (#882) * Added support for super dao conbimed consensus in UI for support and voting * Added block and cycle types for dao consensus params * Disabled the propose new answers for super/combined consenses props --- src/consensus/dao.cpp | 43 +++++++++++++++++++----------- src/consensus/daoconsensusparams.h | 18 +++++++------ src/qt/daoconsultationvote.cpp | 19 ++++++++++--- src/qt/daosupport.cpp | 19 +++++++++++-- 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/src/consensus/dao.cpp b/src/consensus/dao.cpp index b55f78993..21c90707a 100644 --- a/src/consensus/dao.cpp +++ b/src/consensus/dao.cpp @@ -276,50 +276,61 @@ bool IsEndCycle(const CBlockIndex* pindex, const CStateViewCache& view) return (pindex->nHeight+1) % GetConsensusParameter(Consensus::CONSENSUS_PARAM_VOTING_CYCLE_LENGTH, view) == 0; } -std::string FormatConsensusParameter(Consensus::ConsensusParamsPos pos, std::string string) +std::string FormatConsensusParameter(Consensus::ConsensusParamsPos pos, std::string str) { - std::string ret = string; + std::string ret = str; if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_NAV) - ret = FormatMoney(stoll(string)) + " NAV"; + ret = FormatMoney(stoll(str)) + " NAV"; else if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_PERCENT) { std::ostringstream out; out.precision(2); - out << std::fixed << (float)stoll(string) / 100.0; + out << std::fixed << (float)stoll(str) / 100.0; ret = out.str() + "%"; } - else if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_NUMBER) + else if ( + Consensus::vConsensusParamsType[pos] == Consensus::TYPE_NUMBER || + Consensus::vConsensusParamsType[pos] == Consensus::TYPE_BLOCK || + Consensus::vConsensusParamsType[pos] == Consensus::TYPE_CYCLE) { if (pos == Consensus::CONSENSUS_PARAM_PROPOSAL_MAX_VOTING_CYCLES || pos == Consensus::CONSENSUS_PARAM_PAYMENT_REQUEST_MAX_VOTING_CYCLES) { - ret = std::to_string(stoll(string) + 1); + ret = std::to_string(stoll(str) + 1); } + + if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_BLOCK) + ret = ret + " Blocks"; + else if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_CYCLE) + ret = ret + " Cycles"; } return ret; } -std::string RemoveFormatConsensusParameter(Consensus::ConsensusParamsPos pos, std::string string) +std::string RemoveFormatConsensusParameter(Consensus::ConsensusParamsPos pos, std::string str) { - string.erase(std::remove_if(string.begin(), string.end(), - [](const char& c ) -> bool { return !std::isdigit(c) && c != '.' && c != ',' && c != '-'; } ), string.end()); + str.erase(std::remove_if(str.begin(), str.end(), + [](const char& c ) -> bool { return !std::isdigit(c) && c != '.' && c != ',' && c != '-'; } ), str.end()); - std::string ret = string; + std::string ret = str; try { if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_NAV) - ret = std::to_string((uint64_t)(stof(string) * COIN)); + ret = std::to_string((uint64_t)(stof(str) * COIN)); else if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_PERCENT) { - ret = std::to_string((uint64_t)(stof(string) * 100)); + ret = std::to_string((uint64_t)(stof(str) * 100)); } - else if (Consensus::vConsensusParamsType[pos] == Consensus::TYPE_NUMBER) + else if ( + Consensus::vConsensusParamsType[pos] == Consensus::TYPE_NUMBER || + Consensus::vConsensusParamsType[pos] == Consensus::TYPE_BLOCK || + Consensus::vConsensusParamsType[pos] == Consensus::TYPE_CYCLE) { if (pos == Consensus::CONSENSUS_PARAM_PROPOSAL_MAX_VOTING_CYCLES || pos == Consensus::CONSENSUS_PARAM_PAYMENT_REQUEST_MAX_VOTING_CYCLES) { - ret = std::to_string(stoll(string) - 1); + ret = std::to_string(stoll(str) - 1); } } } @@ -1408,8 +1419,8 @@ bool VoteStep(const CValidationState& state, CBlockIndex *pindexNew, const bool auto answers = answer->GetAnswers(); auto parameters = parent.GetParameters(); - - if (answers.size() == parameters.size()) + + if (answers.size() == parameters.size()) { for (size_t i = 0; i < answers.size(); i++) { mapConsensusToChange.insert(std::make_pair(parameters[i], stoll(answers[i]))); diff --git a/src/consensus/daoconsensusparams.h b/src/consensus/daoconsensusparams.h index 3d6b8e955..a7bbb6dd7 100644 --- a/src/consensus/daoconsensusparams.h +++ b/src/consensus/daoconsensusparams.h @@ -12,7 +12,9 @@ enum ConsensusParamType TYPE_NUMBER, TYPE_PERCENT, TYPE_NAV, - TYPE_BOOL + TYPE_BOOL, + TYPE_BLOCK, + TYPE_CYCLE }; enum ConsensusParamsPos @@ -95,15 +97,15 @@ static std::string sConsensusParamsDesc[Consensus::MAX_CONSENSUS_PARAMS] = { static ConsensusParamType vConsensusParamsType[MAX_CONSENSUS_PARAMS] = { - TYPE_NUMBER, + TYPE_BLOCK, TYPE_PERCENT, TYPE_PERCENT, - TYPE_NUMBER, - TYPE_NUMBER, - TYPE_NUMBER, - TYPE_NUMBER, + TYPE_CYCLE, + TYPE_CYCLE, + TYPE_CYCLE, + TYPE_CYCLE, TYPE_NAV, TYPE_NAV, @@ -112,13 +114,13 @@ static ConsensusParamType vConsensusParamsType[MAX_CONSENSUS_PARAMS] = TYPE_PERCENT, TYPE_PERCENT, TYPE_NAV, - TYPE_NUMBER, + TYPE_CYCLE, TYPE_PERCENT, TYPE_PERCENT, TYPE_PERCENT, TYPE_NAV, - TYPE_NUMBER, + TYPE_CYCLE, TYPE_NUMBER, TYPE_PERCENT, diff --git a/src/qt/daoconsultationvote.cpp b/src/qt/daoconsultationvote.cpp index 8436b3fe5..aaab84549 100644 --- a/src/qt/daoconsultationvote.cpp +++ b/src/qt/daoconsultationvote.cpp @@ -77,12 +77,23 @@ DaoConsultationVote::DaoConsultationVote(QWidget *parent, CConsultation consulta if (c.parent != consultation.hash) continue; - std::string sAnswer = c.sAnswer; + QString s = ""; - if (consultation.IsAboutConsensusParameter()) - sAnswer = FormatConsensusParameter((Consensus::ConsensusParamsPos)consultation.nMin, c.sAnswer); + if (consultation.IsSuper()) + { + for (int i = 0; i < c.vAnswer.size(); ++i) { + if (i != 0) + s = s + "\n"; + s = s + QString::fromStdString(Consensus::sConsensusParamsDesc[consultation.vParameters[i]] + ": "); + s = s + QString::fromStdString(consultation.IsAboutConsensusParameter() ? FormatConsensusParameter((Consensus::ConsensusParamsPos) consultation.vParameters[i], c.vAnswer[i]) : c.vAnswer[i]); + } + } + else + { + s = QString::fromStdString(consultation.IsAboutConsensusParameter() ? FormatConsensusParameter((Consensus::ConsensusParamsPos) consultation.nMin, c.sAnswer) : c.sAnswer); + } - QCheckBox* answer = new QCheckBox(QString::fromStdString(sAnswer)); + QCheckBox* answer = new QCheckBox(s); answers << answer; answer->setProperty("id", QString::fromStdString(c.hash.GetHex())); diff --git a/src/qt/daosupport.cpp b/src/qt/daosupport.cpp index 53e83d441..1daa909fe 100644 --- a/src/qt/daosupport.cpp +++ b/src/qt/daosupport.cpp @@ -41,7 +41,21 @@ DaoSupport::DaoSupport(QWidget *parent, CConsultation consultation) : if (c.parent != consultation.hash) continue; - QString s = QString::fromStdString(consultation.IsAboutConsensusParameter() ? FormatConsensusParameter((Consensus::ConsensusParamsPos)consultation.nMin, c.sAnswer) : c.sAnswer); + QString s = ""; + + if (consultation.IsSuper()) + { + for (int i = 0; i < c.vAnswer.size(); ++i) { + if (i != 0) + s = s + "\n"; + s = s + QString::fromStdString(Consensus::sConsensusParamsDesc[consultation.vParameters[i]] + ": "); + s = s + QString::fromStdString(consultation.IsAboutConsensusParameter() ? FormatConsensusParameter((Consensus::ConsensusParamsPos) consultation.vParameters[i], c.vAnswer[i]) : c.vAnswer[i]); + } + } + else + { + s = QString::fromStdString(consultation.IsAboutConsensusParameter() ? FormatConsensusParameter((Consensus::ConsensusParamsPos) consultation.nMin, c.sAnswer) : c.sAnswer); + } QCheckBox* answer = new QCheckBox(s); @@ -67,7 +81,8 @@ DaoSupport::DaoSupport(QWidget *parent, CConsultation consultation) : connect(proposeBtn, SIGNAL(clicked()), this, SLOT(onPropose())); bottomBoxLayout->addStretch(1); - if (consultation.CanHaveNewAnswers()) + // Check if we can have answers and if it's not a super/combined consensus proposal + if (consultation.CanHaveNewAnswers() && !consultation.IsSuper()) bottomBoxLayout->addWidget(proposeBtn); bottomBoxLayout->addWidget(closeBtn);