Skip to content

Commit

Permalink
Add and connect function to validate the operator service
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Feb 21, 2022
1 parent 4818419 commit fad8d1a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/evo/specialtx_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/* -- Helper static functions -- */

static bool CheckService(const CService& addr, CValidationState& state)
bool CheckService(const CService& addr, CValidationState& state)
{
if (!addr.IsValid()) {
return state.DoS(10, false, REJECT_INVALID, "bad-protx-ipaddr");
Expand Down
3 changes: 3 additions & 0 deletions src/evo/specialtx_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class uint256;
/** The maximum allowed size of the extraPayload (for any TxType) */
static const unsigned int MAX_SPECIALTX_EXTRAPAYLOAD = 10000;

/** Operator service validity checks */
bool CheckService(const CService& addr, CValidationState& state);

/** Payload validity checks (including duplicate unique properties against list at pindexPrev)*/
// Note: for +v2, if the tx is not a special tx, this method returns true.
// Note2: This function only performs extra payload related checks, it does NOT checks regular inputs and outputs.
Expand Down
19 changes: 19 additions & 0 deletions src/interfaces/tiertwo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "bls/key_io.h"
#include "evo/deterministicmns.h"
#include "optional.h"
#include "netbase.h"
#include "evo/specialtx_validation.h" // For CheckService
#include "validation.h"
#include "wallet/wallet.h"

Expand All @@ -20,6 +22,23 @@ bool TierTwo::isBlsPubKeyValid(const std::string& blsKey)
return opKey && opKey->IsValid();
}

OperationResult TierTwo::isServiceValid(const std::string& serviceStr)
{
if (serviceStr.empty()) return false;
const auto& params = Params();
CService service;
if (!Lookup(serviceStr, service, params.GetDefaultPort(), false)) {
return {false, strprintf("invalid network address %s", serviceStr)};
}

CValidationState state;
if (!CheckService(service, state)) {
return {false, state.GetRejectReason()};
}
// All good
return {true};
}

Optional<DMNData> TierTwo::getDMNData(const uint256& pro_tx_hash, const CBlockIndex* tip)
{
if (!tip) return nullopt;
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/tiertwo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef PIVX_INTERFACES_TIERTWO_H
#define PIVX_INTERFACES_TIERTWO_H

#include "operationresult.h"
#include "sync.h"
#include "uint256.h"
#include "validationinterface.h"
Expand Down Expand Up @@ -59,6 +60,9 @@ class TierTwo : public CValidationInterface {
// Return true if the bls key is valid
bool isBlsPubKeyValid(const std::string& blsKey);

// Verifies the operator service address validity
OperationResult isServiceValid(const std::string& serviceStr);

// Return the DMNs that this wallet "owns".
// future: add filter to return by owner, operator, voter or a combination of them.
std::vector<std::shared_ptr<DMNView>> getKnownDMNs() { return WITH_LOCK(cs_cache, return m_cached_dmns;); };
Expand Down
7 changes: 7 additions & 0 deletions src/qt/pivx/masternodewizarddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ void MasterNodeWizardDialog::accept()
isOk = createMN();
QDialog::accept();
} else {
if (!validateService()) return; // invalid state informed internally
// Ask if the user want to customize the owner, operator and voter addresses and keys
// if not, the process will generate all the values for them and present them in the summary page.
isWaitingForAsk = true;
Expand Down Expand Up @@ -517,6 +518,12 @@ bool MasterNodeWizardDialog::createMN()
return true;
}

bool MasterNodeWizardDialog::validateService()
{
auto opRes = interfaces::g_tiertwo->isServiceValid(ui->lineEditIpAddress->text().toStdString());
return opRes || errorOut(tr(opRes.getError().c_str()));
}

bool MasterNodeWizardDialog::validateOwner()
{
QString ownerAddress(ui->lineEditOwnerAddress->text());
Expand Down
1 change: 1 addition & 0 deletions src/qt/pivx/masternodewizarddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private Q_SLOTS:
void moveToNextPage(int currentPos, int nextPos);
void moveBack(int backPos);

bool validateService();
bool validateVoter();
bool validateOwner();
bool validateOperator();
Expand Down

0 comments on commit fad8d1a

Please sign in to comment.