Bitcoin ABC  0.22.13
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 
8 #include <interfaces/wallet.h>
10 #include <qt/walletmodel.h>
12 #include <sync.h>
13 #include <util/translation.h>
14 
15 #include <QMutex>
16 
17 #include <map>
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include <QMessageBox>
23 #include <QProgressDialog>
24 #include <QString>
25 #include <QThread>
26 #include <QTimer>
27 
28 class ClientModel;
29 class OptionsModel;
30 class PlatformStyle;
31 class WalletModel;
32 
33 namespace interfaces {
34 class Handler;
35 class Node;
36 class Wallet;
37 } // namespace interfaces
38 
41 class CreateWalletDialog;
42 class OpenWalletActivity;
44 
48 class WalletController : public QObject {
49  Q_OBJECT
50 
51  void removeAndDeleteWallet(WalletModel *wallet_model);
52 
53 public:
54  WalletController(ClientModel &client_model,
55  const PlatformStyle *platform_style, QObject *parent);
57 
59  std::vector<WalletModel *> getOpenWallets() const;
60 
61  WalletModel *getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
62 
65  std::map<std::string, bool> listWalletDir() const;
66 
67  void closeWallet(WalletModel *wallet_model, QWidget *parent = nullptr);
68 
69 Q_SIGNALS:
70  void walletAdded(WalletModel *wallet_model);
71  void walletRemoved(WalletModel *wallet_model);
72 
73  void coinsSent(interfaces::Wallet &wallet, SendCoinsRecipient recipient,
74  QByteArray transaction);
75 
76 private:
77  QThread *const m_activity_thread;
78  QObject *const m_activity_worker;
83  mutable QMutex m_mutex;
84  std::vector<WalletModel *> m_wallets;
85  std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
86 
88 };
89 
90 class WalletControllerActivity : public QObject {
91  Q_OBJECT
92 
93 public:
94  WalletControllerActivity(WalletController *wallet_controller,
95  QWidget *parent_widget,
96  const CChainParams &chainparams);
97  virtual ~WalletControllerActivity();
98 
99 Q_SIGNALS:
100  void finished();
101 
102 protected:
103  interfaces::Node &node() const { return m_wallet_controller->m_node; }
104  QObject *worker() const { return m_wallet_controller->m_activity_worker; }
105 
106  void showProgressDialog(const QString &label_text);
107  void destroyProgressDialog();
108 
110  QWidget *const m_parent_widget;
111  QProgressDialog *m_progress_dialog{nullptr};
112  WalletModel *m_wallet_model{nullptr};
114  std::vector<bilingual_str> m_warning_message;
115 
117 };
118 
120  Q_OBJECT
121 
122 public:
123  CreateWalletActivity(WalletController *wallet_controller,
124  QWidget *parent_widget,
125  const CChainParams &chainparams);
126  virtual ~CreateWalletActivity();
127 
128  void create();
129 
130 Q_SIGNALS:
131  void created(WalletModel *wallet_model);
132 
133 private:
134  void askPassphrase();
135  void createWallet();
136  void finish();
137 
139  CreateWalletDialog *m_create_wallet_dialog{nullptr};
140  AskPassphraseDialog *m_passphrase_dialog{nullptr};
141 };
142 
144  Q_OBJECT
145 
146 public:
147  OpenWalletActivity(WalletController *wallet_controller,
148  QWidget *parent_widget, const CChainParams &chainparams);
149 
150  void open(const std::string &path);
151 
152 Q_SIGNALS:
153  void opened(WalletModel *wallet_model);
154 
155 private:
156  void finish();
157 };
158 
159 #endif // BITCOIN_QT_WALLETCONTROLLER_H
interfaces::Node & node() const
Bilingual messages:
Definition: translation.h:17
const PlatformStyle *const m_platform_style
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:56
Controller between interfaces::Node, WalletModel instances and the GUI.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:47
QObject *const m_activity_worker
const CChainParams & m_chainparams
QWidget *const m_parent_widget
Interface for accessing a wallet.
Definition: wallet.h:56
std::vector< bilingual_str > m_warning_message
ClientModel & m_client_model
interfaces::Node & m_node
Model for Bitcoin network client.
Definition: clientmodel.h:34
std::vector< WalletModel * > m_wallets
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:48
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:47
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:45
OptionsModel *const m_options_model
WalletController *const m_wallet_controller