mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
refactor: use coinjoin interfaces in qt
This commit is contained in:
parent
60240b1fde
commit
7fd30b5203
@ -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<interfaces::CoinJoin::Loader>& coinJoinLoader() = 0;
|
||||
|
||||
//! Register handler for init messages.
|
||||
using InitMessageFn = std::function<void(const std::string& message)>;
|
||||
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <governance/object.h>
|
||||
#include <init.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <interfaces/coinjoin.h>
|
||||
#include <interfaces/handler.h>
|
||||
#include <interfaces/wallet.h>
|
||||
#include <llmq/chainlocks.h>
|
||||
@ -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<interfaces::CoinJoin::Loader>& coinJoinLoader() override { return m_context->coinjoin_loader; }
|
||||
|
||||
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
|
||||
{
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <functional>
|
||||
#include <chain.h>
|
||||
#include <chainparams.h>
|
||||
#include <interfaces/coinjoin.h>
|
||||
#include <interfaces/handler.h>
|
||||
#include <interfaces/node.h>
|
||||
#include <qt/governancelist.h>
|
||||
@ -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
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <qt/guiutil.h>
|
||||
#include <qt/optionsmodel.h>
|
||||
|
||||
#include <interfaces/coinjoin.h>
|
||||
#include <interfaces/node.h>
|
||||
#include <interfaces/wallet.h>
|
||||
#include <validation.h> // 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();
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <qt/walletmodel.h>
|
||||
|
||||
#include <coinjoin/options.h>
|
||||
#include <interfaces/coinjoin.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@ -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("<span style='" + GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_ERROR) + "'>(" + tr("Disabled") + ")</span>");
|
||||
}
|
||||
walletModel->coinJoin().stopMixing();
|
||||
walletModel->coinJoin()->stopMixing();
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <qt/recentrequeststablemodel.h>
|
||||
#include <qt/transactiontablemodel.h>
|
||||
|
||||
#include <interfaces/coinjoin.h>
|
||||
#include <interfaces/handler.h>
|
||||
#include <interfaces/node.h>
|
||||
#include <key_io.h>
|
||||
@ -77,6 +78,11 @@ void WalletModel::setClientModel(ClientModel* client_model)
|
||||
if (!m_client_model) timer->stop();
|
||||
}
|
||||
|
||||
std::unique_ptr<interfaces::CoinJoin::Client> WalletModel::coinJoin() const
|
||||
{
|
||||
return m_node.coinJoinLoader()->GetClient(m_wallet->getWalletName());
|
||||
}
|
||||
|
||||
void WalletModel::updateStatus()
|
||||
{
|
||||
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
|
||||
|
@ -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<interfaces::CoinJoin::Client> coinJoin() const;
|
||||
|
||||
QString getWalletName() const;
|
||||
QString getDisplayName() const;
|
||||
|
Loading…
Reference in New Issue
Block a user