Bitcoin Core  27.99.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, bool> listWalletDir() const;
65 
66  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
67  void closeAllWallets(QWidget* parent = nullptr);
68 
69  void migrateWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
70 
71 Q_SIGNALS:
72  void walletAdded(WalletModel* wallet_model);
73  void walletRemoved(WalletModel* wallet_model);
74 
75  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
76 
77 private:
78  QThread* const m_activity_thread;
79  QObject* const m_activity_worker;
84  mutable QMutex m_mutex;
85  std::vector<WalletModel*> m_wallets;
86  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
87 
89  friend class MigrateWalletActivity;
90 };
91 
92 class WalletControllerActivity : public QObject
93 {
94  Q_OBJECT
95 
96 public:
97  WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
98  virtual ~WalletControllerActivity() = default;
99 
100 Q_SIGNALS:
101  void finished();
102 
103 protected:
105  QObject* worker() const { return m_wallet_controller->m_activity_worker; }
106 
107  void showProgressDialog(const QString& title_text, const QString& label_text, bool show_minimized=false);
108 
110  QWidget* const m_parent_widget;
113  std::vector<bilingual_str> m_warning_message;
114 };
115 
116 
118 {
119  Q_OBJECT
120 
121 public:
122  CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
123  virtual ~CreateWalletActivity();
124 
125  void create();
126 
127 Q_SIGNALS:
128  void created(WalletModel* wallet_model);
129 
130 private:
131  void askPassphrase();
132  void createWallet();
133  void finish();
134 
138 };
139 
141 {
142  Q_OBJECT
143 
144 public:
145  OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
146 
147  void open(const std::string& path);
148 
149 Q_SIGNALS:
150  void opened(WalletModel* wallet_model);
151 
152 private:
153  void finish();
154 };
155 
157 {
158  Q_OBJECT
159 
160 public:
161  LoadWalletsActivity(WalletController* wallet_controller, QWidget* parent_widget);
162 
163  void load(bool show_loading_minimized);
164 };
165 
167 {
168  Q_OBJECT
169 
170 public:
171  RestoreWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
172 
173  void restore(const fs::path& backup_file, const std::string& wallet_name);
174 
175 Q_SIGNALS:
176  void restored(WalletModel* wallet_model);
177 
178 private:
179  void finish();
180 };
181 
183 {
184  Q_OBJECT
185 
186 public:
187  MigrateWalletActivity(WalletController* wallet_controller, QWidget* parent) : WalletControllerActivity(wallet_controller, parent) {}
188 
189  void migrate(WalletModel* wallet_model);
190 
191 Q_SIGNALS:
192  void migrated(WalletModel* wallet_model);
193 
194 private:
196 
197  void finish();
198 };
199 
200 #endif // BITCOIN_QT_WALLETCONTROLLER_H
Multifunctional dialog to ask for passphrases.
Model for Bitcoin network client.
Definition: clientmodel.h:54
AskPassphraseDialog * m_passphrase_dialog
CreateWalletDialog * m_create_wallet_dialog
CreateWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void created(WalletModel *wallet_model)
Dialog for creating wallets.
void load(bool show_loading_minimized)
LoadWalletsActivity(WalletController *wallet_controller, QWidget *parent_widget)
void migrate(WalletModel *wallet_model)
MigrateWalletActivity(WalletController *wallet_controller, QWidget *parent)
void migrated(WalletModel *wallet_model)
void opened(WalletModel *wallet_model)
OpenWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
void open(const std::string &path)
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:43
void restore(const fs::path &backup_file, const std::string &wallet_name)
void restored(WalletModel *wallet_model)
RestoreWalletActivity(WalletController *wallet_controller, QWidget *parent_widget)
std::vector< bilingual_str > m_warning_message
QObject * worker() const
WalletController *const m_wallet_controller
interfaces::Node & node() const
void showProgressDialog(const QString &title_text, const QString &label_text, bool show_minimized=false)
virtual ~WalletControllerActivity()=default
WalletControllerActivity(WalletController *wallet_controller, QWidget *parent_widget)
QWidget *const m_parent_widget
Controller between interfaces::Node, WalletModel instances and the GUI.
WalletController(ClientModel &client_model, const PlatformStyle *platform_style, QObject *parent)
WalletModel * getOrCreateWallet(std::unique_ptr< interfaces::Wallet > wallet)
ClientModel & m_client_model
void removeAndDeleteWallet(WalletModel *wallet_model)
void walletAdded(WalletModel *wallet_model)
void closeAllWallets(QWidget *parent=nullptr)
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
QThread *const m_activity_thread
std::map< std::string, bool > listWalletDir() const
Returns all wallet names in the wallet dir mapped to whether the wallet is loaded.
void migrateWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
void coinsSent(WalletModel *wallet_model, SendCoinsRecipient recipient, QByteArray transaction)
QObject *const m_activity_worker
void walletRemoved(WalletModel *wallet_model)
const PlatformStyle *const m_platform_style
interfaces::Node & m_node
void closeWallet(WalletModel *wallet_model, QWidget *parent=nullptr)
OptionsModel *const m_options_model
std::vector< WalletModel * > m_wallets
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:48
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:33
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:70
Filesystem operations and types.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:58
Bilingual messages:
Definition: translation.h:18