Skip to content

Commit 1f0823f

Browse files
furszyFuzzbawls
authored andcommitted
[GUI][Model] Start missing masternodes flow implemented.
Github-Pull: #1221 Rebased-From: 86de445
1 parent 90639d1 commit 1f0823f

File tree

5 files changed

+68
-13
lines changed

5 files changed

+68
-13
lines changed

src/qt/pivx/forms/masternodeswidget.ui

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@
264264
<widget class="QPushButton" name="pushButtonSave">
265265
<property name="minimumSize">
266266
<size>
267-
<width>280</width>
267+
<width>283</width>
268268
<height>50</height>
269269
</size>
270270
</property>
271271
<property name="maximumSize">
272272
<size>
273-
<width>280</width>
273+
<width>283</width>
274274
<height>50</height>
275275
</size>
276276
</property>
@@ -295,6 +295,19 @@
295295
</property>
296296
</widget>
297297
</item>
298+
<item>
299+
<widget class="QPushButton" name="pushButtonStartMissing">
300+
<property name="minimumSize">
301+
<size>
302+
<width>125</width>
303+
<height>50</height>
304+
</size>
305+
</property>
306+
<property name="text">
307+
<string>Start Inactive/s</string>
308+
</property>
309+
</widget>
310+
</item>
298311
</layout>
299312
</item>
300313
</layout>

src/qt/pivx/masternodeswidget.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define DECORATION_SIZE 65
3131
#define NUM_ITEMS 3
3232
#define REQUEST_START_ALL 1
33+
#define REQUEST_START_MISSING 2
3334

3435
class MNHolder : public FurListRow<QWidget*>
3536
{
@@ -100,6 +101,7 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
100101
ui->pushButtonSave->setText(tr("Create Masternode Controller"));
101102
setCssBtnPrimary(ui->pushButtonSave);
102103
setCssBtnPrimary(ui->pushButtonStartAll);
104+
setCssBtnPrimary(ui->pushButtonStartMissing);
103105

104106
/* Options */
105107
ui->btnAbout->setTitleClassAndText("btn-title-grey", "What is a Masternode?");
@@ -120,7 +122,12 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
120122
setCssProperty(ui->labelEmpty, "text-empty");
121123

122124
connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(onCreateMNClicked()));
123-
connect(ui->pushButtonStartAll, SIGNAL(clicked()), this, SLOT(onStartAllClicked()));
125+
connect(ui->pushButtonStartAll, &QPushButton::clicked, [this]() {
126+
onStartAllClicked(REQUEST_START_ALL);
127+
});
128+
connect(ui->pushButtonStartMissing, &QPushButton::clicked, [this]() {
129+
onStartAllClicked(REQUEST_START_MISSING);
130+
});
124131
connect(ui->listMn, SIGNAL(clicked(QModelIndex)), this, SLOT(onMNClicked(QModelIndex)));
125132
connect(ui->btnAbout, &OptionButton::clicked, [this](){window->openFAQ(9);});
126133
connect(ui->btnAboutController, &OptionButton::clicked, [this](){window->openFAQ(10);});
@@ -228,23 +235,31 @@ bool MasterNodesWidget::startMN(CMasternodeConfig::CMasternodeEntry mne, std::st
228235
return true;
229236
}
230237

