Skip to content

Commit 7fd30b5

Browse files
UdjinM6PastaPastaPasta
authored andcommitted
refactor: use coinjoin interfaces in qt
1 parent 60240b1 commit 7fd30b5

File tree

7 files changed

+40
-20
lines changed

7 files changed

+40
-20
lines changed

src/interfaces/node.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct NodeContext;
3939
namespace interfaces {
4040
class Handler;
4141
class WalletLoader;
42+
namespace CoinJoin {
43+
class Loader;
44+
} //namespsace CoinJoin
4245
struct BlockTip;
4346

4447
//! Interface for the src/evo part of a dash node (dashd process).
@@ -303,6 +306,9 @@ class Node
303306
//! Return interface for accessing coinjoin related handler.
304307
virtual CoinJoin::Options& coinJoinOptions() = 0;
305308

309+
//! Return interface for accessing coinjoin loader handler.
310+
virtual std::unique_ptr<interfaces::CoinJoin::Loader>& coinJoinLoader() = 0;
311+
306312
//! Register handler for init messages.
307313
using InitMessageFn = std::function<void(const std::string& message)>;
308314
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;

src/node/interfaces.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <governance/object.h>
1616
#include <init.h>
1717
#include <interfaces/chain.h>
18+
#include <interfaces/coinjoin.h>
1819
#include <interfaces/handler.h>
1920
#include <interfaces/wallet.h>
2021
#include <llmq/chainlocks.h>
@@ -451,6 +452,7 @@ class NodeImpl : public Node
451452
LLMQ& llmq() override { return m_llmq; }
452453
Masternode::Sync& masternodeSync() override { return m_masternodeSync; }
453454
CoinJoin::Options& coinJoinOptions() override { return m_coinjoin; }
455+
std::unique_ptr<interfaces::CoinJoin::Loader>& coinJoinLoader() override { return m_context->coinjoin_loader; }
454456

455457
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
456458
{

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <functional>
3434
#include <chain.h>
3535
#include <chainparams.h>
36+
#include <interfaces/coinjoin.h>
3637
#include <interfaces/handler.h>
3738
#include <interfaces/node.h>
3839
#include <qt/governancelist.h>
@@ -1379,7 +1380,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, const QStri
13791380
#ifdef ENABLE_WALLET
13801381
if (enableWallet) {
13811382
for (const auto& wallet : m_node.walletLoader().getWallets()) {
1382-
disableAppNap |= wallet->coinJoin().isMixing();
1383+
disableAppNap |= m_node.coinJoinLoader()->GetClient(wallet->getWalletName())->isMixing();
13831384
}
13841385
}
13851386
#endif // ENABLE_WALLET

src/qt/optionsdialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <qt/guiutil.h>
1616
#include <qt/optionsmodel.h>
1717

18+
#include <interfaces/coinjoin.h>
1819
#include <interfaces/node.h>
1920
#include <interfaces/wallet.h>
2021
#include <validation.h> // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS
@@ -411,7 +412,7 @@ void OptionsDialog::on_okButton_clicked()
411412
#ifdef ENABLE_WALLET
412413
if (m_enable_wallet) {
413414
for (auto& wallet : model->node().walletLoader().getWallets()) {
414-
wallet->coinJoin().resetCachedBlocks();
415+
model->node().coinJoinLoader()->GetClient(wallet->getWalletName())->resetCachedBlocks();
415416
wallet->markDirty();
416417
}
417418
}

src/qt/overviewpage.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <qt/walletmodel.h>
1717

1818
#include <coinjoin/options.h>
19+
#include <interfaces/coinjoin.h>
1920

2021
#include <cmath>
2122

@@ -306,7 +307,7 @@ void OverviewPage::setWalletModel(WalletModel *model)
306307

307308
// Disable coinJoinClient builtin support for automatic backups while we are in GUI,
308309
// we'll handle automatic backups and user warnings in coinJoinStatus()
309-
walletModel->coinJoin().disableAutobackups();
310+
walletModel->coinJoin()->disableAutobackups();
310311

311312
connect(ui->toggleCoinJoin, &QPushButton::clicked, this, &OverviewPage::toggleCoinJoin);
312313

@@ -523,7 +524,7 @@ void OverviewPage::coinJoinStatus(bool fForce)
523524
int nBestHeight = clientModel->node().getNumBlocks();
524525

525526
// We are processing more than 1 block per second, we'll just leave
526-
if (nBestHeight > walletModel->coinJoin().getCachedBlocks() && GetTime() - nLastDSProgressBlockTime <= 1) return;
527+
if (nBestHeight > walletModel->coinJoin()->getCachedBlocks() && GetTime() - nLastDSProgressBlockTime <= 1) return;
527528
nLastDSProgressBlockTime = GetTime();
528529

529530
QString strKeysLeftText(tr("keys left: %1").arg(walletModel->getKeysLeftSinceAutoBackup()));
@@ -533,9 +534,9 @@ void OverviewPage::coinJoinStatus(bool fForce)
533534
ui->labelCoinJoinEnabled->setToolTip(strKeysLeftText);
534535

535536
QString strCoinJoinName = QString::fromStdString(gCoinJoinName);
536-
if (!walletModel->coinJoin().isMixing()) {
537-
if (nBestHeight != walletModel->coinJoin().getCachedBlocks()) {
538-
walletModel->coinJoin().setCachedBlocks(nBestHeight);
537+
if (!walletModel->coinJoin()->isMixing()) {
538+
if (nBestHeight != walletModel->coinJoin()->getCachedBlocks()) {
539+
walletModel->coinJoin()->setCachedBlocks(nBestHeight);
539540
updateCoinJoinProgress();
540541
}
541542

@@ -596,7 +597,7 @@ void OverviewPage::coinJoinStatus(bool fForce)
596597
}
597598
}
598599

599-
QString strEnabled = walletModel->coinJoin().isMixing() ? tr("Enabled") : tr("Disabled");
600+
QString strEnabled = walletModel->coinJoin()->isMixing() ? tr("Enabled") : tr("Disabled");
600601
// Show how many keys left in advanced PS UI mode only
601602
if(fShowAdvancedCJUI) strEnabled += ", " + strKeysLeftText;
602603
ui->labelCoinJoinEnabled->setText(strEnabled);
@@ -618,15 +619,15 @@ void OverviewPage::coinJoinStatus(bool fForce)
618619
}
619620

620621
// check coinjoin status and unlock if needed
621-
if(nBestHeight != walletModel->coinJoin().getCachedBlocks()) {
622+
if(nBestHeight != walletModel->coinJoin()->getCachedBlocks()) {
622623
// Balance and number of transactions might have changed
623-
walletModel->coinJoin().setCachedBlocks(nBestHeight);
624+
walletModel->coinJoin()->setCachedBlocks(nBestHeight);
624625
updateCoinJoinProgress();
625626
}
626627

627628
setWidgetsVisible(true);
628629

629-
ui->labelSubmittedDenom->setText(QString(walletModel->coinJoin().getSessionDenoms().c_str()));
630+
ui->labelSubmittedDenom->setText(QString(walletModel->coinJoin()->getSessionDenoms().c_str()));
630631
}
631632

632633
void OverviewPage::toggleCoinJoin(){
@@ -641,7 +642,7 @@ void OverviewPage::toggleCoinJoin(){
641642
settings.setValue("hasMixed", "hasMixed");
642643
}
643644

644-
if (!walletModel->coinJoin().isMixing()) {
645+
if (!walletModel->coinJoin()->isMixing()) {
645646
auto& options = walletModel->node().coinJoinOptions();
646647
const CAmount nMinAmount = options.getSmallestDenomination() + options.getMaxCollateralAmount();
647648
if(m_balances.balance < nMinAmount) {
@@ -659,7 +660,7 @@ void OverviewPage::toggleCoinJoin(){
659660
if(!ctx.isValid())
660661
{
661662
//unlock was cancelled
662-
walletModel->coinJoin().resetCachedBlocks();
663+
walletModel->coinJoin()->resetCachedBlocks();
663664
QMessageBox::warning(this, strCoinJoinName,
664665
tr("Wallet is locked and user declined to unlock. Disabling %1.").arg(strCoinJoinName),
665666
QMessageBox::Ok, QMessageBox::Ok);
@@ -670,15 +671,15 @@ void OverviewPage::toggleCoinJoin(){
670671

671672
}
672673

673-
walletModel->coinJoin().resetCachedBlocks();
674+
walletModel->coinJoin()->resetCachedBlocks();
674675

675-
if (walletModel->coinJoin().isMixing()) {
676+
if (walletModel->coinJoin()->isMixing()) {
676677
ui->toggleCoinJoin->setText(tr("Start %1").arg(strCoinJoinName));
677-
walletModel->coinJoin().resetPool();
678-
walletModel->coinJoin().stopMixing();
678+
walletModel->coinJoin()->resetPool();
679+
walletModel->coinJoin()->stopMixing();
679680
} else {
680681
ui->toggleCoinJoin->setText(tr("Stop %1").arg(strCoinJoinName));
681-
walletModel->coinJoin().startMixing();
682+
walletModel->coinJoin()->startMixing();
682683
}
683684
}
684685

@@ -718,5 +719,5 @@ void OverviewPage::DisableCoinJoinCompletely()
718719
if (nWalletBackups <= 0) {
719720
ui->labelCoinJoinEnabled->setText("<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>(" + tr("Disabled") + ")</span>");
720721
}
721-
walletModel->coinJoin().stopMixing();
722+
walletModel->coinJoin()->stopMixing();
722723
}

src/qt/walletmodel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <qt/recentrequeststablemodel.h>
1818
#include <qt/transactiontablemodel.h>
1919

20+
#include <interfaces/coinjoin.h>
2021
#include <interfaces/handler.h>
2122
#include <interfaces/node.h>
2223
#include <key_io.h>
@@ -77,6 +78,11 @@ void WalletModel::setClientModel(ClientModel* client_model)
7778
if (!m_client_model) timer->stop();
7879
}
7980

81+
std::unique_ptr<interfaces::CoinJoin::Client> WalletModel::coinJoin() const
82+
{
83+
return m_node.coinJoinLoader()->GetClient(m_wallet->getWalletName());
84+
}
85+
8086
void WalletModel::updateStatus()
8187
{
8288
EncryptionStatus newEncryptionStatus = getEncryptionStatus();

src/qt/walletmodel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class uint256;
3838

3939
namespace interfaces {
4040
class Node;
41+
namespace CoinJoin {
42+
class Client;
43+
} // namespace CoinJoin
4144
} // namespace interfaces
4245

4346
QT_BEGIN_NAMESPACE
@@ -151,7 +154,7 @@ class WalletModel : public QObject
151154
interfaces::Node& node() const { return m_node; }
152155
interfaces::Wallet& wallet() const { return *m_wallet; }
153156
void setClientModel(ClientModel* client_model);
154-
interfaces::CoinJoin::Client& coinJoin() const { return m_wallet->coinJoin(); }
157+
std::unique_ptr<interfaces::CoinJoin::Client> coinJoin() const;
155158

156159
QString getWalletName() const;
157160
QString getDisplayName() const;

0 commit comments

Comments
 (0)