Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
walletmodel.h
Go to the documentation of this file.
1// Copyright (c) 2011-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_WALLETMODEL_H
6#define BITCOIN_QT_WALLETMODEL_H
7
8#include <chainparams.h>
9#include <interfaces/wallet.h>
10
11#if defined(HAVE_CONFIG_H)
12#include <config/bitcoin-config.h>
13#endif
14
17
18#include <QObject>
19
20#include <memory>
21#include <vector>
22
24class ClientModel;
25class OptionsModel;
26class PlatformStyle;
31
32class CCoinControl;
33class CKeyID;
34class COutPoint;
35class COutput;
36class CPubKey;
37
38namespace interfaces {
39class Node;
40} // namespace interfaces
41
43class QTimer;
45
47class WalletModel : public QObject {
49
50public:
51 explicit WalletModel(std::unique_ptr<interfaces::Wallet> wallet,
53 const PlatformStyle *platformStyle,
54 QObject *parent = nullptr);
56
57 // Returned by sendCoins
70
72 // !wallet->IsCrypted()
74 // wallet->IsCrypted() && wallet->IsLocked()
76 // wallet->IsCrypted() && !wallet->IsLocked()
78 };
79
84
86
87 // Check address for validity
88 bool validateAddress(const QString &address);
89
90 // Return status record for SendCoins, contains error id + information
98
99 // prepare transaction for getting txfee before sending coins
102
103 // Send coins to a list of recipients
105
106 // Wallet encryption
108 // Passphrase only needed when unlocking
109 bool setWalletLocked(bool locked,
112 const SecureString &newPass);
113
114 // RAI object for unlocking wallet, returned by requestUnlock()
116 public:
119
120 bool isValid() const { return valid; }
121
122 // Copy constructor is disabled.
123 UnlockContext(const UnlockContext &) = delete;
124 // Move operator and constructor transfer the context
127 CopyFrom(std::move(rhs));
128 return *this;
129 }
130
131 private:
133 bool valid;
134 // mutable, as it can be set to false by copying
135 mutable bool relock;
136
138 void CopyFrom(UnlockContext &&rhs);
139 };
140
142
143 void loadReceiveRequests(std::vector<std::string> &vReceiveRequests);
144 bool saveReceiveRequest(const std::string &sAddress, const int64_t nId,
145 const std::string &sRequest);
146
147 static bool isWalletEnabled();
148
149 interfaces::Node &node() const { return m_node; }
150 interfaces::Wallet &wallet() const { return *m_wallet; }
153
154 const CChainParams &getChainParams() const;
155
156 QString getWalletName() const;
157 QString getDisplayName() const;
158
159 bool isMultiwallet();
160
164
166
167private:
168 std::unique_ptr<interfaces::Wallet> m_wallet;
169 std::unique_ptr<interfaces::Handler> m_handler_unload;
170 std::unique_ptr<interfaces::Handler> m_handler_status_changed;
171 std::unique_ptr<interfaces::Handler> m_handler_address_book_changed;
172 std::unique_ptr<interfaces::Handler> m_handler_transaction_changed;
173 std::unique_ptr<interfaces::Handler> m_handler_show_progress;
174 std::unique_ptr<interfaces::Handler> m_handler_watch_only_changed;
175 std::unique_ptr<interfaces::Handler> m_handler_can_get_addrs_changed;
178
181
182 // Wallet has an options model for wallet-specific options (transaction fee,
183 // for example)
185
189
190 // Cache some values to be able to detect changes
194
195 // Block hash denoting when the last balance update was done.
197
201
203 // Signal that balance in wallet changed
205
206 // Encryption status of wallet changed
208
209 // Signal emitted when wallet needs to be unlocked
210 // It is valid behaviour for listeners to keep the wallet locked after this
211 // signal; this means that the unlocking failed or was cancelled.
213
214 // Fired when a message should be reported to the user
215 void message(const QString &title, const QString &message,
216 unsigned int style);
217
218 // Coins sent: from wallet, to recipient, in (serialized) transaction:
221
222 // Show progress dialog e.g. for rescan
223 void showProgress(const QString &title, int nProgress);
224
225 // Watch-only address added
227
228 // Signal that wallet is about to be removed
229 void unload();
230
231 // Notify that there are now keys in the keypool
233
234public Q_SLOTS:
235 /* Starts a timer to periodically update the balance */
236 void startPollBalance();
237
238 /* Wallet status might have changed */
239 void updateStatus();
241 void updateTransaction();
243 void updateAddressBook(const QString &address, const QString &label,
244 bool isMine, const QString &purpose, int status);
251 void pollBalanceChanged();
252};
253
254#endif // BITCOIN_QT_WALLETMODEL_H
Qt model of the address book in the core.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition chainparams.h:80
Coin Control Features.
Definition coincontrol.h:21
A reference to a CKey: the Hash160 of its serialized public key.
Definition pubkey.h:22
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:20
An encapsulated public key.
Definition pubkey.h:31
Model for Bitcoin network client.
Definition clientmodel.h:43
Interface from Qt to configuration data structure for Bitcoin client.
Model for list of recently generated payment requests / bitcoincash: URIs.
UI model for the transaction table of a wallet.
UnlockContext(const UnlockContext &)=delete
UnlockContext(UnlockContext &&obj)
void CopyFrom(UnlockContext &&rhs)
UnlockContext & operator=(UnlockContext &&rhs)
UnlockContext & operator=(const UnlockContext &)=default
Interface to Bitcoin wallet from Qt view code.
Definition walletmodel.h:47
OptionsModel * optionsModel
bool validateAddress(const QString &address)
AddressTableModel * addressTableModel
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
EncryptionStatus cachedEncryptionStatus
ClientModel * m_client_model
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
BlockHash m_cached_last_update_tip
interfaces::Node & m_node
ClientModel & clientModel() const
interfaces::Node & node() const
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
void startPollBalance()
void pollBalanceChanged()
Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so.
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
AddressTableModel * getAddressTableModel() const
RecentRequestsTableModel * recentRequestsTableModel
TransactionTableModel * transactionTableModel
bool setWalletEncrypted(const SecureString &passphrase)
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
BlockHash getLastBlockProcessed() const
void showProgress(const QString &title, int nProgress)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(interfaces::Wallet &wallet, SendCoinsRecipient recipient, QByteArray transaction)
void setClientModel(ClientModel *client_model)
const CChainParams & getChainParams() const
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
void updateStatus()
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
std::unique_ptr< interfaces::Handler > m_handler_unload
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
EncryptionStatus getEncryptionStatus() const
interfaces::Wallet & wallet() const
RecentRequestsTableModel * getRecentRequestsTableModel()
std::unique_ptr< interfaces::Handler > m_handler_status_changed
interfaces::WalletBalances m_cached_balances
bool fForceCheckBalanceChanged
QString getDisplayName() const
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
bool isMultiwallet()
void unsubscribeFromCoreSignals()
void requireUnlock()
void updateTransaction()
New transaction, or transaction changed status.
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
New, updated or removed address book entry.
void canGetAddressesChanged()
QTimer * timer
bool fHaveWatchOnly
void updateWatchOnlyFlag(bool fHaveWatchonly)
Watch-only added.
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
void encryptionStatusChanged()
std::unique_ptr< interfaces::Wallet > m_wallet
UnlockContext requestUnlock()
void balanceChanged(const interfaces::WalletBalances &balances)
static bool isWalletEnabled()
QString getWalletName() const
std::unique_ptr< interfaces::Handler > m_handler_show_progress
void unload()
@ AmountWithFeeExceedsBalance
Definition walletmodel.h:63
@ TransactionCreationFailed
Definition walletmodel.h:66
@ AmountExceedsBalance
Definition walletmodel.h:62
@ PaymentRequestExpired
Definition walletmodel.h:68
void subscribeToCoreSignals()
TransactionTableModel * getTransactionTableModel()
Data model for a walletmodel transaction.
Top-level interface for a bitcoin node (bitcoind process).
Definition node.h:59
Interface for accessing a wallet.
Definition wallet.h:59
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition secure.h:55
A BlockHash is a unqiue identifier for a block.
Definition blockhash.h:13
SendCoinsReturn(StatusCode _status=OK, QString _reasonCommitFailed="")
Definition walletmodel.h:92
Collection of wallet balances.
Definition wallet.h:347