diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 93aa556bed..f837fdbd45 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -39,6 +39,9 @@ struct NodeContext; namespace interfaces { class Handler; class WalletLoader; +namespace CoinJoin { +class Loader; +} //namespsace CoinJoin struct BlockTip; //! Interface for the src/evo part of a dash node (dashd process). @@ -303,6 +306,9 @@ public: //! Return interface for accessing coinjoin related handler. virtual CoinJoin::Options& coinJoinOptions() = 0; + //! Return interface for accessing coinjoin loader handler. + virtual std::unique_ptr& coinJoinLoader() = 0; + //! Register handler for init messages. using InitMessageFn = std::function; virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 29c3a510d7..41447b2ed4 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -451,6 +452,7 @@ public: LLMQ& llmq() override { return m_llmq; } Masternode::Sync& masternodeSync() override { return m_masternodeSync; } CoinJoin::Options& coinJoinOptions() override { return m_coinjoin; } + std::unique_ptr& coinJoinLoader() override { return m_context->coinjoin_loader; } std::unique_ptr handleInitMessage(InitMessageFn fn) override { diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 890df6c032..2d6cad3bf7 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -1379,7 +1380,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, const QStri #ifdef ENABLE_WALLET if (enableWallet) { for (const auto& wallet : m_node.walletLoader().getWallets()) { - disableAppNap |= wallet->coinJoin().isMixing(); + disableAppNap |= m_node.coinJoinLoader()->GetClient(wallet->getWalletName())->isMixing(); } } #endif // ENABLE_WALLET diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index e52d650bde..bafc6127b4 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS @@ -411,7 +412,7 @@ void OptionsDialog::on_okButton_clicked() #ifdef ENABLE_WALLET if (m_enable_wallet) { for (auto& wallet : model->node().walletLoader().getWallets()) { - wallet->coinJoin().resetCachedBlocks(); + model->node().coinJoinLoader()->GetClient(wallet->getWalletName())->resetCachedBlocks(); wallet->markDirty(); } } diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 40bb4adcac..682ebb5d9e 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -16,6 +16,7 @@ #include #include +#include #include @@ -306,7 +307,7 @@ void OverviewPage::setWalletModel(WalletModel *model) // Disable coinJoinClient builtin support for automatic backups while we are in GUI, // we'll handle automatic backups and user warnings in coinJoinStatus() - walletModel->coinJoin().disableAutobackups(); + walletModel->coinJoin()->disableAutobackups(); connect(ui->toggleCoinJoin, &QPushButton::clicked, this, &OverviewPage::toggleCoinJoin); @@ -523,7 +524,7 @@ void OverviewPage::coinJoinStatus(bool fForce) int nBestHeight = clientModel->node().getNumBlocks(); // We are processing more than 1 block per second, we'll just leave - if (nBestHeight > walletModel->coinJoin().getCachedBlocks() && GetTime() - nLastDSProgressBlockTime <= 1) return; + if (nBestHeight > walletModel->coinJoin()->getCachedBlocks() && GetTime() - nLastDSProgressBlockTime <= 1) return; nLastDSProgressBlockTime = GetTime(); QString strKeysLeftText(tr("keys left: %1").arg(walletModel->getKeysLeftSinceAutoBackup())); @@ -533,9 +534,9 @@ void OverviewPage::coinJoinStatus(bool fForce) ui->labelCoinJoinEnabled->setToolTip(strKeysLeftText); QString strCoinJoinName = QString::fromStdString(gCoinJoinName); - if (!walletModel->coinJoin().isMixing()) { - if (nBestHeight != walletModel->coinJoin().getCachedBlocks()) { - walletModel->coinJoin().setCachedBlocks(nBestHeight); + if (!walletModel->coinJoin()->isMixing()) { + if (nBestHeight != walletModel->coinJoin()->getCachedBlocks()) { + walletModel->coinJoin()->setCachedBlocks(nBestHeight); updateCoinJoinProgress(); } @@ -596,7 +597,7 @@ void OverviewPage::coinJoinStatus(bool fForce) } } - QString strEnabled = walletModel->coinJoin().isMixing() ? tr("Enabled") : tr("Disabled"); + QString strEnabled = walletModel->coinJoin()->isMixing() ? tr("Enabled") : tr("Disabled"); // Show how many keys left in advanced PS UI mode only if(fShowAdvancedCJUI) strEnabled += ", " + strKeysLeftText; ui->labelCoinJoinEnabled->setText(strEnabled); @@ -618,15 +619,15 @@ void OverviewPage::coinJoinStatus(bool fForce) } // check coinjoin status and unlock if needed - if(nBestHeight != walletModel->coinJoin().getCachedBlocks()) { + if(nBestHeight != walletModel->coinJoin()->getCachedBlocks()) { // Balance and number of transactions might have changed - walletModel->coinJoin().setCachedBlocks(nBestHeight); + walletModel->coinJoin()->setCachedBlocks(nBestHeight); updateCoinJoinProgress(); } setWidgetsVisible(true); - ui->labelSubmittedDenom->setText(QString(walletModel->coinJoin().getSessionDenoms().c_str())); + ui->labelSubmittedDenom->setText(QString(walletModel->coinJoin()->getSessionDenoms().c_str())); } void OverviewPage::toggleCoinJoin(){ @@ -641,7 +642,7 @@ void OverviewPage::toggleCoinJoin(){ settings.setValue("hasMixed", "hasMixed"); } - if (!walletModel->coinJoin().isMixing()) { + if (!walletModel->coinJoin()->isMixing()) { auto& options = walletModel->node().coinJoinOptions(); const CAmount nMinAmount = options.getSmallestDenomination() + options.getMaxCollateralAmount(); if(m_balances.balance < nMinAmount) { @@ -659,7 +660,7 @@ void OverviewPage::toggleCoinJoin(){ if(!ctx.isValid()) { //unlock was cancelled - walletModel->coinJoin().resetCachedBlocks(); + walletModel->coinJoin()->resetCachedBlocks(); QMessageBox::warning(this, strCoinJoinName, tr("Wallet is locked and user declined to unlock. Disabling %1.").arg(strCoinJoinName), QMessageBox::Ok, QMessageBox::Ok); @@ -670,15 +671,15 @@ void OverviewPage::toggleCoinJoin(){ } - walletModel->coinJoin().resetCachedBlocks(); + walletModel->coinJoin()->resetCachedBlocks(); - if (walletModel->coinJoin().isMixing()) { + if (walletModel->coinJoin()->isMixing()) { ui->toggleCoinJoin->setText(tr("Start %1").arg(strCoinJoinName)); - walletModel->coinJoin().resetPool(); - walletModel->coinJoin().stopMixing(); + walletModel->coinJoin()->resetPool(); + walletModel->coinJoin()->stopMixing(); } else { ui->toggleCoinJoin->setText(tr("Stop %1").arg(strCoinJoinName)); - walletModel->coinJoin().startMixing(); + walletModel->coinJoin()->startMixing(); } } @@ -718,5 +719,5 @@ void OverviewPage::DisableCoinJoinCompletely() if (nWalletBackups <= 0) { ui->labelCoinJoinEnabled->setText("(" + tr("Disabled") + ")"); } - walletModel->coinJoin().stopMixing(); + walletModel->coinJoin()->stopMixing(); } diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index d7c11f1327..049fba2f40 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -77,6 +78,11 @@ void WalletModel::setClientModel(ClientModel* client_model) if (!m_client_model) timer->stop(); } +std::unique_ptr WalletModel::coinJoin() const +{ + return m_node.coinJoinLoader()->GetClient(m_wallet->getWalletName()); +} + void WalletModel::updateStatus() { EncryptionStatus newEncryptionStatus = getEncryptionStatus(); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 9d385f8a3e..b2a31b82b1 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -38,6 +38,9 @@ class uint256; namespace interfaces { class Node; +namespace CoinJoin { +class Client; +} // namespace CoinJoin } // namespace interfaces QT_BEGIN_NAMESPACE @@ -151,7 +154,7 @@ public: interfaces::Node& node() const { return m_node; } interfaces::Wallet& wallet() const { return *m_wallet; } void setClientModel(ClientModel* client_model); - interfaces::CoinJoin::Client& coinJoin() const { return m_wallet->coinJoin(); } + std::unique_ptr coinJoin() const; QString getWalletName() const; QString getDisplayName() const;