Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletcontroller.cpp
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <qt/walletcontroller.h> | #include <qt/walletcontroller.h> | ||||
#include <qt/askpassphrasedialog.h> | #include <qt/askpassphrasedialog.h> | ||||
#include <qt/clientmodel.h> | |||||
#include <qt/createwalletdialog.h> | #include <qt/createwalletdialog.h> | ||||
#include <qt/guiconstants.h> | #include <qt/guiconstants.h> | ||||
#include <qt/guiutil.h> | #include <qt/guiutil.h> | ||||
#include <interfaces/handler.h> | #include <interfaces/handler.h> | ||||
#include <interfaces/node.h> | #include <interfaces/node.h> | ||||
#include <util/string.h> | #include <util/string.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <QApplication> | #include <QApplication> | ||||
#include <QMutexLocker> | #include <QMutexLocker> | ||||
#include <QTimer> | #include <QTimer> | ||||
#include <QWindow> | #include <QWindow> | ||||
#include <algorithm> | #include <algorithm> | ||||
WalletController::WalletController(interfaces::Node &node, | WalletController::WalletController(ClientModel &client_model, | ||||
const PlatformStyle *platform_style, | const PlatformStyle *platform_style, | ||||
OptionsModel *options_model, QObject *parent) | QObject *parent) | ||||
: QObject(parent), m_activity_thread(new QThread(this)), | : QObject(parent), m_activity_thread(new QThread(this)), | ||||
m_activity_worker(new QObject), m_node(node), | m_activity_worker(new QObject), m_client_model(client_model), | ||||
m_platform_style(platform_style), m_options_model(options_model) { | m_node(client_model.node()), m_platform_style(platform_style), | ||||
m_options_model(client_model.getOptionsModel()) { | |||||
m_handler_load_wallet = m_node.handleLoadWallet( | m_handler_load_wallet = m_node.handleLoadWallet( | ||||
[this](std::unique_ptr<interfaces::Wallet> wallet) { | [this](std::unique_ptr<interfaces::Wallet> wallet) { | ||||
getOrCreateWallet(std::move(wallet)); | getOrCreateWallet(std::move(wallet)); | ||||
}); | }); | ||||
for (std::unique_ptr<interfaces::Wallet> &wallet : m_node.getWallets()) { | for (std::unique_ptr<interfaces::Wallet> &wallet : m_node.getWallets()) { | ||||
getOrCreateWallet(std::move(wallet)); | getOrCreateWallet(std::move(wallet)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | if (!m_wallets.empty()) { | ||||
if (wallet_model->wallet().getWalletName() == name) { | if (wallet_model->wallet().getWalletName() == name) { | ||||
return wallet_model; | return wallet_model; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Instantiate model and register it. | // Instantiate model and register it. | ||||
WalletModel *wallet_model = new WalletModel( | WalletModel *wallet_model = new WalletModel( | ||||
std::move(wallet), m_node, m_platform_style, m_options_model, nullptr); | std::move(wallet), m_client_model, m_platform_style, nullptr); | ||||
// Handler callback runs in a different thread so fix wallet model thread | // Handler callback runs in a different thread so fix wallet model thread | ||||
// affinity. | // affinity. | ||||
wallet_model->moveToThread(thread()); | wallet_model->moveToThread(thread()); | ||||
wallet_model->setParent(this); | wallet_model->setParent(this); | ||||
m_wallets.push_back(wallet_model); | m_wallets.push_back(wallet_model); | ||||
// WalletModel::startPollBalance needs to be called in a thread managed by | // WalletModel::startPollBalance needs to be called in a thread managed by | ||||
// Qt because of startTimer. Considering the current thread can be a RPC | // Qt because of startTimer. Considering the current thread can be a RPC | ||||
▲ Show 20 Lines • Show All 210 Lines • Show Last 20 Lines |