Bitcoin Core  0.20.99
P2P Digital Currency
walletcontroller.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 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 
38 class CreateWalletDialog;
39 class OpenWalletActivity;
41 
45 class WalletController : public QObject
46 {
47  Q_OBJECT
48 
49  void removeAndDeleteWallet(WalletModel* wallet_model);
50 
51 public:
52  WalletController(ClientModel& client_model, const PlatformStyle* platform_style, QObject* parent);
54 
56  std::vector<WalletModel*> getOpenWallets() const;
57 
58  WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
59 
62  std::map<std::string, bool> listWalletDir() const;
63 
64  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
65 
66 Q_SIGNALS:
67  void walletAdded(WalletModel* wallet_model);
68  void walletRemoved(WalletModel* wallet_model);
69 
70  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
71 
72 private:
73  QThread* const m_activity_thread;
74  QObject* const m_activity_worker;
79  mutable QMutex m_mutex;
80  std::vector<WalletModel*> m_wallets;
81  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
82 
84 };
85 
86 class WalletControllerActivity : public QObject
87 {
88  Q_OBJECT
89 
90 public:
91  WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
92  virtual ~WalletControllerActivity();
93 
94 Q_SIGNALS:
95  void finished();
96 
97 protected:
98  interfaces::Node& node() const { return m_wallet_controller->m_node; }
99  QObject* worker() const { return m_wallet_controller->m_activity_worker; }
100 
101  void showProgressDialog(const QString& label_text);
102  void destroyProgressDialog();
103 
105  QWidget* const m_parent_widget;
106  QProgressDialog* m_progress_dialog{nullptr};
107  WalletModel* m_wallet_model{nullptr};
109  std::vector<bilingual_str> m_warning_message;
110 };
111 
112 
114 {
115  Q_OBJECT
116 
117 public:
118  CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
119  virtual ~CreateWalletActivity();
120 
121  void create();
122 
123 Q_SIGNALS:
124  void created(WalletModel* wallet_model);
125 
126 private:
127  void askPassphrase();
128  void createWallet();
129  void finish();
130 
132  CreateWalletDialog* m_create_wallet_dialog{nullptr};
133  AskPassphraseDialog* m_passphrase_dialog{nullptr};
134 };
135 
137 {
138  Q_OBJECT
139 
140 public:
141  OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
142 
143  void open(const std::string& path);
144 
145 Q_SIGNALS:
146  void opened(WalletModel* wallet_model);
147 
148 private:
149  void finish();
150 };
151 
152 #endif // BITCOIN_QT_WALLETCONTROLLER_H
std::vector< WalletModel * > m_wallets
interfaces::Node & node() const
Bilingual messages:
Definition: translation.h:16
const PlatformStyle *const m_platform_style
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:60
Controller between interfaces::Node, WalletModel instances and the GUI.
QObject *const m_activity_worker
QWidget *const m_parent_widget
std::vector< bilingual_str > m_warning_message
ClientModel & m_client_model
interfaces::Node & m_node
Model for Bitcoin network client.
Definition: clientmodel.h:44
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:36
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:51
Multifunctional dialog to ask for passphrases.
Dialog for creating wallets.
QObject * worker() const
QThread *const m_activity_thread
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:41
OptionsModel *const m_options_model
WalletController *const m_wallet_controller