forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathmasternodedialogs.cpp
More file actions
721 lines (635 loc) · 28.7 KB
/
Copy pathmasternodedialogs.cpp
File metadata and controls
721 lines (635 loc) · 28.7 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
// 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/masternodedialogs.h>
#include <bls/bls.h>
#include <chainparams.h>
#include <evo/providertx.h>
#include <evo/types.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
#include <key_io.h>
#include <script/standard.h>
#include <support/cleanse.h>
#include <uint256.h>
#include <util/strencodings.h>
#include <qt/guiutil.h>
#include <qt/masternodemodel.h>
#include <qt/masternodewidgets.h>
#include <qt/qvalidatedlineedit.h>
#include <qt/walletmodel.h>
#include <QApplication>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QSizePolicy>
#include <QSpinBox>
#include <QStringList>
#include <QVBoxLayout>
#include <limits>
#include <optional>
#include <string>
#include <utility>
namespace {
bool IsHexString(const QString& text, int length) { return text.size() == length && IsHex(text.toStdString()); }
bool IsValidPlatformNodeId(const QString& text)
{
if (!IsHexString(text, 40)) return false;
uint160 platform_node_id;
platform_node_id.SetHex(text.toStdString());
return !platform_node_id.IsNull();
}
bool IsNonNullP2PKHAddress(const QString& text)
{
const CTxDestination destination{DecodeDestination(text.trimmed().toStdString())};
const auto* key_id{std::get_if<PKHash>(&destination)};
return key_id != nullptr && !ToKeyID(*key_id).IsNull();
}
uint16_t PortOrDefault(const QStringList& endpoints, uint16_t default_port)
{
if (endpoints.isEmpty()) return default_port;
uint16_t port{0};
std::string host;
if (SplitHostPort(endpoints.first().trimmed().toStdString(), port, host) && !host.empty() && port != 0) return port;
return default_port;
}
std::optional<CTxDestination> ParseDestination(const QString& text, QString& error)
{
const CTxDestination destination{DecodeDestination(text.trimmed().toStdString())};
if (!IsValidDestination(destination)) {
error = QObject::tr("Invalid Dash address: %1").arg(text);
return std::nullopt;
}
return destination;
}
std::vector<std::string> ToStringVector(const QStringList& entries)
{
std::vector<std::string> result;
result.reserve(entries.size());
for (const QString& entry : entries)
result.push_back(entry.toStdString());
return result;
}
QString ProviderTxErrorText(const interfaces::ProviderTxError& error)
{
QString text{QString::fromStdString(error.message.translated)};
if (error.code == interfaces::ProviderTxErrorCode::FUNDING_ERROR) {
text = text.isEmpty() ? QObject::tr("The transaction could not be funded.")
: QObject::tr("The transaction could not be funded: %1").arg(text);
}
const QString reject_reason{QString::fromStdString(error.reject_reason)};
if (!reject_reason.isEmpty() && !text.contains(reject_reason)) {
text += QObject::tr("\n\nNetwork rejection: %1").arg(reject_reason);
}
return text;
}
bool OperatorKeyMatches(const CBLSSecretKey& secret_key, const std::vector<unsigned char>& public_key)
{
return secret_key.IsValid() && !public_key.empty() &&
secret_key.GetPublicKey().ToByteVector(/*specificLegacyScheme=*/false) == public_key;
}
} // anonymous namespace
namespace MasternodeMaintenance {
ActionAvailability actionAvailability(bool can_sign, bool owns_owner_key)
{
return {
/*update_service=*/can_sign,
/*update_registrar=*/can_sign && owns_owner_key,
/*revoke=*/can_sign,
};
}
} // namespace MasternodeMaintenance
OperatorSecretWidget::OperatorSecretWidget(QWidget* parent) :
QWidget(parent)
{
m_manual_edit = new QLineEdit(this);
m_manual_edit->setEchoMode(QLineEdit::Password);
m_manual_edit->setPlaceholderText(tr("Operator BLS secret key (64 hexadecimal characters)"));
auto* layout{new QVBoxLayout(this)};
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_manual_edit);
connect(m_manual_edit, &QLineEdit::textChanged, this, &OperatorSecretWidget::changed);
}
bool OperatorSecretWidget::isValid() const
{
std::string encoded{m_manual_edit->text().trimmed().toStdString()};
CBLSSecretKey key;
const bool valid{key.SetHexStr(encoded, /*specificLegacyScheme=*/false)};
if (!encoded.empty()) memory_cleanse(encoded.data(), encoded.size());
return valid;
}
std::optional<CBLSSecretKey> OperatorSecretWidget::takeSecret()
{
std::string encoded{m_manual_edit->text().trimmed().toStdString()};
// QLineEdit does not offer secure storage. Overwrite its visible backing
// value before clearing it, and cleanse the explicit byte copy below.
m_manual_edit->setText(QString(m_manual_edit->text().size(), QLatin1Char('0')));
m_manual_edit->clear();
CBLSSecretKey key;
const bool valid{key.SetHexStr(encoded, /*specificLegacyScheme=*/false)};
if (!encoded.empty()) memory_cleanse(encoded.data(), encoded.size());
if (!valid) return std::nullopt;
return key;
}
struct MasternodeActionDialog::UnlockHolder {
WalletModel::UnlockContext ctx;
explicit UnlockHolder(WalletModel& wallet_model) :
ctx(wallet_model.requestUnlock())
{
}
};
MasternodeActionDialog::MasternodeActionDialog(interfaces::Node& node, WalletModel* wallet_model,
const MasternodeEntry& entry, QWidget* parent) :
QDialog(parent),
m_node{node},
m_wallet_model{wallet_model},
m_protx_hash{entry.proTxHashRaw()},
m_operator_pubkey{entry.operatorPubKeyBytes()},
m_runner{wallet_model ? new MasternodeOperationRunner(node.evo(), wallet_model->wallet(), this) : nullptr}
{
}
MasternodeActionDialog::~MasternodeActionDialog()
{
m_destroying = true;
if (m_runner) m_runner->shutdown();
}
void MasternodeActionDialog::setupUi(const QString& title, const QString& intro, QLayout* form, const QString& ok_text)
{
setWindowTitle(title);
setMinimumWidth(650);
auto* layout{new QVBoxLayout(this)};
auto* intro_label{new QLabel(intro, this)};
intro_label->setWordWrap(true);
layout->addWidget(intro_label);
auto* protx_label{new QLabel(tr("Masternode: %1").arg(QString::fromStdString(m_protx_hash.ToString())), this)};
protx_label->setWordWrap(true);
protx_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
layout->addWidget(protx_label);
layout->addLayout(form);
m_status_label = new QLabel(this);
m_status_label->setWordWrap(true);
m_status_label->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR));
m_status_label->setVisible(false);
layout->addWidget(m_status_label);
m_button_box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
m_ok_button = m_button_box->button(QDialogButtonBox::Ok);
m_ok_button->setText(ok_text);
if (m_wallet_model == nullptr) {
m_ok_button->setToolTip(tr("No wallet is available."));
} else if (m_wallet_model->wallet().privateKeysDisabled()) {
m_ok_button->setToolTip(tr("This wallet is watch-only and cannot sign transactions."));
}
connect(m_button_box, &QDialogButtonBox::accepted, this, &MasternodeActionDialog::submit);
connect(m_button_box, &QDialogButtonBox::rejected, this, &MasternodeActionDialog::reject);
layout->addWidget(m_button_box);
GUIUtil::updateFonts();
validate();
}
FeeSourcePicker* MasternodeActionDialog::addFeeSourceRow(QFormLayout* form, const QString& automatic_note)
{
auto* picker{new FeeSourcePicker(this)};
picker->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
picker->setAutomaticOption(tr("Automatic (recommended)"));
picker->setWalletModel(m_wallet_model);
auto* note{new QLabel(automatic_note, this)};
note->setWordWrap(true);
auto* box{new QVBoxLayout()};
box->addWidget(picker);
box->addWidget(note);
form->addRow(tr("Fee source:"), box);
return picker;
}
bool MasternodeActionDialog::canSign() const
{
return m_wallet_model != nullptr && !m_wallet_model->wallet().privateKeysDisabled();
}
void MasternodeActionDialog::setOkValid(bool valid)
{
m_valid = valid;
if (m_ok_button) m_ok_button->setEnabled(valid && canSign() && !m_busy);
}
void MasternodeActionDialog::showError(const QString& message)
{
m_status_label->setText(message);
m_status_label->setVisible(true);
}
void MasternodeActionDialog::clearError()
{
m_status_label->clear();
m_status_label->setVisible(false);
}
void MasternodeActionDialog::abortOperation(const QString& message)
{
m_unlock.reset();
setBusy(false);
showError(message);
}
void MasternodeActionDialog::reject()
{
if (m_busy) return;
QDialog::reject();
}
bool MasternodeActionDialog::ensureUnlocked()
{
if (!canSign()) return false;
if (!m_unlock) m_unlock = std::make_unique<UnlockHolder>(*m_wallet_model);
if (m_unlock->ctx.isValid()) return true;
m_unlock.reset();
showError(tr("The wallet must be unlocked to create and sign this transaction."));
return false;
}
void MasternodeActionDialog::setBusy(bool busy)
{
if (m_busy == busy) return;
m_busy = busy;
if (busy) {
QApplication::setOverrideCursor(Qt::WaitCursor);
} else {
QApplication::restoreOverrideCursor();
}
if (m_button_box) m_button_box->setEnabled(!busy);
setOkValid(m_valid);
}
void MasternodeActionDialog::resolveOperatorKey(OperatorSecretWidget& widget, SecretCallback callback)
{
if (!ensureUnlocked()) return;
clearError();
setBusy(true);
auto key{widget.takeSecret()};
if (!key) {
abortOperation(tr("Enter a valid basic-scheme BLS operator secret key."));
return;
}
if (!OperatorKeyMatches(*key, m_operator_pubkey)) {
abortOperation(tr("The operator secret key does not match this masternode's registered public key."));
return;
}
callback(*key);
}
void MasternodeActionDialog::startSubmission(std::function<bool(MasternodeOperationRunner::SubmissionCallback)> start)
{
if (!m_busy) {
if (!ensureUnlocked()) return;
clearError();
setBusy(true);
}
if (!start([this](auto result) { finishSubmission(std::move(result)); })) {
abortOperation(tr("Another masternode operation is already in progress."));
}
}
void MasternodeActionDialog::finishSubmission(MasternodeOperationRunner::SubmissionResult result)
{
m_unlock.reset();
if (m_destroying) {
setBusy(false);
return;
}
setBusy(false);
if (const auto* error{std::get_if<interfaces::ProviderTxError>(&result)}) {
showError(ProviderTxErrorText(*error));
return;
}
const auto& submission{std::get<interfaces::ProviderTxSubmission>(result)};
if (!submission.tx) {
showError(tr("The operation completed without returning a transaction."));
return;
}
if (!submission.submitted) {
showError(tr("The transaction was created but was not sent to the network."));
return;
}
QMessageBox::information(this, windowTitle(),
tr("The transaction was sent successfully.") + "\n\n" +
tr("Transaction ID: %1").arg(QString::fromStdString(submission.tx->GetHash().ToString())));
accept();
}
UpdateServiceDialog::UpdateServiceDialog(interfaces::Node& node, WalletModel* wallet_model,
const MasternodeEntry& entry, QWidget* parent) :
UpdateServiceDialog(node, wallet_model, entry, node.evo().getProviderTxCapabilities(), parent)
{
}
UpdateServiceDialog::UpdateServiceDialog(interfaces::Node& node, WalletModel* wallet_model, const MasternodeEntry& entry,
interfaces::ProviderTxCapabilities capabilities, QWidget* parent) :
MasternodeActionDialog(node, wallet_model, entry, parent),
m_type{entry.type()},
m_operator_reward_pct{entry.operatorRewardPct()},
m_capabilities{capabilities}
{
auto* form{new QFormLayout()};
form->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
m_addrs_edit = new QLineEdit(this);
m_addrs_edit->setText(entry.coreP2PAddresses());
m_addrs_edit->setPlaceholderText(tr("IP:PORT, comma-separated for multiple entries"));
if (!m_capabilities.extended_addresses) {
m_addrs_edit->setToolTip(tr("Multiple addresses require extended provider transactions."));
}
connect(m_addrs_edit, &QLineEdit::textChanged, this, &UpdateServiceDialog::validate);
form->addRow(m_capabilities.extended_addresses ? tr("Service addresses:") : tr("Service address:"), m_addrs_edit);
m_operator_key = new OperatorSecretWidget(this);
m_operator_key->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
connect(m_operator_key, &OperatorSecretWidget::changed, this, &UpdateServiceDialog::validate);
form->addRow(tr("Operator key:"), m_operator_key);
if (m_type == MnType::Evo) {
m_platform_node_id_edit = new QLineEdit(this);
m_platform_node_id_edit->setText(entry.platformNodeID());
m_platform_node_id_edit->setPlaceholderText(tr("Platform node ID (40 hexadecimal characters)"));
connect(m_platform_node_id_edit, &QLineEdit::textChanged, this, &UpdateServiceDialog::validate);
form->addRow(tr("Platform node ID:"), m_platform_node_id_edit);
if (m_capabilities.extended_addresses) {
m_platform_p2p_edit = new QLineEdit(this);
m_platform_p2p_edit->setText(entry.platformP2PAddresses());
m_platform_p2p_edit->setPlaceholderText(tr("IP:PORT, comma-separated for multiple entries"));
connect(m_platform_p2p_edit, &QLineEdit::textChanged, this, &UpdateServiceDialog::validate);
form->addRow(tr("Platform P2P addresses:"), m_platform_p2p_edit);
m_platform_https_edit = new QLineEdit(this);
m_platform_https_edit->setText(entry.platformHTTPSAddresses());
m_platform_https_edit->setPlaceholderText(tr("IP:PORT or domain:port, comma-separated"));
connect(m_platform_https_edit, &QLineEdit::textChanged, this, &UpdateServiceDialog::validate);
form->addRow(tr("Platform HTTPS addresses:"), m_platform_https_edit);
} else {
const QStringList p2p{entry.platformP2PAddresses().split(',', Qt::SkipEmptyParts)};
const QStringList https{entry.platformHTTPSAddresses().split(',', Qt::SkipEmptyParts)};
m_platform_p2p_port_edit = new QSpinBox(this);
m_platform_p2p_port_edit->setRange(1, std::numeric_limits<uint16_t>::max());
m_platform_p2p_port_edit->setValue(PortOrDefault(p2p, Params().GetDefaultPlatformP2PPort()));
form->addRow(tr("Platform P2P port:"), m_platform_p2p_port_edit);
m_platform_https_port_edit = new QSpinBox(this);
m_platform_https_port_edit->setRange(1, std::numeric_limits<uint16_t>::max());
m_platform_https_port_edit->setValue(PortOrDefault(https, Params().GetDefaultPlatformHTTPPort()));
form->addRow(tr("Platform HTTPS port:"), m_platform_https_port_edit);
}
}
if (m_operator_reward_pct > 0) {
m_operator_payout_edit = new QValidatedLineEdit(this);
GUIUtil::setupAddressWidget(m_operator_payout_edit, this);
m_operator_payout_edit->setText(entry.operatorPayoutAddress());
connect(m_operator_payout_edit, &QLineEdit::textChanged, this, &UpdateServiceDialog::validate);
form->addRow(tr("Operator payout address:"), m_operator_payout_edit);
}
m_fee_source = addFeeSourceRow(form, tr("Automatic uses the current operator payout, then the masternode payout. "
"Select an address only "
"to override that choice."));
setupUi(m_type == MnType::Evo ? tr("Update EvoNode Service") : tr("Update Masternode Service"),
tr("Update the registered service endpoints. A successful update also revives a PoSe-banned "
"masternode. Every current value is prefilled so unchanged fields are preserved."),
form, tr("Send Update"));
}
void UpdateServiceDialog::validate()
{
QString error;
bool ok{buildNetInfo(error).has_value()};
ok &= m_operator_key->isValid();
if (m_operator_payout_edit) {
ok &= m_operator_payout_edit->text().trimmed().isEmpty() || m_operator_payout_edit->isValid();
}
if (m_type == MnType::Evo) {
ok &= IsValidPlatformNodeId(m_platform_node_id_edit->text().trimmed());
}
setOkValid(ok);
}
std::optional<interfaces::ProviderNetInfo> UpdateServiceDialog::buildNetInfo(QString& error) const
{
interfaces::ProviderNetInfo net_info;
net_info.core_p2p = ToStringVector(MasternodeWidgetUtil::tokenizeEndpointList(m_addrs_edit->text()));
if (m_type == MnType::Evo) {
if (m_capabilities.extended_addresses) {
net_info.platform_p2p = ToStringVector(MasternodeWidgetUtil::tokenizeEndpointList(m_platform_p2p_edit->text()));
net_info.platform_https = ToStringVector(
MasternodeWidgetUtil::tokenizeEndpointList(m_platform_https_edit->text()));
} else {
net_info.platform_p2p = static_cast<uint16_t>(m_platform_p2p_port_edit->value());
net_info.platform_https = static_cast<uint16_t>(m_platform_https_port_edit->value());
}
}
if (const auto validation_error{
m_node.evo().validateProviderNetInfo(net_info, m_type, m_capabilities.version, /*optional=*/false)}) {
error = ProviderTxErrorText(*validation_error);
return std::nullopt;
}
return net_info;
}
std::optional<interfaces::ProviderUpdateServiceRequest> UpdateServiceDialog::buildRequest(const CBLSSecretKey& operator_key,
QString& error) const
{
interfaces::ProviderUpdateServiceRequest request;
request.type = m_type;
request.pro_tx_hash = m_protx_hash;
request.operator_key = operator_key;
request.submit = true;
auto net_info{buildNetInfo(error)};
if (!net_info) return std::nullopt;
request.net_info = std::move(*net_info);
if (m_type == MnType::Evo) {
const QString platform_node_id_text{m_platform_node_id_edit->text().trimmed()};
if (!IsValidPlatformNodeId(platform_node_id_text)) {
error = tr("Enter a valid Platform node ID (40 hexadecimal characters).");
return std::nullopt;
}
uint160 platform_node_id;
platform_node_id.SetHex(platform_node_id_text.toStdString());
request.platform_node_id = platform_node_id;
}
if (m_operator_payout_edit && !m_operator_payout_edit->text().trimmed().isEmpty()) {
auto payout{ParseDestination(m_operator_payout_edit->text(), error)};
if (!payout) return std::nullopt;
request.operator_payout = *payout;
}
if (const QString fee_source{m_fee_source->selectedAddress()}; !fee_source.isEmpty()) {
auto fee{ParseDestination(fee_source, error)};
if (!fee) return std::nullopt;
request.fee_source = *fee;
}
return request;
}
void UpdateServiceDialog::submit()
{
resolveOperatorKey(*m_operator_key, [this](CBLSSecretKey operator_key) {
QString error;
auto request{buildRequest(operator_key, error)};
if (!request) {
abortOperation(error);
return;
}
startSubmission([this, request = std::move(*request)](auto callback) mutable {
return m_runner->updateMasternodeService(std::move(request), std::move(callback));
});
});
}
UpdateRegistrarDialog::UpdateRegistrarDialog(interfaces::Node& node, WalletModel* wallet_model,
const MasternodeEntry& entry, QWidget* parent) :
UpdateRegistrarDialog(node, wallet_model, entry, node.evo().getProviderTxCapabilities(), parent)
{
}
UpdateRegistrarDialog::UpdateRegistrarDialog(interfaces::Node& node, WalletModel* wallet_model,
const MasternodeEntry& entry,
interfaces::ProviderTxCapabilities capabilities, QWidget* parent) :
MasternodeActionDialog(node, wallet_model, entry, parent),
m_capabilities{capabilities},
m_initial_operator_pubkey{entry.operatorPubKey(m_capabilities.version == ProTxVersion::LegacyBLS)},
m_initial_voting{entry.votingAddress()},
m_initial_payout{entry.payoutAddresses().size() == 1 ? entry.payoutAddresses().front() : QString{}}
{
auto* form{new QFormLayout()};
form->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
m_operator_pubkey_edit = new QLineEdit(this);
m_operator_pubkey_edit->setText(m_initial_operator_pubkey);
m_operator_pubkey_edit->setPlaceholderText(tr("Operator BLS public key (96 hexadecimal characters)"));
connect(m_operator_pubkey_edit, &QLineEdit::textChanged, this, &UpdateRegistrarDialog::validate);
form->addRow(tr("Operator public key:"), m_operator_pubkey_edit);
auto* warning{new QLabel(tr("Changing the operator key immediately PoSe-bans the masternode. The new operator must "
"send an Update "
"Service transaction to revive it."),
this)};
warning->setWordWrap(true);
warning->setStyleSheet(GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_WARNING));
form->addRow(warning);
m_voting_edit = new QValidatedLineEdit(this);
GUIUtil::setupAddressWidget(m_voting_edit, this);
m_voting_edit->setText(m_initial_voting);
connect(m_voting_edit, &QLineEdit::textChanged, this, &UpdateRegistrarDialog::validate);
form->addRow(tr("Voting address:"), m_voting_edit);
m_payout_edit = new QValidatedLineEdit(this);
GUIUtil::setupAddressWidget(m_payout_edit, this);
m_payout_edit->setText(m_initial_payout);
connect(m_payout_edit, &QLineEdit::textChanged, this, &UpdateRegistrarDialog::validate);
form->addRow(tr("Payout address:"), m_payout_edit);
if (entry.payoutAddresses().size() != 1) {
m_payout_edit->setEnabled(false);
m_payout_edit->setPlaceholderText(tr("Multiple payout shares are preserved; use the RPC to change them"));
m_payout_edit->setToolTip(tr("This dialog cannot safely flatten a multi-payout masternode into one address."));
}
m_fee_source = addFeeSourceRow(form, tr("Automatic uses the masternode's current primary payout address. Select an "
"address only to "
"override that choice."));
setupUi(tr("Update Masternode Registrar"),
tr("Update the operator key, voting address, or payout address. All current values are prefilled; "
"only changed fields are sent. The owner key must be present in this wallet."),
form, tr("Send Update"));
}
bool UpdateRegistrarDialog::operatorChanged() const
{
return m_operator_pubkey_edit->text().trimmed() != m_initial_operator_pubkey;
}
bool UpdateRegistrarDialog::votingChanged() const { return m_voting_edit->text().trimmed() != m_initial_voting; }
bool UpdateRegistrarDialog::payoutChanged() const
{
return m_payout_edit->isEnabled() && m_payout_edit->text().trimmed() != m_initial_payout;
}
void UpdateRegistrarDialog::validate()
{
const QString operator_pubkey{m_operator_pubkey_edit->text().trimmed()};
const bool any_change{operatorChanged() || votingChanged() || payoutChanged()};
CBLSPublicKey parsed_operator;
const bool operator_valid{
parsed_operator.SetHexStr(operator_pubkey.toStdString(), m_capabilities.version == ProTxVersion::LegacyBLS)};
const bool ok{any_change && operator_valid && IsNonNullP2PKHAddress(m_voting_edit->text()) &&
(!m_payout_edit->isEnabled() || MasternodeWidgetUtil::isP2PKHorP2SHAddress(m_payout_edit->text()))};
setOkValid(ok);
}
std::optional<interfaces::ProviderUpdateRegistrarRequest> UpdateRegistrarDialog::buildRequest(QString& error) const
{
interfaces::ProviderUpdateRegistrarRequest request;
request.pro_tx_hash = m_protx_hash;
request.use_legacy_bls_scheme = m_capabilities.version == ProTxVersion::LegacyBLS;
request.submit = true;
if (operatorChanged()) {
CBLSPublicKey key;
const bool legacy{m_capabilities.version == ProTxVersion::LegacyBLS};
if (!key.SetHexStr(m_operator_pubkey_edit->text().trimmed().toStdString(), legacy)) {
error = tr("Enter a valid operator public key for the current provider-transaction version.");
return std::nullopt;
}
request.operator_key = key;
}
if (votingChanged()) {
const auto destination{ParseDestination(m_voting_edit->text(), error)};
const auto* key_id{destination ? std::get_if<PKHash>(&*destination) : nullptr};
if (!key_id || ToKeyID(*key_id).IsNull()) {
if (error.isEmpty()) error = tr("The voting address must be a key address.");
return std::nullopt;
}
request.voting_key = ToKeyID(*key_id);
}
if (payoutChanged()) {
auto payout{ParseDestination(m_payout_edit->text(), error)};
if (!payout) return std::nullopt;
request.payouts = std::vector<interfaces::ProviderPayout>{{*payout, interfaces::ProviderPayout::MAX_REWARD}};
request.uses_extended_payouts = m_capabilities.version >= ProTxVersion::ExtAddr;
}
if (const QString fee_source{m_fee_source->selectedAddress()}; !fee_source.isEmpty()) {
auto fee{ParseDestination(fee_source, error)};
if (!fee) return std::nullopt;
request.fee_source = *fee;
}
return request;
}
void UpdateRegistrarDialog::submit()
{
QString error;
auto request{buildRequest(error)};
if (!request) {
showError(error);
return;
}
startSubmission([this, request = std::move(*request)](auto callback) mutable {
return m_runner->updateMasternodeRegistrar(std::move(request), std::move(callback));
});
}
RevokeDialog::RevokeDialog(interfaces::Node& node, WalletModel* wallet_model, const MasternodeEntry& entry,
QWidget* parent) :
MasternodeActionDialog(node, wallet_model, entry, parent)
{
auto* form{new QFormLayout()};
form->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
m_reason_combo = new QComboBox(this);
m_reason_combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_reason_combo->addItem(tr("Not specified"), CProUpRevTx::REASON_NOT_SPECIFIED);
m_reason_combo->addItem(tr("Termination of service"), CProUpRevTx::REASON_TERMINATION_OF_SERVICE);
m_reason_combo->addItem(tr("Compromised keys"), CProUpRevTx::REASON_COMPROMISED_KEYS);
m_reason_combo->addItem(tr("Change of keys"), CProUpRevTx::REASON_CHANGE_OF_KEYS);
form->addRow(tr("Reason:"), m_reason_combo);
m_operator_key = new OperatorSecretWidget(this);
m_operator_key->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
connect(m_operator_key, &OperatorSecretWidget::changed, this, &RevokeDialog::validate);
form->addRow(tr("Operator key:"), m_operator_key);
m_fee_source = addFeeSourceRow(form, tr("Automatic uses the current operator payout, then the masternode payout. "
"Select an address only "
"to override that choice."));
setupUi(tr("Revoke Masternode Service"),
tr("Revoking clears the service address and PoSe-bans the masternode until its owner changes the "
"operator key. The collateral is not affected."),
form, tr("Revoke"));
}
void RevokeDialog::validate() { setOkValid(m_operator_key->isValid()); }
std::optional<interfaces::ProviderRevokeRequest> RevokeDialog::buildRequest(CBLSSecretKey operator_key, QString& error) const
{
interfaces::ProviderRevokeRequest request;
request.pro_tx_hash = m_protx_hash;
request.operator_key = operator_key;
request.reason = static_cast<uint16_t>(m_reason_combo->currentData().toUInt());
request.submit = true;
if (const QString fee_source{m_fee_source->selectedAddress()}; !fee_source.isEmpty()) {
auto fee{ParseDestination(fee_source, error)};
if (!fee) return std::nullopt;
request.fee_source = *fee;
}
return request;
}
void RevokeDialog::submit()
{
resolveOperatorKey(*m_operator_key, [this](CBLSSecretKey operator_key) {
QString error;
auto request{buildRequest(operator_key, error)};
if (!request) {
abortOperation(error);
return;
}
startSubmission([this, request = std::move(*request)](auto callback) mutable {
return m_runner->revokeMasternode(std::move(request), std::move(callback));
});
});
}