diff --git a/src/evo/specialtx_validation.cpp b/src/evo/specialtx_validation.cpp index c2d6e2b0297b2e..ab86745f01a505 100644 --- a/src/evo/specialtx_validation.cpp +++ b/src/evo/specialtx_validation.cpp @@ -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"); diff --git a/src/evo/specialtx_validation.h b/src/evo/specialtx_validation.h index eb49d2b0676e8f..3a3c89aa8de644 100644 --- a/src/evo/specialtx_validation.h +++ b/src/evo/specialtx_validation.h @@ -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. diff --git a/src/interfaces/tiertwo.cpp b/src/interfaces/tiertwo.cpp index d3d2c93a5805c3..21d8f36fe4428f 100644 --- a/src/interfaces/tiertwo.cpp +++ b/src/interfaces/tiertwo.cpp @@ -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" @@ -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 TierTwo::getDMNData(const uint256& pro_tx_hash, const CBlockIndex* tip) { if (!tip) return nullopt; diff --git a/src/interfaces/tiertwo.h b/src/interfaces/tiertwo.h index 934e5dbc0c8ab4..0b0a7f81f77c9f 100644 --- a/src/interfaces/tiertwo.h +++ b/src/interfaces/tiertwo.h @@ -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" @@ -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> getKnownDMNs() { return WITH_LOCK(cs_cache, return m_cached_dmns;); }; diff --git a/src/qt/pivx/masternodewizarddialog.cpp b/src/qt/pivx/masternodewizarddialog.cpp index fc5f4426ae3310..06b608e4ae2bb4 100644 --- a/src/qt/pivx/masternodewizarddialog.cpp +++ b/src/qt/pivx/masternodewizarddialog.cpp @@ -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; @@ -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()); diff --git a/src/qt/pivx/masternodewizarddialog.h b/src/qt/pivx/masternodewizarddialog.h index 8a8a942c6e1d1d..0429f047a1d2f8 100644 --- a/src/qt/pivx/masternodewizarddialog.h +++ b/src/qt/pivx/masternodewizarddialog.h @@ -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();