Skip to content

Commit

Permalink
GUI for combined consensus feature (#882)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mxaddict authored Nov 24, 2021
1 parent 536b0cf commit 5fbcc72
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 30 deletions.
43 changes: 27 additions & 16 deletions src/consensus/dao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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])));
Expand Down
18 changes: 10 additions & 8 deletions src/consensus/daoconsensusparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ enum ConsensusParamType
TYPE_NUMBER,
TYPE_PERCENT,
TYPE_NAV,
TYPE_BOOL
TYPE_BOOL,
TYPE_BLOCK,
TYPE_CYCLE
};

enum ConsensusParamsPos
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions src/qt/daoconsultationvote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
19 changes: 17 additions & 2 deletions src/qt/daosupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit 5fbcc72

Please sign in to comment.