Skip to content

Commit 90639d1

Browse files
furszyFuzzbawls
authored andcommitted
[GUI] Masternodes start all flow implemented.
Github-Pull: #1221 Rebased-From: 621bb06
1 parent 14f3220 commit 90639d1

File tree

3 files changed

+100
-20
lines changed

3 files changed

+100
-20
lines changed

src/qt/pivx/forms/masternodeswidget.ui

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@
282282
</property>
283283
</widget>
284284
</item>
285+
<item>
286+
<widget class="QPushButton" name="pushButtonStartAll">
287+
<property name="minimumSize">
288+
<size>
289+
<width>125</width>
290+
<height>50</height>
291+
</size>
292+
</property>
293+
<property name="text">
294+
<string>Start All</string>
295+
</property>
296+
</widget>
297+
</item>
285298
</layout>
286299
</item>
287300
</layout>

src/qt/pivx/masternodeswidget.cpp

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#define DECORATION_SIZE 65
3131
#define NUM_ITEMS 3
32+
#define REQUEST_START_ALL 1
3233

3334
class MNHolder : public FurListRow<QWidget*>
3435
{
@@ -63,7 +64,8 @@ class MNHolder : public FurListRow<QWidget*>
6364

6465
MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
6566
PWidget(parent),
66-
ui(new Ui::MasterNodesWidget)
67+
ui(new Ui::MasterNodesWidget),
68+
isLoading(false)
6769
{
6870
ui->setupUi(this);
6971

@@ -97,6 +99,7 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
9799
/* Buttons */
98100
ui->pushButtonSave->setText(tr("Create Masternode Controller"));
99101
setCssBtnPrimary(ui->pushButtonSave);
102+
setCssBtnPrimary(ui->pushButtonStartAll);
100103

101104
/* Options */
102105
ui->btnAbout->setTitleClassAndText("btn-title-grey", "What is a Masternode?");
@@ -117,6 +120,7 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
117120
setCssProperty(ui->labelEmpty, "text-empty");
118121

119122
connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(onCreateMNClicked()));
123+
connect(ui->pushButtonStartAll, SIGNAL(clicked()), this, SLOT(onStartAllClicked()));
120124
connect(ui->listMn, SIGNAL(clicked(QModelIndex)), this, SLOT(onMNClicked(QModelIndex)));
121125
connect(ui->btnAbout, &OptionButton::clicked, [this](){window->openFAQ(9);});
122126
connect(ui->btnAboutController, &OptionButton::clicked, [this](){window->openFAQ(10);});
@@ -144,13 +148,10 @@ void MasterNodesWidget::loadWalletModel(){
144148
}
145149

146150
void MasterNodesWidget::updateListState() {
147-
if (mnModel->rowCount() > 0) {
148-
ui->listMn->setVisible(true);
149-
ui->emptyContainer->setVisible(false);
150-
} else {
151-
ui->listMn->setVisible(false);
152-
ui->emptyContainer->setVisible(true);
153-
}
151+
bool show = mnModel->rowCount() > 0;
152+
ui->listMn->setVisible(show);
153+
ui->emptyContainer->setVisible(!show);
154+
ui->pushButtonStartAll->setVisible(show);
154155
}
155156

156157
void MasterNodesWidget::onMNClicked(const QModelIndex &index){
@@ -197,29 +198,84 @@ void MasterNodesWidget::onEditMNClicked(){
197198
}
198199
}
199200

200-
void MasterNodesWidget::startAlias(QString strAlias){
201+
void MasterNodesWidget::startAlias(QString strAlias) {
201202
QString strStatusHtml;
202203
strStatusHtml += "Alias: " + strAlias + " ";
203204

204205
for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries()) {
205206
if (mne.getAlias() == strAlias.toStdString()) {
206207
std::string strError;
207-
CMasternodeBroadcast mnb;
208-
if (CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb)) {
209-
strStatusHtml += "successfully started.";
210-
mnodeman.UpdateMasternodeList(mnb);
211-
mnb.Relay();
212-
mnModel->updateMNList();
213-
} else {
214-
strStatusHtml += "failed to start.\nError: " + QString::fromStdString(strError);
215-
}
208+
strStatusHtml += (!startMN(mne, strError)) ? ("failed to start.\nError: " + QString::fromStdString(strError)) : "successfully started.";
216209
break;
217210
}
218211
}
219-
inform(strStatusHtml);
212+
// update UI and notify
213+
updateModelAndInform(strStatusHtml);
214+
}
215+
216+
void MasterNodesWidget::updateModelAndInform(QString informText) {
217+
mnModel->updateMNList();
218+
inform(informText);
219+
}
220+
221+
bool MasterNodesWidget::startMN(CMasternodeConfig::CMasternodeEntry mne, std::string& strError) {
222+
CMasternodeBroadcast mnb;
223+
if (!CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb))
224+
return false;
225+
226+
mnodeman.UpdateMasternodeList(mnb);
227+
mnb.Relay();
228+
return true;
229+
}
230+
231+
void MasterNodesWidget::onStartAllClicked() {
232+
if(!verifyWalletUnlocked()) return;
233+
if (isLoading) {
234+
inform(tr("Start all Masternodes is being executed, please wait"));
235+
} else {
236+
isLoading = true;
237+
if (!execute(REQUEST_START_ALL)) {
238+
isLoading = false;
239+
inform(tr("Cannot perform start all Mastenodes"));
240+
}
241+
}
242+
}
243+
244+
bool MasterNodesWidget::startAll(QString& failText) {
245+
int amountOfMnFailed = 0;
246+
int amountOfMnStarted = 0;
247+
for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries()) {
248+
std::string strError;
249+
if (!startMN(mne, strError)) {
250+
amountOfMnFailed++;
251+
} else {
252+
amountOfMnStarted++;
253+
}
254+
}
255+
if (amountOfMnFailed > 0) {
256+
failText = tr("%1 Masternodes failed to start, %2 started").arg(amountOfMnFailed).arg(amountOfMnStarted);
257+
}
258+
return true;
259+
}
260+
261+
void MasterNodesWidget::run(int type) {
262+
if (type == REQUEST_START_ALL) {
263+
QString failText;
264+
QString inform = startAll(failText) ? tr("All Masternodes started!") : failText;
265+
QMetaObject::invokeMethod(this, "updateModelAndInform", Qt::QueuedConnection,
266+
Q_ARG(QString, inform));
267+
}
268+
isLoading = false;
269+
}
270+
271+
void MasterNodesWidget::onError(QString error, int type) {
272+
if (type == REQUEST_START_ALL) {
273+
QMetaObject::invokeMethod(this, "inform", Qt::QueuedConnection,
274+
Q_ARG(QString, "Error starting all Masternodes"));
275+
}
220276
}
221277

