Skip to content

Commit

Permalink
Added possibility to POSE-UNBAN fom GUI
Browse files Browse the repository at this point in the history
Fix lint



Fix CMake

Remove GetMNCollateralCandidate
  • Loading branch information
Liquid369 committed Apr 28, 2023
1 parent ab5069b commit 20c5455
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 157 deletions.
1 change: 1 addition & 0 deletions src/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ SET(QT_SOURCES
)

qt5_generate_moc(pivx/pfborderimage.h ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_pfborderimage.cpp)
qt5_generate_moc(pivx/clickablelabel.h ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_clickablelabel.cpp)
list(APPEND QT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_pfborderimage.cpp)
list(APPEND QT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/pivx/moc_clickablelabel.cpp)

Expand Down
35 changes: 31 additions & 4 deletions src/qt/pivx/masternodeswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "qt/pivx/masternodeswidget.h"
#include "bls/bls_wrapper.h"
#include "qt/pivx/forms/ui_masternodeswidget.h"

#include "qt/pivx/defaultdialog.h"
Expand All @@ -17,6 +18,7 @@
#include "qt/pivx/mnmodel.h"
#include "qt/pivx/optionbutton.h"
#include "qt/walletmodel.h"
#include "uint256.h"

#define DECORATION_SIZE 65
#define NUM_ITEMS 3
Expand Down Expand Up @@ -166,7 +168,7 @@ void MasterNodesWidget::onMNClicked(const QModelIndex& _index)
if (!menu) {
menu = new TooltipMenu(window, this);
connect(menu, &TooltipMenu::message, this, &AddressesWidget::message);
menu->addBtn(0, tr("Start"), [this](){onEditMNClicked();});
menu->addBtn(0, tr("Start"), [this](){onEditMNClicked();}); //TODO: change to UNBAN once 6.0 is out
menu->addBtn(1, tr("Delete"), [this](){onDeleteMNClicked();});
menu->addBtn(2, tr("Info"), [this](){onInfoMNClicked();});
menu->adjustSize();
Expand Down Expand Up @@ -214,15 +216,40 @@ void MasterNodesWidget::onEditMNClicked()
}
} else {
inform(tr(
"Cannot start masternode, the collateral transaction has not been confirmed by the network yet.\n"
"Please wait few more minutes (masternode collaterals require %1 confirmations).").arg(
mnModel->getMasternodeCollateralMinConf()));
"Cannot start masternode, the collateral transaction has not been confirmed by the network yet.\n"
"Please wait few more minutes (masternode collaterals require %1 confirmations).")
.arg(
mnModel->getMasternodeCollateralMinConf()));
}
} else {
// Deterministic
bool isEnabled = index.sibling(index.row(), MNModel::IS_POSE_ENABLED).data(Qt::DisplayRole).toBool();
if (isEnabled) {
inform(tr("Cannot start an already started Masternode"));
} else {
uint256 proTxHash = uint256S(index.sibling(index.row(), MNModel::PRO_TX_HASH).data(Qt::DisplayRole).toString().toStdString());
Optional<DMNData> opDMN = interfaces::g_tiertwo->getDMNData(proTxHash,
clientModel->getLastBlockIndexProcessed());
if (!opDMN) {
inform(tr("Masternode not found"));
} else {
std::string operatorKeyS = opDMN->operatorSk;
if (operatorKeyS.empty()) {
inform("Operator secret key not found");
} else {
Optional<CBLSSecretKey> operator_key = bls::DecodeSecret(Params(), operatorKeyS);
if (operator_key) {
std::string error_str = "";
if (!mnModel->unbanDMN(*operator_key, proTxHash, error_str)) {
inform(QString::fromStdString(error_str));
} else {
inform("Masternode successfully unbanned! Wait for the next minted block and it will update");
}
} else {
inform("Could not decode operator secret key");
}
}
}
}
}
}
Expand Down
83 changes: 32 additions & 51 deletions src/qt/pivx/masternodewizarddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "qt/pivx/masternodewizarddialog.h"
#include "optional.h"
#include "primitives/transaction.h"
#include "qt/pivx/forms/ui_masternodewizarddialog.h"

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

// Look for a valid collateral utxo
COutPoint collateralOut;

if (!walletModel->getMNCollateralCandidate(collateralOut)) {
// New receive address
auto r = walletModel->getNewAddress(alias);
if (!r) return errorOut(tr(r.getError().c_str()));
if (!mnModel->createMNCollateral(addressLabel,
QString::fromStdString(r.getObjResult()->ToString()),
collateralOut,
returnStr)) {
// error str set internally
return false;
}
}

