Bitcoin Core  0.19.99
P2P Digital Currency
walletcontroller.h
Go to the documentation of this file.
1 // Copyright (c) 2019 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 
12 #include <map>
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 #include <QMessageBox>
18 #include <QMutex>
19 #include <QProgressDialog>
20 #include <QThread>
21 #include <QTimer>
22 #include <QString>
23 
24 class OptionsModel;
25 class PlatformStyle;
26 class WalletModel;
27 
28 namespace interfaces {
29 class Handler;
30 class Node;
31 class Wallet;
32 } // namespace interfaces
33 
36 class CreateWalletDialog;
37 class OpenWalletActivity;
39 
43 class WalletController : public QObject
44 {
45  Q_OBJECT
46 
47  void removeAndDeleteWallet(WalletModel* wallet_model);
48 
49 public:
50  WalletController(interfaces::Node& node, const PlatformStyle* platform_style, OptionsModel* options_model, QObject* parent);
52 
54  std::vector<WalletModel*> getOpenWallets() const;
55 
56  WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
57 
60  std::map<std::string, bool> listWalletDir() const;
61 
62  void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
63 
64 Q_SIGNALS:
65  void walletAdded(WalletModel* wallet_model);
66  void walletRemoved(WalletModel* wallet_model);
67 
68  void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
69 
70 private:
71  QThread* const m_activity_thread;
72  QObject* const m_activity_worker;
76  mutable QMutex m_mutex;
77  std::vector<WalletModel*> m_wallets;
78  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
79 
81 };
82 
83 class WalletControllerActivity : public QObject
84 {
85  Q_OBJECT
86 
87 public:
88  WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
89  virtual ~WalletControllerActivity();
90 
91 Q_SIGNALS:
92  void finished();
93 
94 protected:
95  interfaces::Node& node() const { return m_wallet_controller->m_node; }
96  QObject* worker() const { return m_wallet_controller->m_activity_worker; }
97 
98  void showProgressDialog(const QString& label_text);
99 
101  QWidget* const m_parent_widget;
102  QProgressDialog* m_progress_dialog{nullptr};
103  WalletModel* m_wallet_model{nullptr};
104  std::string m_error_message;
105  std::vector<std::string> m_warning_message;
106 };
107 
108 
110 {
111  Q_OBJECT
112 
113 public:
114  CreateWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
115  virtual ~CreateWalletActivity();
116 
117  void create();
118 
119 Q_SIGNALS:
120  void created(WalletModel* wallet_model);
121 
122 private:
123  void askPassphrase();
124  void createWallet();
125  void finish();
126 
128  CreateWalletDialog* m_create_wallet_dialog{nullptr};
129  AskPassphraseDialog* m_passphrase_dialog{nullptr};
130 };
131 
133 {
134  Q_OBJECT
135 
136 public:
137  OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
138 
139  void open(const std::string& path);
140 
141 Q_SIGNALS:
142  void opened(WalletModel* wallet_model);
143 
144 private:
145  void finish();
146 };
147 
148 #endif // BITCOIN_QT_WALLETCONTROLLER_H
std::vector< WalletModel * > m_wallets
interfaces::Node & node() const
const PlatformStyle *const m_platform_style
std::vector< std::string > m_warning_message
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
interfaces::Node & m_node
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:50
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:39
OptionsModel *const m_options_model
WalletController *const m_wallet_controller