Bitcoin Core  29.1.0
P2P Digital Currency
walletcontroller.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_QT_WALLETCONTROLLER_H
6 #define BITCOIN_QT_WALLETCONTROLLER_H
7 
10 #include <sync.h>
11 #include <util/translation.h>
12 
13 #include <map>
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 #include <QMessageBox>
19 #include <QMutex>
20 #include <QProgressDialog>
21 #include <QThread>
22 #include <QTimer>
23 #include <QString>
24 
25 class ClientModel;
26 class OptionsModel;
27 class PlatformStyle;
28 class WalletModel;
29 
30 namespace interfaces {
31 class Handler;
32 class Node;
33 class Wallet;
34 } // namespace interfaces
35 
36 namespace fs {
37 class path;
38 }
39 
42 class CreateWalletDialog;
44 class OpenWalletActivity;
46 
50 class WalletController : public QObject
51 {
52  Q_OBJECT
53 
54  void removeAndDeleteWallet(WalletModel* wallet_model);
55 
56 public:
57  WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent);
59 
60  WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
61 
64  std::map<std::string, std::pair<bool, std::string>> listWalletDir() const;
65 
66  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
67  void closeAllWallets(QWidget* parent = nullptr);
68 
69 Q_SIGNALS:
70  void walletAdded(WalletModel* wallet_model);
71  void walletRemoved(WalletModel* wallet_model);
72 
73  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
74 
75 private:
76  QThread* const m_activity_thread;
77  QObject* const m_activity_worker;
82  mutable QMutex m_mutex;
83  std::vector<WalletModel*> m_wallets;
84  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
85 
87  friend class MigrateWalletActivity;
88 
90  void removeWallet(WalletModel* wallet_model);
91 };
92 
93 class WalletControllerActivity : public QObject
94 {
95  Q_OBJECT
96 
97 public:
98  WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
99  virtual ~WalletControllerActivity() = default;
100 
101 Q_SIGNALS:
102  void finished();
103 
104 protected:
106  QObject* worker() const { return m_wallet_controller->m_activity_worker; }
107 
108  void showProgressDialog(const QString& title_text, const QString& label_text, bool show_minimized=false);
109 
111  QWidget* const m_parent_widget;
114  std::vector<bilingual_str> m_warning_message;
115 };
116 
117 
119 {
120  Q_OBJECT
121 
122 public:
123  CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
124  virtual ~CreateWalletActivity();
125 
126  void create();
127 
128 Q_SIGNALS:
129  void created(WalletModel* wallet_model);
130 
131 private:
132  void askPassphrase();
133  void createWallet();
134  void finish();
135 
139 };
140 
142 {
143  Q_OBJECT
144 
145 public:
146  OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
147 
148  void open(const std::string& path);
149 
150 Q_SIGNALS:
151  void opened(WalletModel* wallet_model);
152 
153 private:
154  void finish();
155 };
156 
158 {
159  Q_OBJECT
160 
161 public:
162  LoadWalletsActivity(WalletController* wallet_controller, QWidget* parent_widget);
163 
164  void load(bool show_loading_minimized);
165 };
166 
168 {
169  Q_OBJECT
170 
171 public:
172  RestoreWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
173 
174  void restore(const fs::path& backup_file, const std::string& wallet_name);
175 
176 Q_SIGNALS:
177  void restored(WalletModel* wallet_model);
178 
179 private:
180  void finish();
181 };
182 
184 {
185  Q_OBJECT
186 
187 public:
188  MigrateWalletActivity(WalletController* wallet_controller, QWidget* parent) : WalletControllerActivity(wallet_controller, parent) {}
189 
190  void migrate(const std::string& path);
191 
192 Q_SIGNALS:
193  void migrated(WalletModel* wallet_model);
194 
195 private:
197 
198  void finish();
199 };
200 
201 #endif // BITCOIN_QT_WALLETCONTROLLER_H
std::vector< WalletModel * > m_wallets
void showProgressDialog(const QString &title_text, const QString &label_text, bool show_minimized=false)
interfaces::Node & node() const
Bilingual messages:
Definition: translation.h:24
CreateWalletDialog * m_create_wallet_dialog
void closeAllWallets(QWidget *parent=nullptr)
void opened(WalletModel *wallet_model)
const PlatformStyle *const m_platform_style
CreateWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:58
OpenWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
Controller between interfaces::Node, WalletModel instances and the GUI.
LoadWalletsActivity(WalletController *wallet_controller, QWidget *parent_widget)
QObject *const m_activity_worker
MigrateWalletActivity(WalletController *wallet_controller, QWidget *parent)
Filesystem operations and types.
void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, QByteArray transaction)
virtual ~WalletControllerActivity()=default
RestoreWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void migrate(const std::string &path)
void load(bool show_loading_minimized)
void created(WalletModel *wallet_model)
void closeWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
void removeWallet(WalletModel *wallet_model)
Starts the wallet closure procedure.
void restore(const fs::path &backup_file, const std::string &wallet_name)
QWidget *const m_parent_widget
void open(const std::string &path)
void migrated(WalletModel *wallet_model)
std::vector< bilingual_str > m_warning_message
ClientModel & m_client_model
interfaces::Node & m_node
void walletAdded(WalletModel *wallet_model)
Model for Bitcoin network client.
Definition: clientmodel.h:56
void restored(WalletModel *wallet_model)
AskPassphraseDialog * m_passphrase_dialog
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:42
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
Multifunctional dialog to ask for passphrases.
std::map< std::string, std::pair< bool, std::string > > listWalletDir() const
Returns all wallet names in the wallet dir mapped to whether the wallet is loaded.
Dialog for creating wallets.
WalletModel * getOrCreateWallet(std::unique_ptr< interfaces::Wallet > wallet)
void walletRemoved(WalletModel *wallet_model)
QObject * worker() const
WalletControllerActivity(WalletController *wallet_controller, QWidget *parent_widget)
QThread *const m_activity_thread
WalletController(ClientModel &client_model, const PlatformStyle *platform_style, QObject *parent)
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:32
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:70
OptionsModel *const m_options_model
void removeAndDeleteWallet(WalletModel *wallet_model)
WalletController *const m_wallet_controller