if (isDeterministic) {
auto opOwnerAddrAndKeyId = getOrCreateOwnerAddress(alias);
if (!opOwnerAddrAndKeyId.getRes()) {
Expand All @@ -447,7 +429,7 @@ bool MasterNodeWizardDialog::createMN()
// 3) Get operator data
QString operatorKey = ui->lineEditOperatorKey->text();
Optional<CKeyID> operatorPayoutKeyId = walletModel->getKeyIDFromAddr(ui->lineEditOperatorPayoutAddress->text().toStdString());
double operatorPercentage = ui->lineEditPercentage->text().isEmpty() ? 0 : (double) ui->lineEditPercentage->text().toDouble();
double operatorPercentage = ui->lineEditPercentage->text().isEmpty() ? 0 : (double)ui->lineEditPercentage->text().toDouble();

// 4) Get voter data
Optional<CKeyID> votingAddr;
Expand All @@ -463,32 +445,32 @@ bool MasterNodeWizardDialog::createMN()
votingAddr = ownerKeyId;
}

Optional<COutPoint> collateralOut = COutPoint();
Optional<COutPoint> collateralOut = COutPoint();
bool foundCandidate = false;
if(!walletModel->getMNCollateralCandidate(*collateralOut)){
collateralOut= nullopt;
}else{
//We have to lock the collateral or the system could spend it
if (!walletModel->getMNCollateralCandidate(*collateralOut)) {
collateralOut = nullopt;
} else {
// We have to lock the collateral or the system could spend it
walletModel->lockCoin(*collateralOut);
foundCandidate = true;
}
std::string error_str;

auto res = mnModel->createDMN(alias,
collateralOut,
addressLabel,
ipAddress,
port,
ownerKeyId,
operatorKey.isEmpty() ? nullopt : Optional<std::string>(operatorKey.toStdString()),
votingAddr,
payoutKeyId,
error_str,
(uint16_t) operatorPercentage * 100, // operator percentage
operatorPayoutKeyId); // operator payout script
collateralOut,
addressLabel,
ipAddress,
port,
ownerKeyId,
operatorKey.isEmpty() ? nullopt : Optional<std::string>(operatorKey.toStdString()),
votingAddr,
payoutKeyId,
error_str,
(uint16_t)operatorPercentage * 100, // operator percentage
operatorPayoutKeyId); // operator payout script
if (!res) {
//unlock in case of error
if(foundCandidate){
// unlock in case of error
if (foundCandidate) {
walletModel->unlockCoin(*collateralOut);
}
return errorOut(tr(error_str.c_str()));
Expand All @@ -497,18 +479,17 @@ bool MasterNodeWizardDialog::createMN()
// future: move "operatorSk" to a constant field
std::string operatorSk = walletModel->getStrFromTxExtraData(*res.getObjResult(), "operatorSk");
mnSummary = std::make_unique<MNSummary>(alias,
ipAddress+":"+port,
collateralOut?*collateralOut:COutPoint(UINT256_ZERO,0), //TODO: the outpoint index is not 0 in general, but it does not matter (just display)
ownerAddrStr,
payoutAddrStr,
operatorSk.empty() ? operatorKey.toStdString() : operatorSk,
ownerAddrStr, // voting key, for now fixed to owner addr
0, // operator percentage
nullopt); // operator payout
ipAddress + ":" + port,
collateralOut ? *collateralOut : COutPoint(UINT256_ZERO, 0), // TODO: the outpoint index is not 0 in general, but it does not matter (just display)
ownerAddrStr,
payoutAddrStr,
operatorSk.empty() ? operatorKey.toStdString() : operatorSk,
ownerAddrStr, // voting key, for now fixed to owner addr
0, // operator percentage
nullopt); // operator payout

returnStr = tr("Deterministic Masternode created! It will appear on your list on the next mined block!");
} else {

// Legacy
// Look for a valid collateral utxo
COutPoint collateralOut;
Expand All @@ -517,10 +498,10 @@ bool MasterNodeWizardDialog::createMN()
// New receive address
auto r = walletModel->getNewAddress(alias);
if (!r) return errorOut(tr(r.getError().c_str()));
if (!mnModel->createDMNExternalCollateral(addressLabel,
QString::fromStdString(r.getObjResult()->ToString()),
collateralOut,
returnStr)) {
if (!mnModel->createDMNExternalCollateral(addressLabel,
QString::fromStdString(r.getObjResult()->ToString()),
collateralOut,
returnStr)) {
// error str set internally
return false;
}
Expand Down
Loading

0 comments on commit 20c5455

Please sign in to comment.