Skip to content

Commit

Permalink
GUI governance: fix proposal name and URL size limit validation.
Browse files Browse the repository at this point in the history
Github-Pull: #2672
Rebased-From: 948c760
  • Loading branch information
furszy committed Dec 11, 2021
1 parent 594acc6 commit dc10e17
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/budget/budgetproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ static const int64_t BUDGET_VOTE_UPDATE_MIN = 60 * 60;
// Minimum value for a proposal to be considered valid
static const CAmount PROPOSAL_MIN_AMOUNT = 10 * COIN;

// Net ser values
static const size_t PROP_URL_MAX_SIZE = 64;
static const size_t PROP_NAME_MAX_SIZE = 20;

class CBudgetManager;

//
Expand Down Expand Up @@ -113,8 +117,8 @@ class CBudgetProposal
// Serialization for local DB
SERIALIZE_METHODS(CBudgetProposal, obj)
{
READWRITE(LIMITED_STRING(obj.strProposalName, 20));
READWRITE(LIMITED_STRING(obj.strURL, 64));
READWRITE(LIMITED_STRING(obj.strProposalName, PROP_NAME_MAX_SIZE));
READWRITE(LIMITED_STRING(obj.strURL, PROP_URL_MAX_SIZE));
READWRITE(obj.nBlockStart);
READWRITE(obj.nBlockEnd);
READWRITE(obj.nAmount);
Expand Down
11 changes: 8 additions & 3 deletions src/qt/pivx/createproposaldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void CreateProposalDialog::setupPageThree()

void CreateProposalDialog::propNameChanged(const QString& newText)
{
bool isValid = !newText.isEmpty() && IsValidUTF8(newText.toStdString());
bool isValid = !newText.isEmpty() && IsValidUTF8(newText.toStdString()) && govModel->validatePropName(newText).getRes();
setCssEditLine(ui->lineEditPropName, isValid, true);
}

Expand Down Expand Up @@ -182,15 +182,20 @@ bool CreateProposalDialog::validatePageOne()
return false;
}

auto res = govModel->validatePropName(propName);
if (!res) {
inform(QString::fromStdString(res.getError()));
return false;
}

// For now, only accept UTF8 valid strings.
if (!IsValidUTF8(propName.toStdString())) {
setCssEditLine(ui->lineEditPropName, false, true);
inform(tr("Proposal name cannot contain non UTF-8 characters"));
return false;
}


auto res = govModel->validatePropURL(ui->lineEditURL->text());
res = govModel->validatePropURL(ui->lineEditURL->text());
if (!res) inform(QString::fromStdString(res.getError()));
return res.getRes();
}
Expand Down
8 changes: 8 additions & 0 deletions src/qt/pivx/governancemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ std::vector<VoteInfo> GovernanceModel::getLocalMNsVotesForProposal(const Proposa
return localVotes;
}

OperationResult GovernanceModel::validatePropName(const QString& name) const
{
if (name.toUtf8().size() > PROP_NAME_MAX_SIZE) { // limit
return {false, _("Invalid name, maximum size exceeded")};
}
return {true};
}

OperationResult GovernanceModel::validatePropURL(const QString& url) const
{
std::string strError;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/governancemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ QT_END_NAMESPACE

class GovernanceModel : public QObject
{
static const int PROP_URL_MAX_SIZE = 100;

public:
explicit GovernanceModel(ClientModel* _clientModel, MNModel* _mnModel);
Expand Down Expand Up @@ -120,6 +119,7 @@ class GovernanceModel : public QObject
std::vector<VoteInfo> getLocalMNsVotesForProposal(const ProposalInfo& propInfo);
// Check if the URL is valid.
OperationResult validatePropURL(const QString& url) const;
OperationResult validatePropName(const QString& name) const;
OperationResult validatePropAmount(CAmount amount) const;
OperationResult validatePropPaymentCount(int paymentCount) const;
// Whether the tier two network synchronization has finished or not
Expand Down

0 comments on commit dc10e17

Please sign in to comment.