231-
void MasterNodesWidget::onStartAllClicked() {
238+
void MasterNodesWidget::onStartAllClicked(int type) {
232239
if(!verifyWalletUnlocked()) return;
233240
if (isLoading) {
234-
inform(tr("Start all Masternodes is being executed, please wait"));
241+
inform(tr("Background task is being executed, please wait"));
235242
} else {
236243
isLoading = true;
237-
if (!execute(REQUEST_START_ALL)) {
244+
if (!execute(type)) {
238245
isLoading = false;
239-
inform(tr("Cannot perform start all Mastenodes"));
246+
inform(tr("Cannot perform Mastenodes start"));
240247
}
241248
}
242249
}
243250

244-
bool MasterNodesWidget::startAll(QString& failText) {
251+
bool MasterNodesWidget::startAll(QString& failText, bool onlyMissing) {
245252
int amountOfMnFailed = 0;
246253
int amountOfMnStarted = 0;
247254
for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries()) {
255+
// Check for missing only
256+
QString mnAlias = QString::fromStdString(mne.getAlias());
257+
if (onlyMissing && !mnModel->isMNInactive(mnAlias)) {
258+
if (!mnModel->isMNActive(mnAlias))
259+
amountOfMnFailed++;
260+
continue;
261+
}
262+
248263
std::string strError;
249264
if (!startMN(mne, strError)) {
250265
amountOfMnFailed++;
@@ -254,17 +269,20 @@ bool MasterNodesWidget::startAll(QString& failText) {
254269
}
255270
if (amountOfMnFailed > 0) {
256271
failText = tr("%1 Masternodes failed to start, %2 started").arg(amountOfMnFailed).arg(amountOfMnStarted);
272+
return false;
257273
}
258274
return true;
259275
}
260276

261277
void MasterNodesWidget::run(int type) {
262-
if (type == REQUEST_START_ALL) {
278+
bool isStartMissing = type == REQUEST_START_MISSING;
279+
if (type == REQUEST_START_ALL || isStartMissing) {
263280
QString failText;
264-
QString inform = startAll(failText) ? tr("All Masternodes started!") : failText;
281+
QString inform = startAll(failText, isStartMissing) ? tr("All Masternodes started!") : failText;
265282
QMetaObject::invokeMethod(this, "updateModelAndInform", Qt::QueuedConnection,
266283
Q_ARG(QString, inform));
267284
}
285+
268286
isLoading = false;
269287
}
270288

src/qt/pivx/masternodeswidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MasterNodesWidget : public PWidget
4242

4343
private slots:
4444
void onCreateMNClicked();
45-
void onStartAllClicked();
45+
void onStartAllClicked(int type);
4646
void changeTheme(bool isLightTheme, QString &theme) override;
4747
void onMNClicked(const QModelIndex &index);
4848
void onEditMNClicked();
@@ -62,7 +62,7 @@ private slots:
6262
std::atomic<bool> isLoading;
6363

6464
void startAlias(QString strAlias);
65-
bool startAll(QString& failedMN);
65+
bool startAll(QString& failedMN, bool onlyMissing);
6666
bool startMN(CMasternodeConfig::CMasternodeEntry mne, std::string& strError);
6767
};
6868

src/qt/pivx/mnmodel.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,20 @@ bool MNModel::addMn(CMasternodeConfig::CMasternodeEntry* mne){
149149
nodes.insert(QString::fromStdString(mne->getAlias()), std::make_pair(QString::fromStdString(mne->getIp()), pmn));
150150
endInsertRows();
151151
return true;
152+
}
153+
154+
int MNModel::getMNState(QString mnAlias) {
155+
QMap<QString, std::pair<QString, CMasternode*>>::const_iterator it = nodes.find(mnAlias);
156+
if (it != nodes.end()) return it.value().second->activeState;
157+
throw std::runtime_error(std::string("Masternode alias not found"));
158+
}
159+
160+
bool MNModel::isMNInactive(QString mnAlias) {
161+
int activeState = getMNState(mnAlias);
162+
return activeState == CMasternode::MASTERNODE_MISSING || activeState == CMasternode::MASTERNODE_EXPIRED || activeState == CMasternode::MASTERNODE_REMOVE;
163+
}
164+
165+
bool MNModel::isMNActive(QString mnAlias) {
166+
int activeState = getMNState(mnAlias);
167+
return activeState == CMasternode::MASTERNODE_PRE_ENABLED || activeState == CMasternode::MASTERNODE_ENABLED;
152168
}

src/qt/pivx/mnmodel.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ class MNModel : public QAbstractTableModel
4242
void updateMNList();
4343

4444

45+
// Returns the MN activeState field.
46+
int getMNState(QString alias);
47+
// Checks if the masternode is inactive
48+
bool isMNInactive(QString mnAlias);
49+
// Masternode is active if it's in PRE_ENABLED OR ENABLED state
50+
bool isMNActive(QString mnAlias);
51+
52+
4553
private:
4654
// alias mn node ---> pair <ip, master node>
47-
QMap<QString, std::pair<QString,CMasternode*>> nodes;
55+
QMap<QString, std::pair<QString, CMasternode*>> nodes;
4856
QMap<std::string, bool> collateralTxAccepted;
4957
};
5058

0 commit comments

Comments
 (0)