Skip to content

Commit b8b9593

Browse files
committed
Added possibility to POSE-UNBAN fom GUI
1 parent ab5069b commit b8b9593

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

src/qt/pivx/masternodeswidget.cpp

Lines changed: 29 additions & 1 deletion
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();
@@ -223,6 +225,32 @@ void MasterNodesWidget::onEditMNClicked()
223225
bool isEnabled = index.sibling(index.row(), MNModel::IS_POSE_ENABLED).data(Qt::DisplayRole).toBool();
224226
if (isEnabled) {
225227
inform(tr("Cannot start an already started Masternode"));
228+
}else{
229+
uint256 proTxHash =uint256S(index.sibling(index.row(), MNModel::PRO_TX_HASH).data(Qt::DisplayRole).toString().toStdString());
230+
Optional<DMNData> opDMN = interfaces::g_tiertwo->getDMNData(proTxHash,
231+
clientModel->getLastBlockIndexProcessed());
232+
if(!opDMN){
233+
inform(tr("Masternode not found"));
234+
}else{
235+
std::string operatorKeyS = opDMN->operatorSk;
236+
if(operatorKeyS.empty()){
237+
inform("Operator secret key not found");
238+
}else{
239+
Optional<CBLSSecretKey> operator_key = bls::DecodeSecret(Params(),operatorKeyS);
240+
if(operator_key){
241+
std::string error_str = "";
242+
if(!mnModel->unbanDMN(*operator_key,proTxHash,error_str)){
243+
inform(QString::fromStdString(error_str));
244+
}else{
245+
inform("Masternode successfully unbanned! Wait for the next minted block and it will update");
246+
}
247+
}else{
248+
inform("Could not decode operator secret key");
249+
}
250+
}
251+
252+
}
253+
226254
}
227255
}
228256
}

src/qt/pivx/mnmodel.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "bls/key_io.h"
88
#include "coincontrol.h"
9+
#include "evo/deterministicmns.h"
910
#include "interfaces/tiertwo.h"
1011
#include "evo/specialtx_utils.h"
1112
#include "masternode.h"
@@ -417,7 +418,6 @@ CallResult<uint256> MNModel::createDMN(const std::string& alias,
417418
// 2. external.
418419
// 3. fund.
419420

420-
//Either one of them must be non null
421421
auto p_wallet = vpwallets[0]; // TODO: Move to walletModel
422422
const auto& chainparams = Params();
423423

@@ -476,7 +476,45 @@ CallResult<uint256> MNModel::createDMN(const std::string& alias,
476476
// All good
477477
return res;
478478
}
479+
//unban a Pose-banned DMN
480+
bool MNModel::unbanDMN(CBLSSecretKey& operatorKey,uint256 proTxHash, std::string& strError){
481+
ProUpServPL pl;
482+
pl.nVersion = ProUpServPL::CURRENT_VERSION;
483+
pl.proTxHash = proTxHash;
484+
auto dmn = deterministicMNManager->GetListAtChainTip().GetMN(pl.proTxHash); //make sure that the wallet is synced first?
485+
if (!dmn) {
486+
strError = "Masternode not found";
487+
return false;
488+
}
489+
if(!dmn->IsPoSeBanned()){
490+
strError = "Masternode is not Pose-banned";
491+
return false;
492+
}
493+
pl.addr = dmn->pdmnState->addr;
494+
pl.scriptOperatorPayout = dmn->pdmnState->scriptOperatorPayout;
479495

496+
CMutableTransaction tx;
497+
tx.nVersion = CTransaction::TxVersion::SAPLING;
498+
tx.nType = CTransaction::TxType::PROUPSERV;
499+
500+
auto wallet = vpwallets[0]; // TODO: Move to walletModel
501+
auto res = FundSpecialTx(wallet, tx, pl);
502+
if(!res){
503+
strError = res.getError();
504+
return false;
505+
}
506+
res = SignSpecialTxPayloadByHash(tx, pl, operatorKey);
507+
if(!res){
508+
strError = res.getError();
509+
return false;
510+
}
511+
res = SignAndSendSpecialTx(wallet, tx, pl);
512+
if(!res){
513+
strError = res.getError();
514+
return false;
515+
}
516+
return true;
517+
}
480518
OperationResult MNModel::killDMN(const uint256& collateralHash, unsigned int outIndex)
481519
{
482520
auto p_wallet = vpwallets[0]; // TODO: Move to walletModel

src/qt/pivx/mnmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "operationresult.h"
1212
#include "primitives/transaction.h"
1313
#include "bls/key_io.h"
14+
#include "uint256.h"
1415
#include "wallet/wallet.h" // TODO: Move to walletModel
1516

1617
class CMasternode;
@@ -128,6 +129,8 @@ class MNModel : public QAbstractTableModel
128129
OperationResult killDMN(const uint256& collateralHash, unsigned int outIndex);
129130

130131

132+
//Unban a Pose-banned DMN
133+
bool unbanDMN(CBLSSecretKey& operatorKey,uint256 proTxHash, std::string& strError);
131134
// Generates the collateral transaction
132135
bool createDMNExternalCollateral(const QString& alias, const QString& addr, COutPoint& ret_outpoint, QString& ret_error);
133136
bool createDMNInternalCollateral(const QString& alias, const QString& addr, CTransactionRef& ret_tx,COutPoint& ret_outpoint, QString& ret_error,int nExtraSize=0);

0 commit comments

Comments
 (0)