222-
void MasterNodesWidget::onInfoMNClicked(){
278+
void MasterNodesWidget::onInfoMNClicked() {
223279
if(!verifyWalletUnlocked()) return;
224280
showHideOp(true);
225281
MnInfoDialog* dialog = new MnInfoDialog(window);

src/qt/pivx/masternodeswidget.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "qt/pivx/mnmodel.h"
1212
#include "qt/pivx/tooltipmenu.h"
1313
#include <QTimer>
14+
#include <atomic>
1415

1516
class PIVXGUI;
1617

@@ -32,17 +33,23 @@ class MasterNodesWidget : public PWidget
3233
~MasterNodesWidget();
3334

3435
void loadWalletModel() override;
36+
37+
void run(int type) override;
38+
void onError(QString error, int type) override;
39+
3540
void showEvent(QShowEvent *event) override;
3641
void hideEvent(QHideEvent *event) override;
3742

3843
private slots:
3944
void onCreateMNClicked();
45+
void onStartAllClicked();
4046
void changeTheme(bool isLightTheme, QString &theme) override;
4147
void onMNClicked(const QModelIndex &index);
4248
void onEditMNClicked();
4349
void onDeleteMNClicked();
4450
void onInfoMNClicked();
4551
void updateListState();
52+
void updateModelAndInform(QString informText);
4653

4754
private:
4855
Ui::MasterNodesWidget *ui;
@@ -52,7 +59,11 @@ private slots:
5259
QModelIndex index;
5360
QTimer *timer = nullptr;
5461

62+
std::atomic<bool> isLoading;
63+
5564
void startAlias(QString strAlias);
65+
bool startAll(QString& failedMN);
66+
bool startMN(CMasternodeConfig::CMasternodeEntry mne, std::string& strError);
5667
};
5768

5869
#endif // MASTERNODESWIDGET_H

0 commit comments

Comments
 (0)