Skip to content

Commit 20c5455

Browse files
committed
Added possibility to POSE-UNBAN fom GUI
Fix lint Fix CMake Remove GetMNCollateralCandidate
1 parent ab5069b commit 20c5455

File tree

5 files changed

+205
-157
lines changed

5 files changed

+205
-157
lines changed

src/qt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ SET(QT_SOURCES
159159
)
160160

161161
qt5_generate_moc(pivx/pfborderimage.h ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_pfborderimage.cpp)
162+
qt5_generate_moc(pivx/clickablelabel.h ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_clickablelabel.cpp)
162163
list(APPEND QT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_pfborderimage.cpp)
163164
list(APPEND QT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_clickablelabel.cpp)
164165

src/qt/pivx/masternodeswidget.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "qt/pivx/masternodeswidget.h"
6+
#include "bls/bls_wrapper.h"
67
#include "qt/pivx/forms/ui_masternodeswidget.h"
78

89
#include "qt/pivx/defaultdialog.h"
@@ -17,6 +18,7 @@
1718
#include "qt/pivx/mnmodel.h"
1819
#include "qt/pivx/optionbutton.h"
1920
#include "qt/walletmodel.h"
21+
#include "uint256.h"
2022

2123
#define DECORATION_SIZE 65
2224
#define NUM_ITEMS 3
@@ -166,7 +168,7 @@ void MasterNodesWidget::onMNClicked(const QModelIndex& _index)
166168
if (!menu) {
167169
menu = new TooltipMenu(window, this);
168170
connect(menu, &TooltipMenu::message, this, &AddressesWidget::message);
169-
menu->addBtn(0, tr("Start"), [this](){onEditMNClicked();});
171+
menu->addBtn(0, tr("Start"), [this](){onEditMNClicked();}); //TODO: change to UNBAN once 6.0 is out
170172
menu->addBtn(1, tr("Delete"), [this](){onDeleteMNClicked();});
171173
menu->addBtn(2, tr("Info"), [this](){onInfoMNClicked();});
172174
menu->adjustSize();
@@ -214,15 +216,40 @@ void MasterNodesWidget::onEditMNClicked()
214216
}
215217
} else {
216218
inform(tr(
217-
"Cannot start masternode, the collateral transaction has not been confirmed by the network yet.\n"
218-
"Please wait few more minutes (masternode collaterals require %1 confirmations).").arg(
219-
mnModel->getMasternodeCollateralMinConf()));
219+
"Cannot start masternode, the collateral transaction has not been confirmed by the network yet.\n"
220+
"Please wait few more minutes (masternode collaterals require %1 confirmations).")
221+
.arg(
222+
mnModel->getMasternodeCollateralMinConf()));
220223
}
221224
} else {
222225
// Deterministic
223226
bool isEnabled = index.sibling(index.row(), MNModel::IS_POSE_ENABLED).data(Qt::DisplayRole).toBool();
224227
if (isEnabled) {
225228
inform(tr("Cannot start an already started Masternode"));
229+
} else {
230+
uint256 proTxHash = uint256S(index.sibling(index.row(), MNModel::PRO_TX_HASH).data(Qt::DisplayRole).toString().toStdString());
231+
Optional<DMNData> opDMN = interfaces::g_tiertwo->getDMNData(proTxHash,
232+
clientModel->getLastBlockIndexProcessed());
233+
if (!opDMN) {
234+
inform(tr("Masternode not found"));
235+
} else {
236+
std::string operatorKeyS = opDMN->operatorSk;
237+
if (operatorKeyS.empty()) {
238+
inform("Operator secret key not found");
239+
} else {
240+
Optional<CBLSSecretKey> operator_key = bls::DecodeSecret(Params(), operatorKeyS);
241+
if (operator_key) {
242+
std::string error_str = "";
243+
if (!mnModel->unbanDMN(*operator_key, proTxHash, error_str)) {
244+
inform(QString::fromStdString(error_str));
245+
} else {
246+
inform("Masternode successfully unbanned! Wait for the next minted block and it will update");
247+
}
248+
} else {
249+
inform("Could not decode operator secret key");
250+
}
251+
}
252+
}
226253
}
227254
}
228255
}

src/qt/pivx/masternodewizarddialog.cpp

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include "qt/pivx/masternodewizarddialog.h"
6-
#include "optional.h"
7-
#include "primitives/transaction.h"
86
#include "qt/pivx/forms/ui_masternodewizarddialog.h"
97

108
#include "key_io.h"
@@ -410,22 +408,6 @@ bool MasterNodeWizardDialog::createMN()
410408
std::string ipAddress = addressStr.toStdString();
411409
std::string port = portStr.toStdString();
412410

