6 #include "allocators.h" /* for SecureString */
9 class AddressTableModel;
10 class TransactionTableModel;
17 class SendCoinsRecipient
25 /** Interface to Bitcoin wallet from Qt view code. */
26 class WalletModel : public QObject
31 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
34 enum StatusCode // Returned by sendCoins
40 AmountWithFeeExceedsBalance,
42 TransactionCreationFailed, // Error returned when wallet is still locked
43 TransactionCommitFailed,
49 Unencrypted, // !wallet->IsCrypted()
50 Locked, // wallet->IsCrypted() && wallet->IsLocked()
51 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
54 OptionsModel *getOptionsModel();
55 AddressTableModel *getAddressTableModel();
56 TransactionTableModel *getTransactionTableModel();
58 qint64 getBalance() const;
59 qint64 getStake() const;
60 qint64 getUnconfirmedBalance() const;
61 qint64 getImmatureBalance() const;
62 int getNumTransactions() const;
63 EncryptionStatus getEncryptionStatus() const;
65 // Check address for validity
66 bool validateAddress(const QString &address);
68 // Return status record for SendCoins, contains error id + information
69 struct SendCoinsReturn
71 SendCoinsReturn(StatusCode status,
73 QString hex=QString()):
74 status(status), fee(fee), hex(hex) {}
76 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
77 QString hex; // is filled with the transaction hash if status is "OK"
80 // Send coins to a list of recipients
81 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
84 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
85 // Passphrase only needed when unlocking
86 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
87 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
89 bool backupWallet(const QString &filename);
91 // RAI object for unlocking wallet, returned by requestUnlock()
95 UnlockContext(WalletModel *wallet, bool valid, bool relock);
98 bool isValid() const { return valid; }
100 // Copy operator and constructor transfer the context
101 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
102 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
106 mutable bool relock; // mutable, as it can be set to false by copying
108 void CopyFrom(const UnlockContext& rhs);
111 UnlockContext requestUnlock();
116 // Wallet has an options model for wallet-specific options
117 // (transaction fee, for example)
118 OptionsModel *optionsModel;
120 AddressTableModel *addressTableModel;
121 TransactionTableModel *transactionTableModel;
123 // Cache some values to be able to detect changes
124 qint64 cachedBalance;
126 qint64 cachedUnconfirmedBalance;
127 qint64 cachedImmatureBalance;
128 qint64 cachedNumTransactions;
129 EncryptionStatus cachedEncryptionStatus;
134 void subscribeToCoreSignals();
135 void unsubscribeFromCoreSignals();
136 void checkBalanceChanged();
140 /* Wallet status might have changed */
142 /* New transaction, or transaction changed status */
143 void updateTransaction(const QString &hash, int status);
144 /* New, updated or removed address book entry */
145 void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
146 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
147 void pollBalanceChanged();
150 // Signal that balance in wallet changed
151 void balanceChanged(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
153 // Number of transactions in wallet changed
154 void numTransactionsChanged(int count);
156 // Encryption status of wallet changed
157 void encryptionStatusChanged(int status);
159 // Signal emitted when wallet needs to be unlocked
160 // It is valid behaviour for listeners to keep the wallet locked after this signal;
161 // this means that the unlocking failed or was cancelled.
162 void requireUnlock();
164 // Asynchronous error notification
165 void error(const QString &title, const QString &message, bool modal);
169 #endif // WALLETMODEL_H