2023-08-16 19:27:31 +02:00
|
|
|
// Copyright (c) 2019-2020 The Bitcoin Core developers
|
2019-01-18 21:20:55 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2019-11-19 10:10:40 +01:00
|
|
|
#include <qt/walletcontroller.h>
|
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
#include <qt/askpassphrasedialog.h>
|
2018-08-01 19:38:45 +02:00
|
|
|
#include <qt/clientmodel.h>
|
2019-06-21 16:13:15 +02:00
|
|
|
#include <qt/createwalletdialog.h>
|
|
|
|
#include <qt/guiconstants.h>
|
2021-11-06 20:14:18 +01:00
|
|
|
#include <qt/guiutil.h>
|
2019-11-19 10:10:40 +01:00
|
|
|
#include <qt/walletmodel.h>
|
2019-06-21 16:13:15 +02:00
|
|
|
|
refactor: subsume CoinJoin objects under CJContext, deglobalize coinJoin{ClientQueueManager,Server} (#5337)
## Motivation
CoinJoin's subsystems are initialized by variables and managers that
occupy the global context. The _extent_ to which these subsystems
entrench themselves into the codebase is difficult to assess and moving
them out of the global context forces us to enumerate the subsystems in
the codebase that rely on CoinJoin logic and enumerate the order in
which components are initialized and destroyed.
Keeping this in mind, the scope of this pull request aims to:
* Reduce the amount of CoinJoin-specific entities present in the global
scope
* Make the remaining usage of these entities in the global scope
explicit and easily searchable
## Additional Information
* The initialization of `CCoinJoinClientQueueManager` is dependent on
blocks-only mode being disabled (which can be alternatively interpreted
as enabling the relay of transactions). The same applies to
`CBlockPolicyEstimator`, which `CCoinJoinClientQueueManager` depends.
Therefore, `CCoinJoinClientQueueManager` is only initialized if
transaction relaying is enabled and so is its scheduled maintenance
task. This can be found by looking at `init.cpp`
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L1681-L1683),
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L2253-L2255)
and
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L2326-L2327).
For this reason, `CBlockPolicyEstimator` is not a member of `CJContext`
and its usage is fulfilled by passing it as a reference when
initializing the scheduling task.
* `CJClientManager` has not used `CConnman` or `CTxMemPool` as `const`
as existing code that is outside the scope of this PR would cast away
constness, which would be unacceptable. Furthermore, some logical paths
are taken that will grind to a halt if they are stored as `const`.
Examples of such a call chains would be:
* `CJClientManager::DoMaintenance >
CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating >
CCoinJoinClientSession::DoAutomaticDenominating >
CCoinJoinClientSession::StartNewQueue > CConnman::AddPendingMasternode`
which modifies `CConnman::vPendingMasternodes`, which is non-const
behaviour
* `CJClientManager::DoMaintenance >
CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating >
CCoinJoin::IsCollateralValid > AcceptToMemoryPool` which adds a
transaction to the memory pool, which is non-const behaviour
* There were cppcheck [linter
failures](https://github.com/dashpay/dash/pull/5337#issuecomment-1685084688)
that seemed to be caused by the usage of `Assert` in
`coinjoin/client.h`. This seems to be resolved by backporting
[bitcoin#24714](https://github.com/bitcoin/bitcoin/pull/24714). (Thanks
@knst!)
* Depends on #5546
---------
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
2023-09-13 19:52:38 +02:00
|
|
|
#include <coinjoin/client.h>
|
|
|
|
#include <node/context.h>
|
2019-01-18 21:20:55 +01:00
|
|
|
#include <interfaces/handler.h>
|
|
|
|
#include <interfaces/node.h>
|
2022-03-24 21:07:40 +01:00
|
|
|
#include <util/string.h>
|
2022-04-07 06:43:16 +02:00
|
|
|
#include <util/translation.h>
|
2019-11-19 10:10:40 +01:00
|
|
|
#include <wallet/wallet.h>
|
2019-01-18 21:20:55 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2019-03-22 11:07:35 +01:00
|
|
|
#include <QApplication>
|
2019-02-12 19:19:05 +01:00
|
|
|
#include <QMessageBox>
|
2019-01-18 21:20:55 +01:00
|
|
|
#include <QMutexLocker>
|
|
|
|
#include <QThread>
|
2019-06-21 16:13:15 +02:00
|
|
|
#include <QTimer>
|
2019-03-22 11:07:35 +01:00
|
|
|
#include <QWindow>
|
2019-01-18 21:20:55 +01:00
|
|
|
|
2018-08-01 19:38:45 +02:00
|
|
|
WalletController::WalletController(ClientModel& client_model, QObject* parent)
|
2019-01-18 21:20:55 +01:00
|
|
|
: QObject(parent)
|
2019-06-21 16:13:15 +02:00
|
|
|
, m_activity_thread(new QThread(this))
|
|
|
|
, m_activity_worker(new QObject)
|
2018-08-01 19:38:45 +02:00
|
|
|
, m_client_model(client_model)
|
|
|
|
, m_node(client_model.node())
|
|
|
|
, m_options_model(client_model.getOptionsModel())
|
2019-01-18 21:20:55 +01:00
|
|
|
{
|
2023-08-24 10:10:24 +02:00
|
|
|
m_handler_load_wallet = m_node.walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
|
2019-01-18 21:20:55 +01:00
|
|
|
getOrCreateWallet(std::move(wallet));
|
|
|
|
});
|
|
|
|
|
2023-08-24 10:10:24 +02:00
|
|
|
for (std::unique_ptr<interfaces::Wallet>& wallet : m_node.walletLoader().getWallets()) {
|
2019-01-18 21:20:55 +01:00
|
|
|
getOrCreateWallet(std::move(wallet));
|
|
|
|
}
|
2019-02-12 19:19:05 +01:00
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
m_activity_worker->moveToThread(m_activity_thread);
|
|
|
|
m_activity_thread->start();
|
2019-01-18 21:20:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not using the default destructor because not all member types definitions are
|
|
|
|
// available in the header, just forward declared.
|
2019-02-12 19:19:05 +01:00
|
|
|
WalletController::~WalletController()
|
|
|
|
{
|
2019-06-21 16:13:15 +02:00
|
|
|
m_activity_thread->quit();
|
|
|
|
m_activity_thread->wait();
|
|
|
|
delete m_activity_worker;
|
2019-02-12 19:19:05 +01:00
|
|
|
}
|
2019-01-18 21:20:55 +01:00
|
|
|
|
2019-07-08 16:27:18 +02:00
|
|
|
std::vector<WalletModel*> WalletController::getOpenWallets() const
|
2019-01-18 21:20:55 +01:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
return m_wallets;
|
|
|
|
}
|
|
|
|
|
2019-07-08 16:27:18 +02:00
|
|
|
std::map<std::string, bool> WalletController::listWalletDir() const
|
2019-02-12 19:19:05 +01:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2019-07-08 16:27:18 +02:00
|
|
|
std::map<std::string, bool> wallets;
|
2023-08-24 10:10:24 +02:00
|
|
|
for (const std::string& name : m_node.walletLoader().listWalletDir()) {
|
2019-07-08 16:27:18 +02:00
|
|
|
wallets[name] = false;
|
|
|
|
}
|
2019-02-12 19:19:05 +01:00
|
|
|
for (WalletModel* wallet_model : m_wallets) {
|
2019-07-08 16:27:18 +02:00
|
|
|
auto it = wallets.find(wallet_model->wallet().getWalletName());
|
|
|
|
if (it != wallets.end()) it->second = true;
|
2019-02-12 19:19:05 +01:00
|
|
|
}
|
|
|
|
return wallets;
|
|
|
|
}
|
|
|
|
|
2019-02-14 21:46:22 +01:00
|
|
|
void WalletController::closeWallet(WalletModel* wallet_model, QWidget* parent)
|
|
|
|
{
|
|
|
|
QMessageBox box(parent);
|
|
|
|
box.setWindowTitle(tr("Close wallet"));
|
2019-09-16 10:41:05 +02:00
|
|
|
box.setText(tr("Are you sure you wish to close the wallet <i>%1</i>?").arg(GUIUtil::HtmlEscape(wallet_model->getDisplayName())));
|
2019-02-14 21:46:22 +01:00
|
|
|
box.setInformativeText(tr("Closing the wallet for too long can result in having to resync the entire chain if pruning is enabled."));
|
|
|
|
box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
|
|
|
|
box.setDefaultButton(QMessageBox::Yes);
|
|
|
|
if (box.exec() != QMessageBox::Yes) return;
|
|
|
|
|
|
|
|
// First remove wallet from node.
|
|
|
|
wallet_model->wallet().remove();
|
|
|
|
// Now release the model.
|
|
|
|
removeAndDeleteWallet(wallet_model);
|
|
|
|
}
|
|
|
|
|
2019-01-18 21:20:55 +01:00
|
|
|
WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
|
|
|
|
// Return model instance if exists.
|
|
|
|
if (!m_wallets.empty()) {
|
|
|
|
std::string name = wallet->getWalletName();
|
|
|
|
for (WalletModel* wallet_model : m_wallets) {
|
|
|
|
if (wallet_model->wallet().getWalletName() == name) {
|
|
|
|
return wallet_model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate model and register it.
|
2018-08-01 19:38:45 +02:00
|
|
|
WalletModel* wallet_model = new WalletModel(std::move(wallet), m_client_model, nullptr);
|
2019-08-12 14:15:48 +02:00
|
|
|
// Handler callback runs in a different thread so fix wallet model thread affinity.
|
|
|
|
wallet_model->moveToThread(thread());
|
|
|
|
wallet_model->setParent(this);
|
2019-01-18 21:20:55 +01:00
|
|
|
m_wallets.push_back(wallet_model);
|
|
|
|
|
2019-10-26 13:00:01 +02:00
|
|
|
// WalletModel::startPollBalance needs to be called in a thread managed by
|
|
|
|
// Qt because of startTimer. Considering the current thread can be a RPC
|
|
|
|
// thread, better delegate the calling to Qt with Qt::AutoConnection.
|
|
|
|
const bool called = QMetaObject::invokeMethod(wallet_model, "startPollBalance");
|
|
|
|
assert(called);
|
|
|
|
|
2022-06-01 16:47:01 +02:00
|
|
|
connect(wallet_model, &WalletModel::unload, this, [this, wallet_model] {
|
2019-03-22 11:07:35 +01:00
|
|
|
// Defer removeAndDeleteWallet when no modal widget is active.
|
|
|
|
// TODO: remove this workaround by removing usage of QDiallog::exec.
|
|
|
|
if (QApplication::activeModalWidget()) {
|
|
|
|
connect(qApp, &QApplication::focusWindowChanged, wallet_model, [this, wallet_model]() {
|
|
|
|
if (!QApplication::activeModalWidget()) {
|
|
|
|
removeAndDeleteWallet(wallet_model);
|
|
|
|
}
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
} else {
|
|
|
|
removeAndDeleteWallet(wallet_model);
|
|
|
|
}
|
2022-06-01 16:47:01 +02:00
|
|
|
}, Qt::QueuedConnection);
|
2019-01-18 21:20:55 +01:00
|
|
|
|
|
|
|
// Re-emit coinsSent signal from wallet model.
|
|
|
|
connect(wallet_model, &WalletModel::coinsSent, this, &WalletController::coinsSent);
|
|
|
|
|
|
|
|
// Notify walletAdded signal on the GUI thread.
|
2019-08-12 14:15:48 +02:00
|
|
|
Q_EMIT walletAdded(wallet_model);
|
2019-01-18 21:20:55 +01:00
|
|
|
|
|
|
|
return wallet_model;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletController::removeAndDeleteWallet(WalletModel* wallet_model)
|
|
|
|
{
|
|
|
|
// Unregister wallet model.
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
m_wallets.erase(std::remove(m_wallets.begin(), m_wallets.end(), wallet_model));
|
|
|
|
}
|
|
|
|
Q_EMIT walletRemoved(wallet_model);
|
|
|
|
// Currently this can trigger the unload since the model can hold the last
|
|
|
|
// CWallet shared pointer.
|
|
|
|
delete wallet_model;
|
|
|
|
}
|
2019-02-12 19:19:05 +01:00
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
WalletControllerActivity::WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget)
|
|
|
|
: QObject(wallet_controller)
|
|
|
|
, m_wallet_controller(wallet_controller)
|
|
|
|
, m_parent_widget(parent_widget)
|
|
|
|
{
|
|
|
|
}
|
2019-02-12 19:19:05 +01:00
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
WalletControllerActivity::~WalletControllerActivity()
|
|
|
|
{
|
|
|
|
delete m_progress_dialog;
|
|
|
|
}
|
2019-02-12 19:19:05 +01:00
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
void WalletControllerActivity::showProgressDialog(const QString& label_text)
|
2019-02-12 19:19:05 +01:00
|
|
|
{
|
2020-03-28 03:14:08 +01:00
|
|
|
assert(!m_progress_dialog);
|
2019-06-21 16:13:15 +02:00
|
|
|
m_progress_dialog = new QProgressDialog(m_parent_widget);
|
|
|
|
|
|
|
|
m_progress_dialog->setLabelText(label_text);
|
|
|
|
m_progress_dialog->setRange(0, 0);
|
|
|
|
m_progress_dialog->setCancelButton(nullptr);
|
|
|
|
m_progress_dialog->setWindowModality(Qt::ApplicationModal);
|
|
|
|
GUIUtil::PolishProgressDialog(m_progress_dialog);
|
|
|
|
}
|
|
|
|
|
2020-03-28 03:14:08 +01:00
|
|
|
void WalletControllerActivity::destroyProgressDialog()
|
|
|
|
{
|
|
|
|
assert(m_progress_dialog);
|
|
|
|
delete m_progress_dialog;
|
|
|
|
m_progress_dialog = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
CreateWalletActivity::CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget)
|
|
|
|
: WalletControllerActivity(wallet_controller, parent_widget)
|
|
|
|
{
|
|
|
|
m_passphrase.reserve(MAX_PASSPHRASE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateWalletActivity::~CreateWalletActivity()
|
|
|
|
{
|
|
|
|
delete m_create_wallet_dialog;
|
|
|
|
delete m_passphrase_dialog;
|
|
|
|
}
|
|
|
|
|
2019-09-16 10:41:05 +02:00
|
|
|
void CreateWalletActivity::askPassphrase()
|
2019-06-21 16:13:15 +02:00
|
|
|
{
|
|
|
|
m_passphrase_dialog = new AskPassphraseDialog(AskPassphraseDialog::Encrypt, m_parent_widget, &m_passphrase);
|
2019-09-16 10:41:05 +02:00
|
|
|
m_passphrase_dialog->setWindowModality(Qt::ApplicationModal);
|
2019-06-21 16:13:15 +02:00
|
|
|
m_passphrase_dialog->show();
|
|
|
|
|
|
|
|
connect(m_passphrase_dialog, &QObject::destroyed, [this] {
|
|
|
|
m_passphrase_dialog = nullptr;
|
|
|
|
});
|
|
|
|
connect(m_passphrase_dialog, &QDialog::accepted, [this] {
|
|
|
|
createWallet();
|
|
|
|
});
|
|
|
|
connect(m_passphrase_dialog, &QDialog::rejected, [this] {
|
|
|
|
Q_EMIT finished();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateWalletActivity::createWallet()
|
|
|
|
{
|
|
|
|
showProgressDialog(tr("Creating Wallet <b>%1</b>...").arg(m_create_wallet_dialog->walletName().toHtmlEscaped()));
|
|
|
|
|
|
|
|
std::string name = m_create_wallet_dialog->walletName().toStdString();
|
|
|
|
uint64_t flags = 0;
|
2019-09-16 10:41:05 +02:00
|
|
|
if (m_create_wallet_dialog->isDisablePrivateKeysChecked()) {
|
2019-06-21 16:13:15 +02:00
|
|
|
flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS;
|
2019-02-12 19:19:05 +01:00
|
|
|
}
|
2019-09-16 10:41:05 +02:00
|
|
|
if (m_create_wallet_dialog->isMakeBlankWalletChecked()) {
|
2019-06-21 16:13:15 +02:00
|
|
|
flags |= WALLET_FLAG_BLANK_WALLET;
|
2019-02-12 19:19:05 +01:00
|
|
|
}
|
2019-06-21 16:13:15 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(500, worker(), [this, name, flags] {
|
refactor: subsume CoinJoin objects under CJContext, deglobalize coinJoin{ClientQueueManager,Server} (#5337)
## Motivation
CoinJoin's subsystems are initialized by variables and managers that
occupy the global context. The _extent_ to which these subsystems
entrench themselves into the codebase is difficult to assess and moving
them out of the global context forces us to enumerate the subsystems in
the codebase that rely on CoinJoin logic and enumerate the order in
which components are initialized and destroyed.
Keeping this in mind, the scope of this pull request aims to:
* Reduce the amount of CoinJoin-specific entities present in the global
scope
* Make the remaining usage of these entities in the global scope
explicit and easily searchable
## Additional Information
* The initialization of `CCoinJoinClientQueueManager` is dependent on
blocks-only mode being disabled (which can be alternatively interpreted
as enabling the relay of transactions). The same applies to
`CBlockPolicyEstimator`, which `CCoinJoinClientQueueManager` depends.
Therefore, `CCoinJoinClientQueueManager` is only initialized if
transaction relaying is enabled and so is its scheduled maintenance
task. This can be found by looking at `init.cpp`
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L1681-L1683),
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L2253-L2255)
and
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L2326-L2327).
For this reason, `CBlockPolicyEstimator` is not a member of `CJContext`
and its usage is fulfilled by passing it as a reference when
initializing the scheduling task.
* `CJClientManager` has not used `CConnman` or `CTxMemPool` as `const`
as existing code that is outside the scope of this PR would cast away
constness, which would be unacceptable. Furthermore, some logical paths
are taken that will grind to a halt if they are stored as `const`.
Examples of such a call chains would be:
* `CJClientManager::DoMaintenance >
CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating >
CCoinJoinClientSession::DoAutomaticDenominating >
CCoinJoinClientSession::StartNewQueue > CConnman::AddPendingMasternode`
which modifies `CConnman::vPendingMasternodes`, which is non-const
behaviour
* `CJClientManager::DoMaintenance >
CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating >
CCoinJoin::IsCollateralValid > AcceptToMemoryPool` which adds a
transaction to the memory pool, which is non-const behaviour
* There were cppcheck [linter
failures](https://github.com/dashpay/dash/pull/5337#issuecomment-1685084688)
that seemed to be caused by the usage of `Assert` in
`coinjoin/client.h`. This seems to be resolved by backporting
[bitcoin#24714](https://github.com/bitcoin/bitcoin/pull/24714). (Thanks
@knst!)
* Depends on #5546
---------
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
2023-09-13 19:52:38 +02:00
|
|
|
std::unique_ptr<interfaces::Wallet> wallet = node().walletLoader().createWallet(*::coinJoinClientManagers, name, m_passphrase, flags, m_error_message, m_warning_message);
|
2019-06-21 16:13:15 +02:00
|
|
|
|
2022-10-17 04:33:10 +02:00
|
|
|
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
|
2019-06-21 16:13:15 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(500, this, &CreateWalletActivity::finish);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateWalletActivity::finish()
|
|
|
|
{
|
2020-03-28 03:14:08 +01:00
|
|
|
destroyProgressDialog();
|
2019-06-21 16:13:15 +02:00
|
|
|
|
2020-05-10 10:42:11 +02:00
|
|
|
if (!m_error_message.empty()) {
|
2022-04-07 06:43:16 +02:00
|
|
|
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message.translated));
|
2019-06-21 16:13:15 +02:00
|
|
|
} else if (!m_warning_message.empty()) {
|
2020-05-13 20:30:31 +02:00
|
|
|
QMessageBox::warning(m_parent_widget, tr("Create wallet warning"), QString::fromStdString(Join(m_warning_message, Untranslated("\n")).translated));
|
2019-06-21 16:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_wallet_model) Q_EMIT created(m_wallet_model);
|
|
|
|
|
|
|
|
Q_EMIT finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateWalletActivity::create()
|
|
|
|
{
|
|
|
|
m_create_wallet_dialog = new CreateWalletDialog(m_parent_widget);
|
|
|
|
m_create_wallet_dialog->setWindowModality(Qt::ApplicationModal);
|
|
|
|
m_create_wallet_dialog->show();
|
|
|
|
|
|
|
|
connect(m_create_wallet_dialog, &QObject::destroyed, [this] {
|
|
|
|
m_create_wallet_dialog = nullptr;
|
|
|
|
});
|
|
|
|
connect(m_create_wallet_dialog, &QDialog::rejected, [this] {
|
|
|
|
Q_EMIT finished();
|
|
|
|
});
|
|
|
|
connect(m_create_wallet_dialog, &QDialog::accepted, [this] {
|
2019-09-16 10:41:05 +02:00
|
|
|
if (m_create_wallet_dialog->isEncryptWalletChecked()) {
|
|
|
|
askPassphrase();
|
2019-06-21 16:13:15 +02:00
|
|
|
} else {
|
|
|
|
createWallet();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenWalletActivity::OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget)
|
|
|
|
: WalletControllerActivity(wallet_controller, parent_widget)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenWalletActivity::finish()
|
|
|
|
{
|
2020-03-28 03:14:08 +01:00
|
|
|
destroyProgressDialog();
|
2019-06-21 16:13:15 +02:00
|
|
|
|
2020-05-10 10:42:11 +02:00
|
|
|
if (!m_error_message.empty()) {
|
2022-04-07 06:43:16 +02:00
|
|
|
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message.translated));
|
2019-06-21 16:13:15 +02:00
|
|
|
} else if (!m_warning_message.empty()) {
|
2020-05-13 20:30:31 +02:00
|
|
|
QMessageBox::warning(m_parent_widget, tr("Open wallet warning"), QString::fromStdString(Join(m_warning_message, Untranslated("\n")).translated));
|
2019-06-21 16:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_wallet_model) Q_EMIT opened(m_wallet_model);
|
|
|
|
|
2019-02-12 19:19:05 +01:00
|
|
|
Q_EMIT finished();
|
|
|
|
}
|
2019-06-21 16:13:15 +02:00
|
|
|
|
|
|
|
void OpenWalletActivity::open(const std::string& path)
|
|
|
|
{
|
|
|
|
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
|
|
|
|
|
|
|
|
showProgressDialog(tr("Opening Wallet <b>%1</b>...").arg(name.toHtmlEscaped()));
|
|
|
|
|
|
|
|
QTimer::singleShot(0, worker(), [this, path] {
|
refactor: subsume CoinJoin objects under CJContext, deglobalize coinJoin{ClientQueueManager,Server} (#5337)
## Motivation
CoinJoin's subsystems are initialized by variables and managers that
occupy the global context. The _extent_ to which these subsystems
entrench themselves into the codebase is difficult to assess and moving
them out of the global context forces us to enumerate the subsystems in
the codebase that rely on CoinJoin logic and enumerate the order in
which components are initialized and destroyed.
Keeping this in mind, the scope of this pull request aims to:
* Reduce the amount of CoinJoin-specific entities present in the global
scope
* Make the remaining usage of these entities in the global scope
explicit and easily searchable
## Additional Information
* The initialization of `CCoinJoinClientQueueManager` is dependent on
blocks-only mode being disabled (which can be alternatively interpreted
as enabling the relay of transactions). The same applies to
`CBlockPolicyEstimator`, which `CCoinJoinClientQueueManager` depends.
Therefore, `CCoinJoinClientQueueManager` is only initialized if
transaction relaying is enabled and so is its scheduled maintenance
task. This can be found by looking at `init.cpp`
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L1681-L1683),
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L2253-L2255)
and
[here](https://github.com/dashpay/dash/blob/93f8df1c31fdce6a14f149acfdff22678c3f22ca/src/init.cpp#L2326-L2327).
For this reason, `CBlockPolicyEstimator` is not a member of `CJContext`
and its usage is fulfilled by passing it as a reference when
initializing the scheduling task.
* `CJClientManager` has not used `CConnman` or `CTxMemPool` as `const`
as existing code that is outside the scope of this PR would cast away
constness, which would be unacceptable. Furthermore, some logical paths
are taken that will grind to a halt if they are stored as `const`.
Examples of such a call chains would be:
* `CJClientManager::DoMaintenance >
CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating >
CCoinJoinClientSession::DoAutomaticDenominating >
CCoinJoinClientSession::StartNewQueue > CConnman::AddPendingMasternode`
which modifies `CConnman::vPendingMasternodes`, which is non-const
behaviour
* `CJClientManager::DoMaintenance >
CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating >
CCoinJoin::IsCollateralValid > AcceptToMemoryPool` which adds a
transaction to the memory pool, which is non-const behaviour
* There were cppcheck [linter
failures](https://github.com/dashpay/dash/pull/5337#issuecomment-1685084688)
that seemed to be caused by the usage of `Assert` in
`coinjoin/client.h`. This seems to be resolved by backporting
[bitcoin#24714](https://github.com/bitcoin/bitcoin/pull/24714). (Thanks
@knst!)
* Depends on #5546
---------
Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com>
Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
2023-09-13 19:52:38 +02:00
|
|
|
std::unique_ptr<interfaces::Wallet> wallet = node().walletLoader().loadWallet(*::coinJoinClientManagers, path, m_error_message, m_warning_message);
|
2019-06-21 16:13:15 +02:00
|
|
|
|
|
|
|
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
|
|
|
|
|
|
|
|
QTimer::singleShot(0, this, &OpenWalletActivity::finish);
|
|
|
|
});
|
|
|
|
}
|