413-
// Look for a valid collateral utxo
414-
COutPoint collateralOut;
415-
416-
if (!walletModel->getMNCollateralCandidate(collateralOut)) {
417-
// New receive address
418-
auto r = walletModel->getNewAddress(alias);
419-
if (!r) return errorOut(tr(r.getError().c_str()));
420-
if (!mnModel->createMNCollateral(addressLabel,
421-
QString::fromStdString(r.getObjResult()->ToString()),
422-
collateralOut,
423-
returnStr)) {
424-
// error str set internally
425-
return false;
426-
}
427-
}
428-
429411
if (isDeterministic) {
430412
auto opOwnerAddrAndKeyId = getOrCreateOwnerAddress(alias);
431413
if (!opOwnerAddrAndKeyId.getRes()) {
@@ -447,7 +429,7 @@ bool MasterNodeWizardDialog::createMN()
447429
// 3) Get operator data
448430
QString operatorKey = ui->lineEditOperatorKey->text();
449431
Optional<CKeyID> operatorPayoutKeyId = walletModel->getKeyIDFromAddr(ui->lineEditOperatorPayoutAddress->text().toStdString());
450-
double operatorPercentage = ui->lineEditPercentage->text().isEmpty() ? 0 : (double) ui->lineEditPercentage->text().toDouble();
432+
double operatorPercentage = ui->lineEditPercentage->text().isEmpty() ? 0 : (double)ui->lineEditPercentage->text().toDouble();
451433

452434
// 4) Get voter data
453435
Optional<CKeyID> votingAddr;
@@ -463,32 +445,32 @@ bool MasterNodeWizardDialog::createMN()
463445
votingAddr = ownerKeyId;
464446
}
465447

466-
Optional<COutPoint> collateralOut = COutPoint();
448+
Optional<COutPoint> collateralOut = COutPoint();
467449
bool foundCandidate = false;
468-
if(!walletModel->getMNCollateralCandidate(*collateralOut)){
469-
collateralOut= nullopt;
470-
}else{
471-
//We have to lock the collateral or the system could spend it
450+
if (!walletModel->getMNCollateralCandidate(*collateralOut)) {
451+
collateralOut = nullopt;
452+
} else {
453+
// We have to lock the collateral or the system could spend it
472454
walletModel->lockCoin(*collateralOut);
473455
foundCandidate = true;
474456
}
475457
std::string error_str;
476-
458+
477459
auto res = mnModel->createDMN(alias,
478-
collateralOut,
479-
addressLabel,
480-
ipAddress,
481-
port,
482-
ownerKeyId,
483-
operatorKey.isEmpty() ? nullopt : Optional<std::string>(operatorKey.toStdString()),
484-
votingAddr,
485-
payoutKeyId,
486-
error_str,
487-
(uint16_t) operatorPercentage * 100, // operator percentage
488-
operatorPayoutKeyId); // operator payout script
460+
collateralOut,
461+
addressLabel,
462+
ipAddress,
463+
port,
464+
ownerKeyId,
465+
operatorKey.isEmpty() ? nullopt : Optional<std::string>(operatorKey.toStdString()),
466+
votingAddr,
467+
payoutKeyId,
468+
error_str,
469+
(uint16_t)operatorPercentage * 100, // operator percentage
470+
operatorPayoutKeyId); // operator payout script
489471
if (!res) {
490-
//unlock in case of error
491-
if(foundCandidate){
472+
// unlock in case of error
473+
if (foundCandidate) {
492474
walletModel->unlockCoin(*collateralOut);
493475
}
494476
return errorOut(tr(error_str.c_str()));
@@ -497,18 +479,17 @@ bool MasterNodeWizardDialog::createMN()
497479
// future: move "operatorSk" to a constant field
498480
std::string operatorSk = walletModel->getStrFromTxExtraData(*res.getObjResult(), "operatorSk");
499481
mnSummary = std::make_unique<MNSummary>(alias,
500-
ipAddress+":"+port,
501-
collateralOut?*collateralOut:COutPoint(UINT256_ZERO,0), //TODO: the outpoint index is not 0 in general, but it does not matter (just display)
502-
ownerAddrStr,
503-
payoutAddrStr,
504-
operatorSk.empty() ? operatorKey.toStdString() : operatorSk,
505-
ownerAddrStr, // voting key, for now fixed to owner addr
506-
0, // operator percentage
507-
nullopt); // operator payout
482+
ipAddress + ":" + port,
483+
collateralOut ? *collateralOut : COutPoint(UINT256_ZERO, 0), // TODO: the outpoint index is not 0 in general, but it does not matter (just display)
484+
ownerAddrStr,
485+
payoutAddrStr,
486+
operatorSk.empty() ? operatorKey.toStdString() : operatorSk,
487+
ownerAddrStr, // voting key, for now fixed to owner addr
488+
0, // operator percentage
489+
nullopt); // operator payout
508490

509491
returnStr = tr("Deterministic Masternode created! It will appear on your list on the next mined block!");
510492
} else {
511-
512493
// Legacy
513494
// Look for a valid collateral utxo
514495
COutPoint collateralOut;
@@ -517,10 +498,10 @@ bool MasterNodeWizardDialog::createMN()
517498
// New receive address
518499
auto r = walletModel->getNewAddress(alias);
519500
if (!r) return errorOut(tr(r.getError().c_str()));
520-
if (!mnModel->createDMNExternalCollateral(addressLabel,
521-
QString::fromStdString(r.getObjResult()->ToString()),
522-
collateralOut,
523-
returnStr)) {
501+
if (!mnModel->createDMNExternalCollateral(addressLabel,
502+
QString::fromStdString(r.getObjResult()->ToString()),
503+
collateralOut,
504+
returnStr)) {
524505
// error str set internally
525506
return false;
526507
}

0 commit comments

Comments
 (0)