forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmasternodewizard.cpp
More file actions
1788 lines (1656 loc) · 75 KB
/
Copy pathmasternodewizard.cpp
File metadata and controls
1788 lines (1656 loc) · 75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2026 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <qt/masternodewizard.h>
#include <chainparams.h>
#include <evo/dmn_types.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
#include <key_io.h>
#include <primitives/transaction.h>
#include <script/standard.h>
#include <util/strencodings.h>
#include <qt/bitcoinunits.h>
#include <qt/guiutil.h>
#include <qt/masternodeoperationrunner.h>
#include <qt/masternodewidgets.h>
#include <qt/optionsmodel.h>
#include <qt/qvalidatedlineedit.h>
#include <qt/sendcoinsdialog.h>
#include <qt/walletmodel.h>
#include <QButtonGroup>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QFormLayout>
#include <QFrame>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLayoutItem>
#include <QLineEdit>
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QProgressBar>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollArea>
#include <QSpinBox>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QtMath>
#include <limits>
#include <set>
#include <string>
#include <variant>
#include <vector>
namespace {
using MasternodeWidgetUtil::CARD_PADDING;
using MasternodeWidgetUtil::GROUP_SPACING;
using MasternodeWidgetUtil::ROW_SPACING;
using MasternodeWidgetUtil::TITLE_SPACING;
using MasternodeWidgetUtil::makeCard;
using MasternodeWidgetUtil::makeOptionCard;
using MasternodeWidgetUtil::makeValue;
//! Point size of a page heading
constexpr double PAGE_TITLE_SIZE{14};
std::set<COutPoint> RegisteredCollaterals(interfaces::Wallet& wallet)
{
const auto registered{wallet.listProTxCoins()};
return {registered.begin(), registered.end()};
}
QLabel* MakeTitle(const QString& text, QWidget* parent)
{
return MasternodeWidgetUtil::makeTitle(text, parent, PAGE_TITLE_SIZE);
}
//! Heading of one block inside a page, in the page's own text size
QLabel* MakeLabel(const QString& text, QWidget* parent)
{
return MasternodeWidgetUtil::makeTitle(text, parent);
}
QLabel* MakeHint(const QString& text, QWidget* parent)
{
return MasternodeWidgetUtil::makeHint(text, parent);
}
//! Vertical layout of a wizard page: the dialog supplies the margins, the page
//! only keeps the rhythm between its groups.
QVBoxLayout* MakePageLayout(QWidget* page)
{
auto* layout{new QVBoxLayout(page)};
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(GROUP_SPACING);
return layout;
}
//! One group inside a page: label, hint and controls sit closer together than
//! the groups themselves do.
QVBoxLayout* MakeBlock(QVBoxLayout* page_layout)
{
auto* block{new QVBoxLayout()};
block->setSpacing(TITLE_SPACING);
page_layout->addLayout(block);
return block;
}
QString FormatAmount(const WalletModel* wallet_model, CAmount amount)
{
const auto unit{wallet_model && wallet_model->getOptionsModel() ?
wallet_model->getOptionsModel()->getDisplayUnit() :
BitcoinUnits::Unit::DASH};
return BitcoinUnits::formatWithUnit(unit, amount, /*plussign=*/false, BitcoinUnits::SeparatorStyle::ALWAYS);
}
} // anonymous namespace
//! Keeps the wallet unlocked on the GUI thread while a typed provider operation is in
//! flight. UnlockContext is neither copyable nor movable, so it is constructed
//! in place from requestUnlock()'s prvalue.
struct RegisterMasternodeWizard::UnlockHolder
{
WalletModel::UnlockContext ctx;
explicit UnlockHolder(WalletModel& wallet_model) :
ctx(wallet_model.requestUnlock()) {}
};
RegisterMasternodeWizard::RegisterMasternodeWizard(interfaces::Node& node, WalletModel* walletModel, QWidget* parent) :
QDialog(parent),
m_node(node),
m_walletModel(walletModel)
{
setWindowTitle(tr("Register Masternode"));
m_pages = new QStackedWidget(this);
// Insertion order must match the Page enum: the enum value doubles as the
// stack index.
m_pages->insertWidget(PageType, createTypePage());
m_pages->insertWidget(PageCollateral, createCollateralPage());
m_pages->insertWidget(PageService, createServicePage());
m_pages->insertWidget(PageKeys, createKeysPage());
m_pages->insertWidget(PagePayout, createPayoutPage());
m_pages->insertWidget(PagePlatform, createPlatformPage());
m_pages->insertWidget(PageFee, createFeePage());
m_pages->insertWidget(PageReview, createReviewPage());
m_pages->insertWidget(PageSecret, createSecretPage());
m_pages->insertWidget(PageSign, createSignPage());
m_pages->insertWidget(PageResult, createResultPage());
m_progress_label = MakeHint(QString(), this);
m_error_label = new QLabel(this);
m_error_label->setWordWrap(true);
m_error_label->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR));
m_error_label->setMinimumHeight(m_error_label->fontMetrics().lineSpacing() * 2);
m_busy_bar = new QProgressBar(this);
m_busy_bar->setRange(0, 0);
m_busy_bar->setTextVisible(false);
m_busy_bar->setMaximumHeight(4);
m_busy_bar->setVisible(false);
m_back_button = new QPushButton(tr("Back"), this);
m_next_button = new QPushButton(tr("Next"), this);
m_next_button->setDefault(true);
m_cancel_button = new QPushButton(tr("Cancel"), this);
auto* buttons{new QHBoxLayout()};
buttons->addWidget(m_back_button);
buttons->addStretch();
buttons->addWidget(m_cancel_button);
buttons->addWidget(m_next_button);
// The dialog owns the page margins; the pages themselves use none so the
// two do not add up.
auto* layout{new QVBoxLayout(this)};
layout->setContentsMargins(24, 12, 24, 12);
layout->setSpacing(GROUP_SPACING);
layout->addWidget(m_progress_label);
layout->addWidget(m_pages, /*stretch=*/1);
layout->addWidget(m_busy_bar);
layout->addWidget(m_error_label);
layout->addLayout(buttons);
connect(m_back_button, &QPushButton::clicked, this, &RegisterMasternodeWizard::onBack);
connect(m_next_button, &QPushButton::clicked, this, &RegisterMasternodeWizard::onNext);
connect(m_cancel_button, &QPushButton::clicked, this, &RegisterMasternodeWizard::reject);
const auto edited = [this] { onPageEdited(); };
for (QLineEdit* const edit :
{static_cast<QLineEdit*>(m_col_address), m_col_txid, m_service_edit, static_cast<QLineEdit*>(m_owner_edit),
static_cast<QLineEdit*>(m_voting_edit), static_cast<QLineEdit*>(m_payout_edit), m_platform_nodeid,
m_platform_p2p, m_platform_https, m_confirm_edit}) {
connect(edit, &QLineEdit::textChanged, this, edited);
}
connect(m_sig_edit, &QPlainTextEdit::textChanged, this, edited);
connect(m_col_utxo_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, edited);
connect(m_col_vout, QOverload<int>::of(&QSpinBox::valueChanged), this, edited);
connect(m_platform_p2p_port, QOverload<int>::of(&QSpinBox::valueChanged), this, edited);
connect(m_platform_https_port, QOverload<int>::of(&QSpinBox::valueChanged), this, edited);
connect(m_fee_picker, QOverload<int>::of(&QComboBox::currentIndexChanged), this, edited);
connect(m_operator_widget, &OperatorKeyWidget::changed, this, [this] {
rebuildOrder();
onPageEdited();
});
if (m_walletModel != nullptr) {
m_runner = std::make_unique<MasternodeOperationRunner>(m_node.evo(), m_walletModel->wallet(), this);
}
rebuildOrder();
enterPage(PageType);
GUIUtil::disableMacFocusRect(this);
GUIUtil::updateFonts();
setMinimumSize(700, 560);
resize(760, 680);
}
RegisterMasternodeWizard::~RegisterMasternodeWizard()
{
// Finish and synchronously deliver any backend result before releasing
// session-owned state. A prepare may have acquired a coin lock.
m_destroying = true;
if (m_runner) m_runner->shutdown();
m_runner.reset();
if (m_prepared_collateral_lock_acquired && m_walletModel != nullptr) {
m_walletModel->wallet().unlockCoin(m_prepared_collateral_outpoint);
}
for (QLineEdit* const edit : {m_secret_edit, m_conf_line_edit, m_confirm_edit}) {
edit->setText(QString(edit->text().size(), QLatin1Char('0')));
edit->clear();
}
}
QWidget* RegisterMasternodeWizard::createTypePage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Masternode type"), page));
m_type_regular = new QRadioButton(
tr("Masternode — %1 collateral").arg(FormatAmount(m_walletModel, GetMnType(MnType::Regular).collat_amount)),
page);
m_type_regular->setChecked(true);
auto regular_card{makeOptionCard(page, m_type_regular,
tr("Provides Core network services and earns regular masternode rewards."))};
regular_card.body->setVisible(false);
layout->addWidget(regular_card.card);
m_type_evo = new QRadioButton(
tr("EvoNode — %1 collateral").arg(FormatAmount(m_walletModel, GetMnType(MnType::Evo).collat_amount)), page);
auto evo_card{makeOptionCard(page, m_type_evo,
tr("Additionally hosts Dash Platform, has four times the voting weight and earns a "
"larger share of rewards. Requires a Platform node ID and extra services."))};
evo_card.body->setVisible(false);
layout->addWidget(evo_card.card);
layout->addStretch();
auto* group{new QButtonGroup(page)};
group->addButton(m_type_regular);
group->addButton(m_type_evo);
connect(m_type_regular, &QRadioButton::toggled, this, [this] {
setWindowTitle(isEvo() ? tr("Register EvoNode") : tr("Register Masternode"));
rebuildOrder();
refreshCollateralCandidates();
updateProgress();
});
return page;
}
QWidget* RegisterMasternodeWizard::createCollateralPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Collateral"), page));
m_col_fund = new QRadioButton(tr("Send collateral from this wallet to a new address"), page);
m_col_fund->setChecked(true);
auto fund_card{makeOptionCard(page, m_col_fund,
tr("A single transaction funds the collateral and registers the masternode."))};
m_col_fund_box = fund_card.body;
{
auto* row{new QHBoxLayout()};
m_col_address = new QValidatedLineEdit(m_col_fund_box);
GUIUtil::setupAddressWidget(m_col_address, this);
row->addWidget(m_col_address, /*stretch=*/1);
auto* fresh{new QPushButton(tr("Use new address"), m_col_fund_box)};
connect(fresh, &QPushButton::clicked, this, [this] {
QString err;
const QString addr{freshAddress(err)};
if (addr.isEmpty()) {
showError(err);
} else {
m_col_address->setText(addr);
}
});
row->addWidget(fresh);
fund_card.body_layout->addLayout(row);
}
layout->addWidget(fund_card.card);
m_col_wallet = new QRadioButton(tr("Use an existing collateral output of this wallet"), page);
auto wallet_card{makeOptionCard(page, m_col_wallet,
tr("An unspent P2PKH output of exactly the collateral amount, confirmed and not "
"used by another masternode."))};
m_col_wallet_box = wallet_card.body;
{
m_col_utxo_combo = new QComboBox(m_col_wallet_box);
m_col_utxo_combo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
m_col_utxo_combo->setMinimumContentsLength(40);
wallet_card.body_layout->addWidget(m_col_utxo_combo);
// Empty state of the card: the exact requirement, filled in with the
// type's collateral amount by refreshCollateralCandidates().
m_col_utxo_none = MakeHint(QString(), m_col_wallet_box);
m_col_utxo_none->setVisible(false);
wallet_card.body_layout->addWidget(m_col_utxo_none);
}
layout->addWidget(wallet_card.card);
m_col_external = new QRadioButton(tr("Reference an external collateral (e.g. hardware wallet)"), page);
auto external_card{makeOptionCard(page, m_col_external,
tr("A confirmed P2PKH output of exactly the collateral amount, held outside "
"this wallet."))};
m_col_external_box = external_card.body;
{
external_card.body_layout->addWidget(
MakeHint(tr("After review you will be asked to sign a message with the collateral key outside this "
"wallet."),
m_col_external_box));
auto* outpoint_form{new QFormLayout()};
outpoint_form->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
m_col_txid = new QLineEdit(m_col_external_box);
m_col_txid->setPlaceholderText(tr("Collateral transaction id (64 hexadecimal characters)"));
m_col_txid->setMaxLength(64);
outpoint_form->addRow(tr("Transaction ID:"), m_col_txid);
m_col_vout = new QSpinBox(m_col_external_box);
m_col_vout->setRange(0, 99999);
m_col_vout->setToolTip(tr("Output index"));
m_col_vout->setMaximumWidth(140);
outpoint_form->addRow(tr("Output index:"), m_col_vout);
external_card.body_layout->addLayout(outpoint_form);
}
layout->addWidget(external_card.card);
layout->addStretch();
auto* group{new QButtonGroup(page)};
group->addButton(m_col_fund);
group->addButton(m_col_wallet);
group->addButton(m_col_external);
const auto update_boxes = [this] {
m_col_fund_box->setVisible(m_col_fund->isChecked());
m_col_wallet_box->setVisible(m_col_wallet->isChecked());
m_col_external_box->setVisible(m_col_external->isChecked());
if (m_col_wallet->isChecked()) refreshCollateralCandidates();
rebuildOrder();
};
connect(m_col_fund, &QRadioButton::toggled, this, update_boxes);
connect(m_col_wallet, &QRadioButton::toggled, this, update_boxes);
connect(m_col_external, &QRadioButton::toggled, this, update_boxes);
update_boxes();
return page;
}
QWidget* RegisterMasternodeWizard::createServicePage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Service addresses"), page));
auto* block{MakeBlock(layout)};
block->addWidget(MakeHint(tr("Public addresses your masternode will serve the Core P2P network on, separated "
"by commas or spaces. Each entry must be unique on the network."),
page));
m_service_edit = new QLineEdit(page);
m_service_edit->setPlaceholderText(QString("1.2.3.4:%1").arg(Params().GetDefaultPort()));
block->addWidget(m_service_edit);
block->addWidget(MakeHint(tr("May be left empty; the masternode then stays inactive until you send a service "
"update with an address."),
page));
layout->addStretch();
return page;
}
QWidget* RegisterMasternodeWizard::createKeysPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Keys"), page));
auto* scroll{new QScrollArea(page)};
scroll->setObjectName("mnWizardScroll");
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->viewport()->setAutoFillBackground(false);
auto* key_container{new QWidget(scroll)};
auto* key_layout{MakePageLayout(key_container)};
key_layout->setContentsMargins(0, 0, ROW_SPACING, 0);
// Owner and voting address rows share the "fill in a fresh wallet address"
// button, differing only in the field they write to.
const auto address_row = [this, key_container](QValidatedLineEdit*& edit) {
auto* row{new QHBoxLayout()};
edit = new QValidatedLineEdit(key_container);
GUIUtil::setupAddressWidget(edit, this);
row->addWidget(edit, /*stretch=*/1);
auto* fresh{new QPushButton(tr("Use new address"), key_container)};
QValidatedLineEdit* const target{edit};
connect(fresh, &QPushButton::clicked, this, [this, target] {
QString err;
const QString addr{freshAddress(err)};
if (addr.isEmpty()) {
showError(err);
} else {
target->setText(addr);
}
});
row->addWidget(fresh);
return row;
};
auto* owner_block{MakeBlock(key_layout)};
owner_block->addWidget(MakeLabel(tr("Owner address"), key_container));
owner_block->addWidget(MakeHint(tr("Controls this masternode (P2PKH): its key signs registrar updates. Use "
"a new address to keep that key in this wallet, or enter an address "
"controlled by the owner."),
key_container));
owner_block->addLayout(address_row(m_owner_edit));
auto* voting_block{MakeBlock(key_layout)};
voting_block->addWidget(MakeLabel(tr("Voting address"), key_container));
voting_block->addWidget(MakeHint(tr("May be delegated (P2PKH). Leave empty to vote with the owner key; use "
"a new address to keep a separate voting key in this wallet."),
key_container));
voting_block->addLayout(address_row(m_voting_edit));
m_voting_edit->setPlaceholderText(tr("Leave empty to use the owner address"));
auto* operator_block{MakeBlock(key_layout)};
operator_block->addWidget(MakeLabel(tr("Operator key"), key_container));
operator_block->addWidget(MakeHint(tr("The operator runs the masternode server (BLS); only the public key is "
"registered on-chain."),
key_container));
m_operator_widget = new OperatorKeyWidget(key_container);
operator_block->addWidget(MakeHint(tr("A generated secret key is shown and must be confirmed before registering. "
"It is not stored in this wallet."),
key_container));
operator_block->addWidget(m_operator_widget);
key_layout->addStretch();
scroll->setWidget(key_container);
layout->addWidget(scroll, /*stretch=*/1);
return page;
}
QWidget* RegisterMasternodeWizard::createPayoutPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Payout"), page));
auto* payout_block{MakeBlock(layout)};
payout_block->addWidget(MakeLabel(tr("Payout address"), page));
payout_block->addWidget(MakeHint(tr("Receives this masternode's block rewards (P2PKH or P2SH)."), page));
auto* payout_row{new QHBoxLayout()};
m_payout_edit = new QValidatedLineEdit(page);
GUIUtil::setupAddressWidget(m_payout_edit, this);
payout_row->addWidget(m_payout_edit, /*stretch=*/1);
auto* payout_fresh{new QPushButton(tr("Use new address"), page)};
connect(payout_fresh, &QPushButton::clicked, this, [this] {
QString err;
const QString addr{freshAddress(err)};
if (addr.isEmpty()) {
showError(err);
} else {
m_payout_edit->setText(addr);
}
});
payout_row->addWidget(payout_fresh);
payout_block->addLayout(payout_row);
auto* reward_block{MakeBlock(layout)};
reward_block->addWidget(MakeLabel(tr("Operator reward"), page));
reward_block->addWidget(MakeHint(tr("Share of the reward promised to the operator."), page));
m_operator_reward = new QDoubleSpinBox(page);
m_operator_reward->setRange(0.0, 100.0);
m_operator_reward->setDecimals(2);
m_operator_reward->setSuffix(QString::fromUtf8(" %"));
m_operator_reward->setMinimumWidth(120);
m_operator_reward->setMaximumWidth(160);
auto* reward_row{new QHBoxLayout()};
reward_row->addWidget(m_operator_reward);
reward_row->addStretch();
reward_block->addLayout(reward_row);
m_reward_warning = MakeHint(tr("The operator will permanently receive this share of all rewards of this "
"masternode. Leave it at 0 unless you have an agreement with your operator."),
page);
m_reward_warning->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_WARNING));
m_reward_warning->setVisible(false);
reward_block->addWidget(m_reward_warning);
connect(m_operator_reward, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
[this](double value) { m_reward_warning->setVisible(value > 0.0); });
layout->addStretch();
return page;
}
QWidget* RegisterMasternodeWizard::createPlatformPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Platform services"), page));
auto* nodeid_block{MakeBlock(layout)};
nodeid_block->addWidget(MakeLabel(tr("Platform node ID"), page));
nodeid_block->addWidget(MakeHint(tr("Derived from the Platform P2P public key (40 hexadecimal characters)."),
page));
m_platform_nodeid = new QLineEdit(page);
m_platform_nodeid->setMaxLength(40);
m_platform_nodeid->setPlaceholderText(QString("f2dbd9b0a1f541a7c44d34a58674d0262f5feca5"));
nodeid_block->addWidget(m_platform_nodeid);
// Only one of the two cards is ever shown: which one depends on whether v24
// is active, and with it on the ProTx version the node will build.
{
auto card{makeOptionCard(page, MakeLabel(tr("Platform addresses"), page),
tr("ADDR:PORT entries, separated by commas or spaces."))};
m_platform_addr_box = card.card;
card.body_layout->addWidget(MakeHint(tr("Platform P2P"), m_platform_addr_box));
m_platform_p2p = new QLineEdit(card.body);
m_platform_p2p->setPlaceholderText(QString("1.2.3.4:26656"));
card.body_layout->addWidget(m_platform_p2p);
card.body_layout->addWidget(MakeHint(tr("Platform HTTPS API"), m_platform_addr_box));
m_platform_https = new QLineEdit(card.body);
m_platform_https->setPlaceholderText(QString("platform.example.org:443"));
card.body_layout->addWidget(m_platform_https);
layout->addWidget(m_platform_addr_box);
}
{
auto card{makeOptionCard(page, MakeLabel(tr("Platform ports"), page),
tr("Before v24 activation only the Platform ports can be registered; they apply "
"to the first service address."))};
m_platform_port_box = card.card;
auto* row{new QHBoxLayout()};
row->addWidget(new QLabel(tr("Platform P2P port:"), card.body));
m_platform_p2p_port = new QSpinBox(card.body);
m_platform_p2p_port->setRange(1, 65535);
m_platform_p2p_port->setValue(Params().GetDefaultPlatformP2PPort());
row->addWidget(m_platform_p2p_port);
row->addSpacing(GROUP_SPACING);
row->addWidget(new QLabel(tr("Platform HTTPS port:"), card.body));
m_platform_https_port = new QSpinBox(card.body);
m_platform_https_port->setRange(1, 65535);
m_platform_https_port->setValue(Params().GetDefaultPlatformHTTPPort());
row->addWidget(m_platform_https_port);
row->addStretch();
card.body_layout->addLayout(row);
layout->addWidget(m_platform_port_box);
}
layout->addStretch();
return page;
}
QWidget* RegisterMasternodeWizard::createFeePage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Fee source"), page));
auto* block{MakeBlock(layout)};
m_fee_explain = MakeHint(QString(), page);
block->addWidget(m_fee_explain);
m_fee_picker = new FeeSourcePicker(page);
m_fee_picker->setWalletModel(m_walletModel);
block->addWidget(m_fee_picker);
layout->addStretch();
return page;
}
QWidget* RegisterMasternodeWizard::createReviewPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Review"), page));
// An EvoNode summary is a third longer than a masternode one, so the review
// scrolls instead of squeezing its cards
auto* scroll{new QScrollArea(page)};
scroll->setObjectName("mnWizardScroll");
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->viewport()->setAutoFillBackground(false);
m_review_container = new QWidget(scroll);
m_review_layout = new QVBoxLayout(m_review_container);
m_review_layout->setContentsMargins(0, 0, ROW_SPACING, 0);
m_review_layout->setSpacing(GROUP_SPACING);
m_review_layout->addStretch();
scroll->setWidget(m_review_container);
layout->addWidget(scroll, /*stretch=*/1);
return page;
}
QWidget* RegisterMasternodeWizard::createSignPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Prove collateral ownership"), page));
auto* message_block{MakeBlock(layout)};
m_sign_address_label = MakeHint(QString(), page);
message_block->addWidget(m_sign_address_label);
message_block->addWidget(MakeHint(tr("Sign the following message with the collateral key (for example with "
"your hardware wallet's sign-message feature), then paste the base64 "
"signature below."),
page));
m_sign_message = new QPlainTextEdit(page);
m_sign_message->setReadOnly(true);
m_sign_message->setMaximumHeight(90);
message_block->addWidget(m_sign_message);
auto* copy_row{new QHBoxLayout()};
auto* copy_button{new QPushButton(tr("Copy message"), page)};
connect(copy_button, &QPushButton::clicked, this,
[this] { GUIUtil::setClipboard(m_sign_message->toPlainText()); });
copy_row->addWidget(copy_button);
copy_row->addStretch();
message_block->addLayout(copy_row);
auto* signature_block{MakeBlock(layout)};
signature_block->addWidget(MakeLabel(tr("Signature"), page));
m_sig_edit = new QPlainTextEdit(page);
m_sig_edit->setPlaceholderText(tr("Paste the base64 signature here"));
m_sig_edit->setMaximumHeight(90);
signature_block->addWidget(m_sig_edit);
layout->addStretch();
return page;
}
QWidget* RegisterMasternodeWizard::createSecretPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Save operator key"), page));
layout->addWidget(MakeHint(tr("Save this generated key before registering. It is kept nowhere else and cannot "
"be recovered from the wallet."),
page));
auto* scroll{new QScrollArea(page)};
scroll->setObjectName("mnWizardScroll");
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->viewport()->setAutoFillBackground(false);
auto* secret_container{new QWidget(scroll)};
auto* secret_layout{new QVBoxLayout(secret_container)};
secret_layout->setContentsMargins(0, 0, ROW_SPACING, 0);
secret_layout->setSpacing(GROUP_SPACING);
auto* secret_box{makeCard(secret_container)};
auto* box{new QVBoxLayout(secret_box)};
box->setContentsMargins(CARD_PADDING, CARD_PADDING, CARD_PADDING, CARD_PADDING);
box->setSpacing(TITLE_SPACING);
box->addWidget(MakeLabel(tr("Operator secret key"), secret_box));
m_secret_note = MakeHint(tr("Save it now — registration cannot start until you confirm it."), secret_box);
m_secret_note->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_WARNING));
box->addWidget(m_secret_note);
m_secret_edit = new QLineEdit(secret_box);
m_secret_edit->setReadOnly(true);
m_secret_edit->setFont(GUIUtil::fixedPitchFont());
box->addWidget(m_secret_edit);
box->addWidget(MakeHint(tr("Add this line to dash.conf on your masternode server:"), secret_box));
auto* conf_row{new QHBoxLayout()};
m_conf_line_edit = new QLineEdit(secret_box);
m_conf_line_edit->setReadOnly(true);
m_conf_line_edit->setFont(GUIUtil::fixedPitchFont());
conf_row->addWidget(m_conf_line_edit, /*stretch=*/1);
auto* copy_conf{new QPushButton(tr("Copy"), secret_box)};
connect(copy_conf, &QPushButton::clicked, this, [this] { GUIUtil::setClipboard(m_conf_line_edit->text()); });
conf_row->addWidget(copy_conf);
box->addLayout(conf_row);
auto* confirm_box{new QWidget(secret_box)};
auto* confirm_layout{new QVBoxLayout(confirm_box)};
confirm_layout->setContentsMargins(0, 0, 0, 0);
confirm_layout->setSpacing(TITLE_SPACING);
confirm_layout->addWidget(MakeHint(tr("Type the last 4 characters of the secret key to confirm you saved it "
"before registering:"),
confirm_box));
m_confirm_edit = new QLineEdit(confirm_box);
m_confirm_edit->setMaxLength(4);
m_confirm_edit->setMaximumWidth(120);
confirm_layout->addWidget(m_confirm_edit);
box->addWidget(confirm_box);
secret_layout->addWidget(secret_box);
secret_layout->addStretch();
scroll->setWidget(secret_container);
layout->addWidget(scroll, /*stretch=*/1);
return page;
}
QWidget* RegisterMasternodeWizard::createResultPage()
{
auto* page{new QWidget(this)};
auto* layout{MakePageLayout(page)};
layout->addWidget(MakeTitle(tr("Masternode registered"), page));
auto* scroll{new QScrollArea(page)};
scroll->setObjectName("mnWizardScroll");
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scroll->viewport()->setAutoFillBackground(false);
auto* result_container{new QWidget(scroll)};
auto* result_layout{new QVBoxLayout(result_container)};
result_layout->setContentsMargins(0, 0, ROW_SPACING, 0);
result_layout->setSpacing(GROUP_SPACING);
// What happened
{
auto* card{makeCard(result_container)};
auto* box{new QVBoxLayout(card)};
box->setContentsMargins(CARD_PADDING, CARD_PADDING, CARD_PADDING, CARD_PADDING);
box->setSpacing(TITLE_SPACING);
m_result_label = MakeHint(QString(), card);
box->addWidget(m_result_label);
box->addWidget(MakeLabel(tr("Provider transaction hash"), card));
m_result_hash = makeValue(QString(), card, /*monospace=*/true);
box->addWidget(m_result_hash);
m_result_tx_note = MakeHint(QString(), card);
box->addWidget(m_result_tx_note);
result_layout->addWidget(card);
}
// What to do next
{
auto* card{makeCard(result_container)};
auto* box{new QVBoxLayout(card)};
box->setContentsMargins(CARD_PADDING, CARD_PADDING, CARD_PADDING, CARD_PADDING);
box->setSpacing(TITLE_SPACING);
box->addWidget(MakeLabel(tr("Next steps"), card));
m_next_steps = new QLabel(card);
m_next_steps->setWordWrap(true);
m_next_steps->setTextInteractionFlags(Qt::TextSelectableByMouse);
box->addWidget(m_next_steps);
result_layout->addWidget(card);
}
result_layout->addStretch();
scroll->setWidget(result_container);
layout->addWidget(scroll, /*stretch=*/1);
return page;
}
bool RegisterMasternodeWizard::isEvo() const
{
return m_type_evo->isChecked();
}
bool RegisterMasternodeWizard::usesExtendedAddresses() const
{
return m_node.evo().getProviderTxCapabilities().extended_addresses;
}
bool RegisterMasternodeWizard::isExternalCollateral() const
{
return m_col_external->isChecked();
}
bool RegisterMasternodeWizard::isFundCollateral() const
{
return m_col_fund->isChecked();
}
std::optional<CTxDestination> RegisterMasternodeWizard::knownCollateralDestination() const
{
if (isFundCollateral()) {
const CTxDestination destination{DecodeDestination(collateralAddress().toStdString())};
if (IsValidDestination(destination)) return destination;
return std::nullopt;
}
if (!m_col_wallet->isChecked() || m_col_utxo_combo->currentIndex() < 0) {
return std::nullopt;
}
const CTxDestination destination{DecodeDestination(
m_col_utxo_combo->itemData(m_col_utxo_combo->currentIndex(), COLLATERAL_ADDRESS_ROLE).toString().toStdString())};
return IsValidDestination(destination) ? std::optional{destination} : std::nullopt;
}
QString RegisterMasternodeWizard::collateralAddress() const
{
return isFundCollateral() ? m_col_address->text().trimmed() : QString();
}
QString RegisterMasternodeWizard::ownerAddress() const
{
return m_owner_edit->text().trimmed();
}
QString RegisterMasternodeWizard::votingAddress() const
{
return m_voting_edit->text().trimmed();
}
QString RegisterMasternodeWizard::freshAddress(QString& err) const
{
err.clear();
if (m_walletModel == nullptr) {
err = tr("No wallet is available.");
return {};
}
auto dest{m_walletModel->wallet().getNewDestination(/*label=*/"")};
if (!dest) {
err = tr("Could not generate a new address: %1")
.arg(QString::fromStdString(util::ErrorString(dest).translated));
return {};
}
return QString::fromStdString(EncodeDestination(*dest));
}
CAmount RegisterMasternodeWizard::collateralAmount() const
{
return GetMnType(isEvo() ? MnType::Evo : MnType::Regular).collat_amount;
}
bool RegisterMasternodeWizard::secretGateRequired() const
{
return m_operator_widget->hasGeneratedSecret();
}
bool RegisterMasternodeWizard::secretConfirmed() const
{
return m_confirm_edit->text().trimmed().compare(m_operator_widget->secretHex().right(4),
Qt::CaseInsensitive) == 0;
}
void RegisterMasternodeWizard::rebuildOrder()
{
const std::optional<Page> current{m_order.isEmpty() ? std::nullopt : std::optional<Page>{currentPage()}};
m_order = {PageType, PageCollateral, PageService, PageKeys, PagePayout};
if (isEvo()) m_order << PagePlatform;
m_order << PageFee << PageReview;
if (m_operator_widget != nullptr && secretGateRequired()) m_order << PageSecret;
if (isExternalCollateral()) m_order << PageSign;
m_order << PageResult;
if (current && m_order.contains(*current)) {
m_pos = m_order.indexOf(*current);
} else if (m_pos >= m_order.size()) {
m_pos = m_order.size() - 1;
}
updateProgress();
}
RegisterMasternodeWizard::Page RegisterMasternodeWizard::currentPage() const
{
return m_order.isEmpty() ? PageType : m_order.at(m_pos);
}
QString RegisterMasternodeWizard::pageTitle(Page page) const
{
switch (page) {
case PageType:
return tr("Masternode type");
case PageCollateral:
return tr("Collateral");
case PageService:
return tr("Service addresses");
case PageKeys:
return tr("Keys");
case PagePayout:
return tr("Payout");
case PagePlatform:
return tr("Platform services");
case PageFee:
return tr("Fee source");
case PageReview:
return tr("Review");
case PageSecret:
return tr("Save operator key");
case PageSign:
return tr("Prove collateral ownership");
case PageResult:
return tr("Complete");
}
return {};
}
void RegisterMasternodeWizard::updateProgress()
{
if (m_progress_label == nullptr || m_order.isEmpty()) return;
if (currentPage() == PageResult) {
m_progress_label->setText(tr("Complete"));
return;
}
const int total{m_order.size() - 1};
m_progress_label->setText(tr("Step %1 of %2 · %3").arg(m_pos + 1).arg(total).arg(pageTitle(currentPage())));
}
void RegisterMasternodeWizard::goToPage(Page page)
{
const int pos{m_order.indexOf(page)};
if (pos < 0) return;
m_pos = pos;
enterPage(page);
}
void RegisterMasternodeWizard::enterPage(Page page)
{
m_pages->setCurrentIndex(page);
m_validation_page.reset();
showError(QString());
if (page != PageReview) m_unlock.reset();
switch (page) {
case PageCollateral:
if (m_col_address->text().isEmpty() && m_walletModel != nullptr) {
QString err;
const QString addr{freshAddress(err)};
if (!addr.isEmpty()) m_col_address->setText(addr);
}
refreshCollateralCandidates();
break;
case PageKeys: {
if (m_owner_edit->text().isEmpty() && m_walletModel != nullptr) {
QString err;
const QString addr{freshAddress(err)};
if (!addr.isEmpty()) m_owner_edit->setText(addr);
}
break;
}
case PagePayout:
if (m_payout_edit->text().isEmpty() && m_walletModel != nullptr) {
QString err;
const QString addr{freshAddress(err)};
if (!addr.isEmpty()) m_payout_edit->setText(addr);
}
break;
case PagePlatform: {
const auto capabilities{m_node.evo().getProviderTxCapabilities()};
const bool v3{capabilities.extended_addresses};
m_platform_provider_version = capabilities.version;
m_platform_extended_addresses = v3;
m_platform_addr_box->setVisible(v3);
m_platform_port_box->setVisible(!v3);
break;
}
case PageFee: {
// The exact fee depends on selected coins and current wallet fee
// settings. Do not reject a viable source using a fixed estimate; the
// typed funding operation remains the authority.
const CAmount required{isFundCollateral() ? collateralAmount() : 0};
std::optional<COutPoint> excluded_outpoint;
if (m_col_wallet->isChecked() && m_col_utxo_combo->currentIndex() >= 0) {
uint256 hash;
hash.SetHex(m_col_utxo_combo->currentData().toString().toStdString());
excluded_outpoint.emplace(
hash, static_cast<uint32_t>(m_col_utxo_combo->itemData(m_col_utxo_combo->currentIndex(), VOUT_ROLE).toInt()));
}
m_fee_picker->setExcludedOutpoint(std::move(excluded_outpoint));
m_fee_picker->setMinimumBalance(required);
m_fee_picker->refresh();
if (isFundCollateral()) {
m_fee_explain->setText(
tr("The selected address funds the %1 collateral plus the transaction fee. The exact fee is "
"calculated from your wallet settings when you register, and change returns to this address.")
.arg(FormatAmount(m_walletModel, collateralAmount())));
} else {
m_fee_explain->setText(tr("The selected address pays the transaction fee."));
}
break;
}
case PageReview:
populateReview();
break;
case PageSecret:
populateSecret();
break;
default:
break;
}
updateProgress();
updateButtons();
}
bool RegisterMasternodeWizard::validatePage(Page page, QString& err)
{
err.clear();
switch (page) {
case PageCollateral:
if (isFundCollateral()) {
if (!MasternodeWidgetUtil::isP2PKHorP2SHAddress(collateralAddress())) {
err = tr("Enter a valid collateral address (P2PKH or P2SH).");
}
} else if (m_col_wallet->isChecked()) {
if (m_col_utxo_combo->currentIndex() < 0) {
err = tr("This wallet has no unspent output of exactly %1. Fund the collateral from the wallet "
"instead.")
.arg(FormatAmount(m_walletModel, collateralAmount()));
}
} else {
const QString txid{m_col_txid->text().trimmed()};
uint256 hash;
hash.SetHex(txid.toStdString());
if (txid.length() != 64 || !IsHex(txid.toStdString()) || hash.IsNull()) {
err = tr("Enter the collateral transaction id as 64 hexadecimal characters.");
}
}
break;
case PageService: {
const QStringList list{MasternodeWidgetUtil::tokenizeEndpointList(m_service_edit->text())};
if (list.isEmpty() && isEvo() && !usesExtendedAddresses()) {