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 <interfaces/handler.h> | #include <interfaces/handler.h> | ||||
#include <interfaces/node.h> | #include <interfaces/node.h> | ||||
#include <QApplication> | #include <QApplication> | ||||
#include <QMessageBox> | |||||
#include <QMutexLocker> | #include <QMutexLocker> | ||||
#include <QThread> | #include <QThread> | ||||
#include <QWindow> | #include <QWindow> | ||||
#include <algorithm> | #include <algorithm> | ||||
WalletController::WalletController(interfaces::Node &node, | WalletController::WalletController(interfaces::Node &node, | ||||
const PlatformStyle *platform_style, | const PlatformStyle *platform_style, | ||||
Show All 14 Lines | |||||
// available in the header, just forward declared. | // available in the header, just forward declared. | ||||
WalletController::~WalletController() {} | WalletController::~WalletController() {} | ||||
std::vector<WalletModel *> WalletController::getWallets() const { | std::vector<WalletModel *> WalletController::getWallets() const { | ||||
QMutexLocker locker(&m_mutex); | QMutexLocker locker(&m_mutex); | ||||
return m_wallets; | return m_wallets; | ||||
} | } | ||||
std::vector<std::string> WalletController::getWalletsAvailableToOpen() const { | |||||
QMutexLocker locker(&m_mutex); | |||||
std::vector<std::string> wallets = m_node.listWalletDir(); | |||||
for (WalletModel *wallet_model : m_wallets) { | |||||
auto it = std::remove(wallets.begin(), wallets.end(), | |||||
wallet_model->wallet().getWalletName()); | |||||
if (it != wallets.end()) { | |||||
wallets.erase(it); | |||||
} | |||||
} | |||||
return wallets; | |||||
} | |||||
WalletModel *WalletController::openWallet(const CChainParams ¶ms, | |||||
const std::string &name, | |||||
QWidget *parent) { | |||||
std::string error, warning; | |||||
WalletModel *wallet_model = | |||||
getOrCreateWallet(m_node.loadWallet(params, name, error, warning)); | |||||
if (wallet_model == nullptr) { | |||||
QMessageBox::warning(parent, tr("Open Wallet"), | |||||
QString::fromStdString(error)); | |||||
} | |||||
if (!warning.empty()) { | |||||
QMessageBox::information(parent, tr("Open Wallet"), | |||||
QString::fromStdString(warning)); | |||||
} | |||||
return wallet_model; | |||||
} | |||||
WalletModel *WalletController::getOrCreateWallet( | WalletModel *WalletController::getOrCreateWallet( | ||||
std::unique_ptr<interfaces::Wallet> wallet) { | std::unique_ptr<interfaces::Wallet> wallet) { | ||||
QMutexLocker locker(&m_mutex); | QMutexLocker locker(&m_mutex); | ||||
// Return model instance if exists. | // Return model instance if exists. | ||||
if (!m_wallets.empty()) { | if (!m_wallets.empty()) { | ||||
std::string name = wallet->getWalletName(); | std::string name = wallet->getWalletName(); | ||||
for (WalletModel *wallet_model : m_wallets) { | for (WalletModel *wallet_model : m_wallets) { | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |