Skip to content

Commit beb1cf6

Browse files
committed
[Refactoring][GUI] remove pwalletMain direct access in mnmodel
1 parent 4ca5a2a commit beb1cf6

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

src/qt/pivx/masternodeswidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ MasterNodesWidget::MasterNodesWidget(PIVXGUI *parent) :
7777
new MNHolder(isLightTheme()),
7878
this
7979
);
80-
mnModel = new MNModel(this);
80+
mnModel = new MNModel(this, walletModel);
8181

8282
this->setStyleSheet(parent->styleSheet());
8383

src/qt/pivx/mnmodel.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "uint256.h"
1313
#include "wallet/wallet.h"
1414

15-
MNModel::MNModel(QObject *parent) : QAbstractTableModel(parent)
15+
MNModel::MNModel(QObject *parent, WalletModel* _model) :
16+
QAbstractTableModel(parent),
17+
walletModel(_model)
1618
{
1719
updateMNList();
1820
}
@@ -34,11 +36,8 @@ void MNModel::updateMNList()
3436
pmn->vin = txIn;
3537
}
3638
nodes.insert(QString::fromStdString(mne.getAlias()), std::make_pair(QString::fromStdString(mne.getIp()), pmn));
37-
if (pwalletMain) {
38-
const CWalletTx *walletTx = pwalletMain->GetWalletTx(txHash);
39-
bool txAccepted = walletTx &&
40-
WITH_LOCK(pwalletMain->cs_wallet, return walletTx->GetDepthInMainChain()) >= MasternodeCollateralMinConf();
41-
collateralTxAccepted.insert(mne.getTxHash(), txAccepted);
39+
if (walletModel) {
40+
collateralTxAccepted.insert(mne.getTxHash(), walletModel->getWalletTxDepth(txHash) >= MasternodeCollateralMinConf());
4241
}
4342
}
4443
Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(end, 5, QModelIndex()) );
@@ -109,9 +108,8 @@ QVariant MNModel::data(const QModelIndex &index, int role) const
109108
case WAS_COLLATERAL_ACCEPTED:{
110109
if (!isAvailable) return false;
111110
std::string txHash = rec->vin.prevout.hash.GetHex();
112-
if (!collateralTxAccepted.value(txHash)) {
113-
const CWalletTx *walletTx = pwalletMain->GetWalletTx(rec->vin.prevout.hash);
114-
return walletTx && WITH_LOCK(pwalletMain->cs_wallet, return walletTx->GetDepthInMainChain()) > 0;
111+
if (!collateralTxAccepted.value(txHash) && walletModel) {
112+
return walletModel->getWalletTxDepth(rec->vin.prevout.hash) > 0;
115113
}
116114
return true;
117115
}

src/qt/pivx/mnmodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
#include <QAbstractTableModel>
99
#include "masternode.h"
1010
#include "masternodeconfig.h"
11+
#include "qt/walletmodel.h"
1112

1213
class MNModel : public QAbstractTableModel
1314
{
1415
Q_OBJECT
1516

1617
public:
17-
explicit MNModel(QObject *parent = nullptr);
18+
explicit MNModel(QObject *parent, WalletModel* _model);
1819
~MNModel() override {
1920
nodes.clear();
2021
collateralTxAccepted.clear();
@@ -56,6 +57,7 @@ class MNModel : public QAbstractTableModel
5657

5758

5859
private:
60+
WalletModel* walletModel;
5961
// alias mn node ---> pair <ip, master node>
6062
QMap<QString, std::pair<QString, CMasternode*>> nodes;
6163
QMap<std::string, bool> collateralTxAccepted;

src/qt/walletmodel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,17 @@ bool WalletModel::getMNCollateralCandidate(COutPoint& outPoint)
10201020
return false;
10211021
}
10221022

1023+
// Depth of a wallet transaction or -1 if not found
1024+
int WalletModel::getWalletTxDepth(const uint256& txHash) const
1025+
{
1026+
const CWalletTx *walletTx = wallet->GetWalletTx(txHash);
1027+
if (!walletTx) {
1028+
return -1;
1029+
}
1030+
LOCK(wallet->cs_wallet);
1031+
return walletTx->GetDepthInMainChain();
1032+
}
1033+
10231034
bool WalletModel::isSpent(const COutPoint& outpoint) const
10241035
{
10251036
LOCK(wallet->cs_wallet);

src/qt/walletmodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ class WalletModel : public QObject
295295
bool IsShieldedDestination(const CWDestination& address);
296296
bool isUsed(CTxDestination address);
297297
bool getMNCollateralCandidate(COutPoint& outPoint);
298+
// Depth of a wallet transaction or -1 if not found
299+
int getWalletTxDepth(const uint256& txHash) const;
298300
bool isSpent(const COutPoint& outpoint) const;
299301

300302
class ListCoinsKey {

0 commit comments

Comments
 (0)