Repository navigation
Expand file tree
/
Copy pathmasternodelist.cpp
More file actions
executable file
·745 lines (626 loc) · 27.3 KB
/
Copy pathmasternodelist.cpp
File metadata and controls
executable file
·745 lines (626 loc) · 27.3 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
#include <qt/masternodelist.h>
#include <qt/forms/ui_masternodelist.h>
#include <crown/legacysigner.h>
#include <crown/init.h>
#include <init.h>
#include <key_io.h>
#include <masternode/activemasternode.h>
#include <masternode/masternode-budget.h>
#include <masternode/masternode-sync.h>
#include <masternode/masternodeconfig.h>
#include <masternode/masternodeman.h>
#include <node/context.h>
#include <rpc/blockchain.h>
#include <qt/addresstablemodel.h>
#include <qt/bitcoinunits.h>
#include <qt/clientmodel.h>
#include <qt/createmasternodedialog.h>
#include <qt/datetablewidgetitem.h>
#include <qt/privatekeywidget.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <qt/startmissingdialog.h>
#include <qt/walletmodel.h>
#include <sync.h>
#include <util/time.h>
#include <wallet/wallet.h>
#include <QMessageBox>
#include <QTimer>
int GetOffsetFromUtc()
{
#if QT_VERSION < 0x050200
const QDateTime dateTime1 = QDateTime::currentDateTime();
const QDateTime dateTime2 = QDateTime(dateTime1.date(), dateTime1.time(), Qt::UTC);
return dateTime1.secsTo(dateTime2);
#else
return QDateTime::currentDateTime().offsetFromUtc();
#endif
}
RecursiveMutex cs_masternodes;
MasternodeList::MasternodeList(const PlatformStyle *platformStyle, QWidget *parent) :
QWidget(parent),
ui(new Ui::MasternodeList),
clientModel(0),
walletModel(0)
{
ui->setupUi(this);
ui->startButton->setEnabled(false);
ui->voteManyYesButton->setEnabled(false);
ui->voteManyNoButton->setEnabled(false);
int columnAliasWidth = 100;
int columnAddressWidth = 200;
int columnProtocolWidth = 60;
int columnStatusWidth = 80;
int columnActiveWidth = 130;
int columnLastSeenWidth = 130;
ui->tableWidgetMyMasternodes->setColumnWidth(0, columnAliasWidth);
ui->tableWidgetMyMasternodes->setColumnWidth(1, columnAddressWidth);
ui->tableWidgetMyMasternodes->setColumnWidth(2, columnProtocolWidth);
ui->tableWidgetMyMasternodes->setColumnWidth(3, columnStatusWidth);
ui->tableWidgetMyMasternodes->setColumnWidth(4, columnActiveWidth);
ui->tableWidgetMyMasternodes->setColumnWidth(5, columnLastSeenWidth);
ui->tableWidgetMasternodes->setColumnWidth(0, columnAddressWidth);
ui->tableWidgetMasternodes->setColumnWidth(1, columnProtocolWidth);
ui->tableWidgetMasternodes->setColumnWidth(2, columnStatusWidth);
ui->tableWidgetMasternodes->setColumnWidth(3, columnActiveWidth);
ui->tableWidgetMasternodes->setColumnWidth(4, columnLastSeenWidth);
ui->tableWidgetMyMasternodes->setContextMenuPolicy(Qt::CustomContextMenu);
QAction *startAliasAction = new QAction(tr("Start alias"), this);
QAction *editAction = new QAction(tr("Edit"), this);
contextMenu = new QMenu();
contextMenu->addAction(startAliasAction);
contextMenu->addAction(editAction);
connect(ui->tableWidgetMyMasternodes, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&)));
connect(startAliasAction, SIGNAL(triggered()), this, SLOT(on_startButton_clicked()));
connect(editAction, SIGNAL(triggered()), this, SLOT(on_editButton_clicked()));
connect(ui->reloadButton, SIGNAL(triggered()), this, SLOT(on_reloadButton_clicked()));
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateNodeList()));
connect(timer, SIGNAL(timeout()), this, SLOT(updateVoteList()));
connect(timer, SIGNAL(timeout()), this, SLOT(updateMyNodeList()));
connect(timer, SIGNAL(timeout()), this, SLOT(updateNextSuperblock()));
timer->start(1000);
updateNodeList();
updateVoteList();
updateNextSuperblock();
// Fill MN list
fFilterUpdated = false;
nTimeFilterUpdated = GetTime();
updateNodeList();
}
MasternodeList::~MasternodeList()
{
delete ui;
}
void MasternodeList::notReady()
{
QMessageBox::critical(this, tr("Command is not available right now"),
tr("You can't use this command until masternode list is synced"));
return;
}
void MasternodeList::setClientModel(ClientModel *model)
{
if (this->clientModel == NULL)
{
this->clientModel = model;
if(model)
{
// try to update list when masternode count changes
connect(clientModel, SIGNAL(strMasternodesChanged(QString)), this, SLOT(updateNodeList()));
}
}
}
void MasternodeList::setWalletModel(WalletModel *model)
{
if (this->walletModel == NULL)
{
this->walletModel = model;
}
}
void MasternodeList::showContextMenu(const QPoint& point)
{
QTableWidgetItem* item = ui->tableWidgetMyMasternodes->itemAt(point);
if (item) contextMenu->exec(QCursor::pos());
}
void MasternodeList::StartAlias(std::string strAlias)
{
std::string strStatusHtml;
strStatusHtml += "<center>Alias: " + strAlias;
for (CNodeEntry mne : masternodeConfig.getEntries()) {
if (mne.getAlias() == strAlias) {
std::string strError;
CMasternodeBroadcast mnb;
bool fSuccess = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);
if (fSuccess) {
strStatusHtml += "<br>Successfully started masternode.";
mnodeman.UpdateMasternodeList(mnb, *g_rpc_node->connman);
mnb.Relay(*g_rpc_node->connman);
} else {
strStatusHtml += "<br>Failed to start masternode.<br>Error: " + strError;
}
break;
}
}
strStatusHtml += "</center>";
QMessageBox msg;
msg.setText(QString::fromStdString(strStatusHtml));
msg.exec();
}
void MasternodeList::StartAll(std::string strCommand)
{
int nTotal = 0;
int nCountSuccessful = 0;
int nCountFailed = 0;
std::string strFailedHtml;
for (CNodeEntry mne : masternodeConfig.getEntries()) {
std::string strError;
CMasternodeBroadcast mnb;
CTxIn txin = CTxIn(uint256S(mne.getTxHash()), uint32_t(atoi(mne.getOutputIndex().c_str())));
CMasternode* pmn = mnodeman.Find(txin);
if (strCommand == "start-missing" && pmn) continue;
bool fSuccess = CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb);
if (fSuccess) {
nCountSuccessful++;
mnodeman.UpdateMasternodeList(mnb, *g_rpc_node->connman);
mnb.Relay(*g_rpc_node->connman);
} else {
nCountFailed++;
strFailedHtml += "\nFailed to start " + mne.getAlias() + ". Error: " + strError;
}
nTotal++;
}
GetMainWallet()->Lock();
std::string returnObj;
returnObj = strprintf("Successfully started %d masternodes, failed to start %d, total %d", nCountSuccessful, nCountFailed, nCountFailed + nCountSuccessful);
if (nCountFailed > 0) {
returnObj += strFailedHtml;
}
QMessageBox msg;
msg.setText(QString::fromStdString(returnObj));
msg.exec();
updateMyNodeList(true);
}
void MasternodeList::updateMyMasternodeInfo(QString strAlias, QString strAddr, QString privkey, QString txHash, QString txIndex, CMasternode *pmn)
{
LOCK(cs_mnlistupdate);
bool fOldRowFound = false;
int nNewRow = 0;
for (int i = 0; i < ui->tableWidgetMyMasternodes->rowCount(); i++) {
if (ui->tableWidgetMyMasternodes->item(i, 0)->text() == strAlias) {
fOldRowFound = true;
nNewRow = i;
break;
}
}
if (nNewRow == 0 && !fOldRowFound) {
nNewRow = ui->tableWidgetMyMasternodes->rowCount();
ui->tableWidgetMyMasternodes->insertRow(nNewRow);
}
QTableWidgetItem* aliasItem = new QTableWidgetItem(strAlias);
QTableWidgetItem* addrItem = new QTableWidgetItem(pmn ? QString::fromStdString(pmn->addr.ToString()) : strAddr);
PrivateKeyWidget *privateKeyWidget = new PrivateKeyWidget(privkey);
QTableWidgetItem* protocolItem = new QTableWidgetItem(QString::number(pmn ? pmn->protocolVersion : -1));
QTableWidgetItem* statusItem = new QTableWidgetItem(QString::fromStdString(pmn ? pmn->Status() : "MISSING"));
QTableWidgetItem* activeSecondsItem = new QTableWidgetItem(QString::fromStdString(DurationToDHMS(pmn ? (int64_t)(pmn->lastPing.sigTime - pmn->sigTime) : 0)));
QTableWidgetItem* lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M", pmn ? (int64_t)pmn->lastPing.sigTime : 0)));
QTableWidgetItem* pubkeyItem = new QTableWidgetItem(QString::fromStdString(pmn ? EncodeDestination(PKHash(pmn->pubkey)) : ""));
ui->tableWidgetMyMasternodes->setItem(nNewRow, 0, aliasItem);
ui->tableWidgetMyMasternodes->setItem(nNewRow, 1, addrItem);
ui->tableWidgetMyMasternodes->setCellWidget(nNewRow, 2, privateKeyWidget);
ui->tableWidgetMyMasternodes->setColumnWidth(2, 150);
ui->tableWidgetMyMasternodes->setItem(nNewRow, 3, protocolItem);
ui->tableWidgetMyMasternodes->setItem(nNewRow, 4, statusItem);
ui->tableWidgetMyMasternodes->setItem(nNewRow, 5, activeSecondsItem);
ui->tableWidgetMyMasternodes->setItem(nNewRow, 6, lastSeenItem);
ui->tableWidgetMyMasternodes->setItem(nNewRow, 7, pubkeyItem);
}
void MasternodeList::updateMyNodeList(bool fForce)
{
static int64_t nTimeMyListUpdated = 0;
// automatically update my masternode list only once in MY_MASTERNODELIST_UPDATE_SECONDS seconds,
// this update still can be triggered manually at any time via button click
int64_t nSecondsTillUpdate = nTimeMyListUpdated + MY_MASTERNODELIST_UPDATE_SECONDS - GetTime();
ui->secondsLabel->setText(QString::number(nSecondsTillUpdate));
if (nSecondsTillUpdate > 0 && !fForce) return;
nTimeMyListUpdated = GetTime();
ui->tableWidgetMyMasternodes->setSortingEnabled(false);
for (CNodeEntry mne : masternodeConfig.getEntries()) {
CTxIn txin = CTxIn(uint256S(mne.getTxHash()), uint32_t(atoi(mne.getOutputIndex().c_str())));
CMasternode* pmn = mnodeman.Find(txin);
updateMyMasternodeInfo(QString::fromStdString(mne.getAlias()), QString::fromStdString(mne.getIp()), QString::fromStdString(mne.getPrivKey()), QString::fromStdString(mne.getTxHash()),
QString::fromStdString(mne.getOutputIndex()), pmn);
}
ui->tableWidgetMyMasternodes->setSortingEnabled(true);
// reset "timer"
ui->secondsLabel->setText("0");
}
void MasternodeList::updateNodeList()
{
TRY_LOCK(cs_mnlistupdate, fLockAcquired);
if(!fLockAcquired) {
return;
}
static int64_t nTimeListUpdated = GetTime();
// to prevent high cpu usage update only once in MASTERNODELIST_UPDATE_SECONDS seconds
// or MASTERNODELIST_FILTER_COOLDOWN_SECONDS seconds after filter was last changed
int64_t nSecondsToWait = fFilterUpdated
? nTimeFilterUpdated - GetTime() + MASTERNODELIST_FILTER_COOLDOWN_SECONDS
: nTimeListUpdated - GetTime() + MASTERNODELIST_UPDATE_SECONDS;
if(fFilterUpdated) ui->countLabel->setText(QString::fromStdString(strprintf("Please wait... %d", nSecondsToWait)));
if(nSecondsToWait > 0) return;
nTimeListUpdated = GetTime();
fFilterUpdated = false;
QString strToFilter;
ui->countLabel->setText("Updating...");
ui->tableWidgetMasternodes->setSortingEnabled(false);
ui->tableWidgetMasternodes->clearContents();
ui->tableWidgetMasternodes->setRowCount(0);
std::vector<CMasternode> vMasternodes = mnodeman.GetFullMasternodeVector();
for (CMasternode& mn : vMasternodes)
{
// populate list
// Address, Protocol, Status, Active Seconds, Last Seen, Pub Key
QTableWidgetItem *addressItem = new QTableWidgetItem(QString::fromStdString(mn.addr.ToString()));
QTableWidgetItem *protocolItem = new QTableWidgetItem(QString::number(mn.protocolVersion));
QTableWidgetItem *statusItem = new QTableWidgetItem(QString::fromStdString(mn.Status()));
QTableWidgetItem *activeSecondsItem = new QTableWidgetItem(QString::fromStdString(DurationToDHMS(mn.lastPing.sigTime - mn.sigTime)));
QTableWidgetItem *lastSeenItem = new QTableWidgetItem(QString::fromStdString(DateTimeStrFormat("%Y-%m-%d %H:%M", mn.lastPing.sigTime + QDateTime::currentDateTime().offsetFromUtc())));
QTableWidgetItem *pubkeyItem = new QTableWidgetItem(QString::fromStdString(EncodeDestination(PKHash(mn.pubkey))));
if (strCurrentFilter != "")
{
strToFilter = addressItem->text() + " " +
protocolItem->text() + " " +
statusItem->text() + " " +
activeSecondsItem->text() + " " +
lastSeenItem->text() + " " +
pubkeyItem->text();
if (!strToFilter.contains(strCurrentFilter)) continue;
}
ui->tableWidgetMasternodes->insertRow(0);
ui->tableWidgetMasternodes->setItem(0, 0, addressItem);
ui->tableWidgetMasternodes->setItem(0, 1, protocolItem);
ui->tableWidgetMasternodes->setItem(0, 2, statusItem);
ui->tableWidgetMasternodes->setItem(0, 3, activeSecondsItem);
ui->tableWidgetMasternodes->setItem(0, 4, lastSeenItem);
ui->tableWidgetMasternodes->setItem(0, 5, pubkeyItem);
}
ui->countLabel->setText(QString::number(ui->tableWidgetMasternodes->rowCount()));
ui->tableWidgetMasternodes->setSortingEnabled(true);
}
void MasternodeList::on_reloadButton_clicked()
{
TRY_LOCK(cs_mnlistupdate, fLockAcquired);
if(!fLockAcquired) {
return;
}
ui->tableWidgetMyMasternodes->setSortingEnabled(false);
ui->tableWidgetMyMasternodes->clearContents();
ui->tableWidgetMyMasternodes->setRowCount(0);
loadNodeConfiguration();
updateMyNodeList(true);
}
void MasternodeList::updateNextSuperblock()
{
Q_ASSERT(::ChainActive().Tip() != NULL);
CBlockIndex* pindexPrev = ::ChainActive().Tip();
if (pindexPrev)
{
const int nextBlock = GetNextSuperblock(pindexPrev->nHeight);
ui->superblockLabel->setText(QString::number(nextBlock));
}
}
void MasternodeList::on_filterLineEdit_textChanged(const QString &strFilterIn)
{
strCurrentFilter = strFilterIn;
nTimeFilterUpdated = GetTime();
fFilterUpdated = true;
ui->countLabel->setText(QString::fromStdString(strprintf("Please wait... %d", MASTERNODELIST_FILTER_COOLDOWN_SECONDS)));
}
void MasternodeList::on_startButton_clicked()
{
// Find selected node alias
QItemSelectionModel* selectionModel = ui->tableWidgetMyMasternodes->selectionModel();
QModelIndexList selected = selectionModel->selectedRows();
if (selected.count() == 0) return;
QModelIndex index = selected.at(0);
int nSelectedRow = index.row();
std::string strAlias = ui->tableWidgetMyMasternodes->item(nSelectedRow, 0)->text().toStdString();
// Display message box
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm masternode start"),
tr("Are you sure you want to start masternode %1?").arg(QString::fromStdString(strAlias)),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
if (retval != QMessageBox::Yes) return;
StartAlias(strAlias);
}
void MasternodeList::on_startAllButton_clicked()
{
if (!masternodeSync.IsSynced()) {
notReady();
return;
}
// Display message box
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm all masternodes start"),
tr("Are you sure you want to start ALL masternodes?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
if (retval != QMessageBox::Yes) return;
StartAll();
}
void MasternodeList::on_startMissingButton_clicked()
{
if(masternodeSync.RequestedMasternodeAssets <= MASTERNODE_SYNC_LIST ||
masternodeSync.RequestedMasternodeAssets == MASTERNODE_SYNC_FAILED) {
QMessageBox::critical(this, tr("Command is not available right now"),
tr("You can't use this command until masternode list is synced"));
return;
}
StartMissingDialog dg(this);
dg.setWindowTitle("Confirm missing masternodes start");
dg.setText("Are you sure you want to start MISSING masternodes?");
dg.setCheckboxText("Start all nodes");
dg.setWarningText(QString("<b>") + tr("WARNING!") + QString("</b>") +
" If checked all ACTIVE masternodes will be reset.");
bool startAll = false;
// Display message box
if (dg.exec()) {
if (dg.checkboxChecked()) {
startAll = true;
}
startAll ? StartAll() : StartAll("start-missing");
}
}
void MasternodeList::on_tableWidgetMyMasternodes_itemSelectionChanged()
{
if(ui->tableWidgetMyMasternodes->selectedItems().count() > 0)
{
ui->startButton->setEnabled(true);
}
}
void MasternodeList::on_UpdateButton_clicked()
{
updateMyNodeList(true);
}
void MasternodeList::on_UpdateVotesButton_clicked()
{
updateVoteList(true);
}
void MasternodeList::updateVoteList(bool reset)
{
Q_ASSERT(::ChainActive().Tip() != NULL);
static int64_t lastVoteListUpdate = 0;
// automatically update my masternode list only once in MY_MASTERNODELIST_UPDATE_SECONDS seconds,
// this update still can be triggered manually at any time via button click
int64_t timeTillUpdate = lastVoteListUpdate + MY_MASTERNODELIST_UPDATE_SECONDS - GetTime();
ui->voteSecondsLabel->setText(QString::number(timeTillUpdate));
if(timeTillUpdate > 0 && !reset) return;
lastVoteListUpdate = GetTime();
QString strToFilter;
ui->tableWidgetVoting->setSortingEnabled(false);
ui->tableWidgetVoting->clearContents();
ui->tableWidgetVoting->setRowCount(0);
int64_t nTotalAllotted = 0;
CBlockIndex* pindexPrev = ::ChainActive().Tip();
if(pindexPrev == NULL)
return;
int blockStart = GetNextSuperblock(pindexPrev->nHeight);
int blockEnd = blockStart + GetBudgetPaymentCycleBlocks() - 1;
std::vector<CBudgetProposal*> winningProps = budget.GetAllProposals();
for (CBudgetProposal* pbudgetProposal : winningProps)
{
CTxDestination address;
ExtractDestination(pbudgetProposal->GetPayee(), address);
if((int64_t)pbudgetProposal->GetRemainingPaymentCount() <= 0) continue;
if (pbudgetProposal->fValid &&
pbudgetProposal->nBlockStart <= blockStart &&
pbudgetProposal->nBlockEnd >= blockEnd)
{
// populate list
QTableWidgetItem *nameItem = new QTableWidgetItem(QString::fromStdString(pbudgetProposal->GetName()));
QLabel *urlItem = new QLabel("<a href=\"" + QString::fromStdString(pbudgetProposal->GetURL()) + "\">" +
QString::fromStdString(pbudgetProposal->GetURL()) + "</a>");
urlItem->setOpenExternalLinks(true);
urlItem->setStyleSheet("background-color: transparent;");
QTableWidgetItem *hashItem = new QTableWidgetItem(QString::fromStdString(pbudgetProposal->GetHash().ToString()));
GUIUtil::QTableWidgetNumberItem *blockStartItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetBlockStart());
GUIUtil::QTableWidgetNumberItem *blockEndItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetBlockEnd());
GUIUtil::QTableWidgetNumberItem *paymentsItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetTotalPaymentCount());
GUIUtil::QTableWidgetNumberItem *remainingPaymentsItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetRemainingPaymentCount());
GUIUtil::QTableWidgetNumberItem *yesVotesItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetYeas());
GUIUtil::QTableWidgetNumberItem *noVotesItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetNays());
GUIUtil::QTableWidgetNumberItem *abstainVotesItem = new GUIUtil::QTableWidgetNumberItem((int64_t)pbudgetProposal->GetAbstains());
QTableWidgetItem *AddressItem = new QTableWidgetItem(QString::fromStdString(EncodeDestination(address)));
GUIUtil::QTableWidgetNumberItem *totalPaymentItem = new GUIUtil::QTableWidgetNumberItem((pbudgetProposal->GetAmount()*pbudgetProposal->GetTotalPaymentCount())/100000000);
GUIUtil::QTableWidgetNumberItem *monthlyPaymentItem = new GUIUtil::QTableWidgetNumberItem(pbudgetProposal->GetAmount()/100000000);
ui->tableWidgetVoting->insertRow(0);
ui->tableWidgetVoting->setItem(0, 0, nameItem);
ui->tableWidgetVoting->setCellWidget(0, 1, urlItem);
ui->tableWidgetVoting->setItem(0, 2, hashItem);
ui->tableWidgetVoting->setItem(0, 3, blockStartItem);
ui->tableWidgetVoting->setItem(0, 4, blockEndItem);
ui->tableWidgetVoting->setItem(0, 5, paymentsItem);
ui->tableWidgetVoting->setItem(0, 6, remainingPaymentsItem);
ui->tableWidgetVoting->setItem(0, 7, yesVotesItem);
ui->tableWidgetVoting->setItem(0, 8, noVotesItem);
ui->tableWidgetVoting->setItem(0, 9, abstainVotesItem);
ui->tableWidgetVoting->setItem(0, 10, AddressItem);
ui->tableWidgetVoting->setItem(0, 11, totalPaymentItem);
ui->tableWidgetVoting->setItem(0, 12, monthlyPaymentItem);
std::string projected;
if ((int64_t)pbudgetProposal->GetYeas() - (int64_t)pbudgetProposal->GetNays() > (ui->tableWidgetMasternodes->rowCount()/10)){
nTotalAllotted += pbudgetProposal->GetAmount()/100000000;
projected = "Yes";
} else {
projected = "No";
}
QTableWidgetItem *projectedItem = new QTableWidgetItem(QString::fromStdString(projected));
ui->tableWidgetVoting->setItem(0, 13, projectedItem);
}
}
ui->totalAllottedLabel->setText(QString::number(nTotalAllotted));
ui->tableWidgetVoting->setSortingEnabled(true);
// reset "timer"
ui->voteSecondsLabel->setText("0");
}
void MasternodeList::VoteMany(std::string strCommand)
{
std::vector<CNodeEntry> mnEntries;
mnEntries = masternodeConfig.getEntries();
int nVote = VOTE_ABSTAIN;
if(strCommand == "yea") nVote = VOTE_YES;
if(strCommand == "nay") nVote = VOTE_NO;
// Find selected Budget Hash
QItemSelectionModel* selectionModel = ui->tableWidgetVoting->selectionModel();
QModelIndexList selected = selectionModel->selectedRows();
if(selected.count() == 0)
return;
QModelIndex index = selected.at(0);
int r = index.row();
std::string strHash = ui->tableWidgetVoting->item(r, 2)->text().toStdString();
uint256 hash;
hash.SetHex(strHash);
const int blockStart = ui->tableWidgetVoting->item(r, 3)->text().toInt();
const int blockEnd = ui->tableWidgetVoting->item(r, 4)->text().toInt();
if (!budget.CanSubmitVotes(blockStart, blockEnd))
{
QMessageBox::critical(
this,
tr("Voting Details"),
tr(
"Sorry, your vote has not been added to the proposal. "
"The proposal voting is currently disabled as we're too close to the proposal payment."
)
);
return;
}
int success = 0;
int failed = 0;
std::string statusObj;
for (CNodeEntry mne : masternodeConfig.getEntries()) {
std::string errorMessage;
std::vector<unsigned char> vchMasterNodeSignature;
std::string strMasterNodeSignMessage;
CPubKey pubKeyCollateralAddress;
CKey keyCollateralAddress;
CPubKey pubKeyMasternode;
CKey keyMasternode;
if(!legacySigner.SetKey(mne.getPrivKey(), keyMasternode, pubKeyMasternode)){
failed++;
statusObj += "\nFailed to vote with " + mne.getAlias() + ". Masternode signing error, could not set key correctly: " + errorMessage;
continue;
}
CMasternode* pmn = mnodeman.Find(pubKeyMasternode);
if(pmn == NULL)
{
failed++;
statusObj += "\nFailed to vote with " + mne.getAlias() + ". Error: Can't find masternode by pubkey";
continue;
}
CBudgetVote vote(pmn->vin, hash, nVote);
if(!vote.Sign(keyMasternode, pubKeyMasternode)){
failed++;
statusObj += "\nFailed to vote with " + mne.getAlias() + ". Error: Failure to sign";
continue;
}
std::string strError = "";
if(budget.SubmitProposalVote(vote, strError)) {
vote.Relay(*g_rpc_node->connman);
success++;
} else {
failed++;
statusObj += "\nFailed to vote with " + mne.getAlias() + ". Error: " + strError;
}
}
std::string returnObj;
returnObj = strprintf("Voted successfully %d time(s) and failed %d time(s).", success, failed);
if (failed > 0)
returnObj += statusObj;
QMessageBox msg;
msg.setText(QString::fromStdString(returnObj));
msg.setWindowTitle(tr("Voting Details"));
msg.exec();
updateVoteList(true);
}
void MasternodeList::on_voteManyYesButton_clicked()
{
// Display message box
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm vote-many"),
tr("Are you sure you want to vote with ALL of your masternodes?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
if(retval != QMessageBox::Yes)
{
return;
}
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
if(encStatus == walletModel->Locked)
{
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if(!ctx.isValid())
{
// Unlock wallet was cancelled
return;
}
VoteMany("yea");
return;
}
VoteMany("yea");
}
void MasternodeList::on_voteManyNoButton_clicked()
{
// Display message box
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm vote-many"),
tr("Are you sure you want to vote with ALL of your masternodes?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
if(retval != QMessageBox::Yes)
{
return;
}
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
if(encStatus == walletModel->Locked)
{
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if(!ctx.isValid())
{
// Unlock wallet was cancelled
return;
}
VoteMany("nay");
return;
}
VoteMany("nay");
}
void MasternodeList::on_voteManyAbstainButton_clicked()
{
// Display message box
QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm vote-many"),
tr("Are you sure you want to vote with ALL of your masternodes?"),
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Cancel);
if(retval != QMessageBox::Yes)
{
return;
}
WalletModel::EncryptionStatus encStatus = walletModel->getEncryptionStatus();
if(encStatus == walletModel->Locked)
{
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if(!ctx.isValid())
{
// Unlock wallet was cancelled
return;
}
VoteMany("abstain");
return;
}
VoteMany("abstain");
}
void MasternodeList::on_tableWidgetVoting_itemSelectionChanged()
{
if(ui->tableWidgetVoting->selectedItems().count() > 0)
{
ui->voteManyYesButton->setEnabled(true);
ui->voteManyNoButton->setEnabled(true);
}
}