]> Git Repo - VerusCoin.git/blob - src/qt/walletmodel.h
Bitcoin-Qt: remove obsolete modal flag from GUI APIs
[VerusCoin.git] / src / qt / walletmodel.h
1 #ifndef WALLETMODEL_H
2 #define WALLETMODEL_H
3
4 #include <QObject>
5
6 #include "allocators.h" /* for SecureString */
7
8 class OptionsModel;
9 class AddressTableModel;
10 class TransactionTableModel;
11 class CWallet;
12
13 QT_BEGIN_NAMESPACE
14 class QTimer;
15 QT_END_NAMESPACE
16
17 class SendCoinsRecipient
18 {
19 public:
20     QString address;
21     QString label;
22     qint64 amount;
23 };
24
25 /** Interface to Bitcoin wallet from Qt view code. */
26 class WalletModel : public QObject
27 {
28     Q_OBJECT
29 public:
30     explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
31     ~WalletModel();
32
33     enum StatusCode // Returned by sendCoins
34     {
35         OK,
36         InvalidAmount,
37         InvalidAddress,
38         AmountExceedsBalance,
39         AmountWithFeeExceedsBalance,
40         DuplicateAddress,
41         TransactionCreationFailed, // Error returned when wallet is still locked
42         TransactionCommitFailed,
43         Aborted
44     };
45
46     enum EncryptionStatus
47     {
48         Unencrypted,  // !wallet->IsCrypted()
49         Locked,       // wallet->IsCrypted() && wallet->IsLocked()
50         Unlocked      // wallet->IsCrypted() && !wallet->IsLocked()
51     };
52
53     OptionsModel *getOptionsModel();
54     AddressTableModel *getAddressTableModel();
55     TransactionTableModel *getTransactionTableModel();
56
57     qint64 getBalance() const;
58     qint64 getUnconfirmedBalance() const;
59     qint64 getImmatureBalance() const;
60     int getNumTransactions() const;
61     EncryptionStatus getEncryptionStatus() const;
62
63     // Check address for validity
64     bool validateAddress(const QString &address);
65
66     // Return status record for SendCoins, contains error id + information
67     struct SendCoinsReturn
68     {
69         SendCoinsReturn(StatusCode status,
70                          qint64 fee=0,
71                          QString hex=QString()):
72             status(status), fee(fee), hex(hex) {}
73         StatusCode status;
74         qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
75         QString hex; // is filled with the transaction hash if status is "OK"
76     };
77
78     // Send coins to a list of recipients
79     SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
80
81     // Wallet encryption
82     bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
83     // Passphrase only needed when unlocking
84     bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
85     bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
86     // Wallet backup
87     bool backupWallet(const QString &filename);
88
89     // RAI object for unlocking wallet, returned by requestUnlock()
90     class UnlockContext
91     {
92     public:
93         UnlockContext(WalletModel *wallet, bool valid, bool relock);
94         ~UnlockContext();
95
96         bool isValid() const { return valid; }
97
98         // Copy operator and constructor transfer the context
99         UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
100         UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
101     private:
102         WalletModel *wallet;
103         bool valid;
104         mutable bool relock; // mutable, as it can be set to false by copying
105
106         void CopyFrom(const UnlockContext& rhs);
107     };
108
109     UnlockContext requestUnlock();
110
111 private:
112     CWallet *wallet;
113
114     // Wallet has an options model for wallet-specific options
115     // (transaction fee, for example)
116     OptionsModel *optionsModel;
117
118     AddressTableModel *addressTableModel;
119     TransactionTableModel *transactionTableModel;
120
121     // Cache some values to be able to detect changes
122     qint64 cachedBalance;
123     qint64 cachedUnconfirmedBalance;
124     qint64 cachedImmatureBalance;
125     qint64 cachedNumTransactions;
126     EncryptionStatus cachedEncryptionStatus;
127     int cachedNumBlocks;
128
129     QTimer *pollTimer;
130
131     void subscribeToCoreSignals();
132     void unsubscribeFromCoreSignals();
133     void checkBalanceChanged();
134
135 signals:
136     // Signal that balance in wallet changed
137     void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance);
138
139     // Number of transactions in wallet changed
140     void numTransactionsChanged(int count);
141
142     // Encryption status of wallet changed
143     void encryptionStatusChanged(int status);
144
145     // Signal emitted when wallet needs to be unlocked
146     // It is valid behaviour for listeners to keep the wallet locked after this signal;
147     // this means that the unlocking failed or was cancelled.
148     void requireUnlock();
149
150     // Asynchronous message notification
151     void message(const QString &title, const QString &message, unsigned int style);
152
153 public slots:
154     /* Wallet status might have changed */
155     void updateStatus();
156     /* New transaction, or transaction changed status */
157     void updateTransaction(const QString &hash, int status);
158     /* New, updated or removed address book entry */
159     void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
160     /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
161     void pollBalanceChanged();
162 };
163
164
165 #endif // WALLETMODEL_H
This page took 0.033414 seconds and 4 git commands to generate.