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
30 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
33 enum StatusCode // Returned by sendCoins
39 AmountWithFeeExceedsBalance,
41 TransactionCreationFailed, // Error returned when wallet is still locked
42 TransactionCommitFailed,
48 Unencrypted, // !wallet->IsCrypted()
49 Locked, // wallet->IsCrypted() && wallet->IsLocked()
50 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
53 OptionsModel *getOptionsModel();
54 AddressTableModel *getAddressTableModel();
55 TransactionTableModel *getTransactionTableModel();
57 qint64 getBalance() const;
58 qint64 getUnconfirmedBalance() const;
59 qint64 getImmatureBalance() const;
60 int getNumTransactions() const;
61 EncryptionStatus getEncryptionStatus() const;
63 // Check address for validity
64 bool validateAddress(const QString &address);
66 // Return status record for SendCoins, contains error id + information
67 struct SendCoinsReturn
69 SendCoinsReturn(StatusCode status,
71 QString hex=QString()):
72 status(status), fee(fee), hex(hex) {}
74 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
75 QString hex; // is filled with the transaction hash if status is "OK"
78 // Send coins to a list of recipients
79 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
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);
87 bool backupWallet(const QString &filename);
89 // RAI object for unlocking wallet, returned by requestUnlock()
93 UnlockContext(WalletModel *wallet, bool valid, bool relock);
96 bool isValid() const { return valid; }
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; }
104 mutable bool relock; // mutable, as it can be set to false by copying
106 void CopyFrom(const UnlockContext& rhs);
109 UnlockContext requestUnlock();
114 // Wallet has an options model for wallet-specific options
115 // (transaction fee, for example)
116 OptionsModel *optionsModel;
118 AddressTableModel *addressTableModel;
119 TransactionTableModel *transactionTableModel;
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;
131 void subscribeToCoreSignals();
132 void unsubscribeFromCoreSignals();
133 void checkBalanceChanged();
136 // Signal that balance in wallet changed
137 void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance);
139 // Number of transactions in wallet changed
140 void numTransactionsChanged(int count);
142 // Encryption status of wallet changed
143 void encryptionStatusChanged(int status);
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();
150 // Asynchronous message notification
151 void message(const QString &title, const QString &message, unsigned int style);
154 /* Wallet status might have changed */
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();
165 #endif // WALLETMODEL_H