2020-04-16 19:14:08 +02:00
|
|
|
// Copyright (c) 2019-2020 The Bitcoin Core developers
|
2019-01-04 19:49:26 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_QT_WALLETCONTROLLER_H
|
|
|
|
#define BITCOIN_QT_WALLETCONTROLLER_H
|
|
|
|
|
2019-11-19 10:10:40 +01:00
|
|
|
#include <qt/sendcoinsrecipient.h>
|
2019-05-24 23:14:16 +02:00
|
|
|
#include <support/allocators/secure.h>
|
2019-01-04 19:49:26 +01:00
|
|
|
#include <sync.h>
|
2019-08-20 00:12:35 +02:00
|
|
|
#include <util/translation.h>
|
2019-01-04 19:49:26 +01:00
|
|
|
|
2019-05-27 20:07:05 +02:00
|
|
|
#include <map>
|
2019-01-04 19:49:26 +01:00
|
|
|
#include <memory>
|
2019-06-21 16:13:15 +02:00
|
|
|
#include <string>
|
2019-01-04 19:49:26 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2019-01-21 17:58:20 +01:00
|
|
|
#include <QMessageBox>
|
2019-01-04 19:49:26 +01:00
|
|
|
#include <QMutex>
|
2019-06-21 16:13:15 +02:00
|
|
|
#include <QProgressDialog>
|
2019-01-21 17:57:22 +01:00
|
|
|
#include <QThread>
|
2019-05-24 23:14:16 +02:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QString>
|
2019-01-04 19:49:26 +01:00
|
|
|
|
2018-08-01 19:38:45 +02:00
|
|
|
class ClientModel;
|
2019-01-04 19:49:26 +01:00
|
|
|
class OptionsModel;
|
|
|
|
class PlatformStyle;
|
2019-11-19 12:45:32 +01:00
|
|
|
class WalletModel;
|
2019-01-04 19:49:26 +01:00
|
|
|
|
|
|
|
namespace interfaces {
|
|
|
|
class Handler;
|
|
|
|
class Node;
|
2019-11-19 12:45:32 +01:00
|
|
|
class Wallet;
|
2019-01-04 19:49:26 +01:00
|
|
|
} // namespace interfaces
|
|
|
|
|
2019-05-24 23:14:16 +02:00
|
|
|
class AskPassphraseDialog;
|
|
|
|
class CreateWalletActivity;
|
|
|
|
class CreateWalletDialog;
|
2019-01-21 17:58:20 +01:00
|
|
|
class OpenWalletActivity;
|
2019-06-21 16:13:15 +02:00
|
|
|
class WalletControllerActivity;
|
2019-01-21 17:58:20 +01:00
|
|
|
|
2019-01-04 19:49:26 +01:00
|
|
|
/**
|
|
|
|
* Controller between interfaces::Node, WalletModel instances and the GUI.
|
|
|
|
*/
|
|
|
|
class WalletController : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
void removeAndDeleteWallet(WalletModel* wallet_model);
|
|
|
|
|
|
|
|
public:
|
2018-08-01 19:38:45 +02:00
|
|
|
WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent);
|
2019-01-04 19:49:26 +01:00
|
|
|
~WalletController();
|
|
|
|
|
2019-05-27 23:14:29 +02:00
|
|
|
//! Returns wallet models currently open.
|
|
|
|
std::vector<WalletModel*> getOpenWallets() const;
|
2019-05-27 20:07:05 +02:00
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
|
|
|
|
|
2019-05-27 20:07:05 +02:00
|
|
|
//! Returns all wallet names in the wallet dir mapped to whether the wallet
|
|
|
|
//! is loaded.
|
|
|
|
std::map<std::string, bool> listWalletDir() const;
|
2019-01-12 12:34:05 +01:00
|
|
|
|
2019-01-18 01:21:36 +01:00
|
|
|
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
|
2019-01-18 02:05:25 +01:00
|
|
|
void closeAllWallets(QWidget* parent = nullptr);
|
2019-01-04 19:49:26 +01:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void walletAdded(WalletModel* wallet_model);
|
|
|
|
void walletRemoved(WalletModel* wallet_model);
|
|
|
|
|
|
|
|
void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
|
|
|
|
|
|
|
|
private:
|
2019-06-21 16:13:15 +02:00
|
|
|
QThread* const m_activity_thread;
|
|
|
|
QObject* const m_activity_worker;
|
2018-08-01 19:38:45 +02:00
|
|
|
ClientModel& m_client_model;
|
2019-01-04 19:49:26 +01:00
|
|
|
interfaces::Node& m_node;
|
|
|
|
const PlatformStyle* const m_platform_style;
|
|
|
|
OptionsModel* const m_options_model;
|
|
|
|
mutable QMutex m_mutex;
|
|
|
|
std::vector<WalletModel*> m_wallets;
|
|
|
|
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
|
2019-01-21 17:58:20 +01:00
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
friend class WalletControllerActivity;
|
2019-01-21 17:58:20 +01:00
|
|
|
};
|
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
class WalletControllerActivity : public QObject
|
2019-01-21 17:58:20 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-06-21 16:13:15 +02:00
|
|
|
WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
|
|
|
|
virtual ~WalletControllerActivity();
|
2019-01-21 17:58:20 +01:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void finished();
|
2019-06-21 16:13:15 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
interfaces::Node& node() const { return m_wallet_controller->m_node; }
|
|
|
|
QObject* worker() const { return m_wallet_controller->m_activity_worker; }
|
|
|
|
|
|
|
|
void showProgressDialog(const QString& label_text);
|
2020-03-30 12:41:20 +02:00
|
|
|
void destroyProgressDialog();
|
2019-06-21 16:13:15 +02:00
|
|
|
|
|
|
|
WalletController* const m_wallet_controller;
|
|
|
|
QWidget* const m_parent_widget;
|
|
|
|
QProgressDialog* m_progress_dialog{nullptr};
|
|
|
|
WalletModel* m_wallet_model{nullptr};
|
2019-08-20 00:12:35 +02:00
|
|
|
bilingual_str m_error_message;
|
|
|
|
std::vector<bilingual_str> m_warning_message;
|
2019-06-21 16:13:15 +02:00
|
|
|
};
|
|
|
|
|
2019-05-24 23:14:16 +02:00
|
|
|
|
|
|
|
class CreateWalletActivity : public WalletControllerActivity
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
|
|
|
|
virtual ~CreateWalletActivity();
|
|
|
|
|
|
|
|
void create();
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void created(WalletModel* wallet_model);
|
|
|
|
|
|
|
|
private:
|
2019-09-07 11:08:28 +02:00
|
|
|
void askPassphrase();
|
2019-05-24 23:14:16 +02:00
|
|
|
void createWallet();
|
|
|
|
void finish();
|
|
|
|
|
|
|
|
SecureString m_passphrase;
|
|
|
|
CreateWalletDialog* m_create_wallet_dialog{nullptr};
|
|
|
|
AskPassphraseDialog* m_passphrase_dialog{nullptr};
|
|
|
|
};
|
|
|
|
|
2019-06-21 16:13:15 +02:00
|
|
|
class OpenWalletActivity : public WalletControllerActivity
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
|
|
|
|
|
|
|
|
void open(const std::string& path);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
2019-01-21 17:58:20 +01:00
|
|
|
void opened(WalletModel* wallet_model);
|
|
|
|
|
|
|
|
private:
|
2019-06-21 16:13:15 +02:00
|
|
|
void finish();
|
2019-01-04 19:49:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_QT_WALLETCONTROLLER_H
|