Skip to content

Commit fad8d1a

Browse files
committed
Add and connect function to validate the operator service
1 parent 4818419 commit fad8d1a

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

src/evo/specialtx_validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/* -- Helper static functions -- */
2222

23-
static bool CheckService(const CService& addr, CValidationState& state)
23+
bool CheckService(const CService& addr, CValidationState& state)
2424
{
2525
if (!addr.IsValid()) {
2626
return state.DoS(10, false, REJECT_INVALID, "bad-protx-ipaddr");

src/evo/specialtx_validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class uint256;
2020
/** The maximum allowed size of the extraPayload (for any TxType) */
2121
static const unsigned int MAX_SPECIALTX_EXTRAPAYLOAD = 10000;
2222

23+
/** Operator service validity checks */
24+
bool CheckService(const CService& addr, CValidationState& state);
25+
2326
/** Payload validity checks (including duplicate unique properties against list at pindexPrev)*/
2427
// Note: for +v2, if the tx is not a special tx, this method returns true.
2528
// Note2: This function only performs extra payload related checks, it does NOT checks regular inputs and outputs.

src/interfaces/tiertwo.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "bls/key_io.h"
88
#include "evo/deterministicmns.h"
99
#include "optional.h"
10+
#include "netbase.h"
11+
#include "evo/specialtx_validation.h" // For CheckService
1012
#include "validation.h"
1113
#include "wallet/wallet.h"
1214

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

25+
OperationResult TierTwo::isServiceValid(const std::string& serviceStr)
26+
{
27+
if (serviceStr.empty()) return false;
28+
const auto& params = Params();
29+
CService service;
30+
if (!Lookup(serviceStr, service, params.GetDefaultPort(), false)) {
31+
return {false, strprintf("invalid network address %s", serviceStr)};
32+
}
33+
34+
CValidationState state;
35+
if (!CheckService(service, state)) {
36+
return {false, state.GetRejectReason()};
37+
}
38+
// All good
39+
return {true};
40+
}
41+
2342
Optional<DMNData> TierTwo::getDMNData(const uint256& pro_tx_hash, const CBlockIndex* tip)
2443
{
2544
if (!tip) return nullopt;

src/interfaces/tiertwo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef PIVX_INTERFACES_TIERTWO_H
66
#define PIVX_INTERFACES_TIERTWO_H
77

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

63+
// Verifies the operator service address validity
64+
OperationResult isServiceValid(const std::string& serviceStr);
65+
6266
// Return the DMNs that this wallet "owns".
6367
// future: add filter to return by owner, operator, voter or a combination of them.
6468
std::vector<std::shared_ptr<DMNView>> getKnownDMNs() { return WITH_LOCK(cs_cache, return m_cached_dmns;); };

src/qt/pivx/masternodewizarddialog.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ void MasterNodeWizardDialog::accept()
286286
isOk = createMN();
287287
QDialog::accept();
288288
} else {
289+
if (!validateService()) return; // invalid state informed internally
289290
// Ask if the user want to customize the owner, operator and voter addresses and keys
290291
// if not, the process will generate all the values for them and present them in the summary page.
291292
isWaitingForAsk = true;
@@ -517,6 +518,12 @@ bool MasterNodeWizardDialog::createMN()
517518
return true;
518519
}
519520

521+
bool MasterNodeWizardDialog::validateService()
522+
{
523+
auto opRes = interfaces::g_tiertwo->isServiceValid(ui->lineEditIpAddress->text().toStdString());
524+
return opRes || errorOut(tr(opRes.getError().c_str()));
525+
}
526+
520527
bool MasterNodeWizardDialog::validateOwner()
521528
{
522529
QString ownerAddress(ui->lineEditOwnerAddress->text());

src/qt/pivx/masternodewizarddialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private Q_SLOTS:
117117
void moveToNextPage(int currentPos, int nextPos);
118118
void moveBack(int backPos);
119119

120+
bool validateService();
120121
bool validateVoter();
121122
bool validateOwner();
122123
bool validateOperator();

0 commit comments

Comments
 (0)