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 getStake() const;
59 qint64 getUnconfirmedBalance() const;
60 qint64 getImmatureBalance() const;
61 int getNumTransactions() const;
62 EncryptionStatus getEncryptionStatus() const;
64 // Check address for validity
65 bool validateAddress(const QString &address);
67 // Return status record for SendCoins, contains error id + information
68 struct SendCoinsReturn
70 SendCoinsReturn(StatusCode status,
72 QString hex=QString()):
73 status(status), fee(fee), hex(hex) {}
75 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
76 QString hex; // is filled with the transaction hash if status is "OK"
79 // Send coins to a list of recipients
80 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
83 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
84 // Passphrase only needed when unlocking
85 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
86 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
88 bool backupWallet(const QString &filename);
90 // RAI object for unlocking wallet, returned by requestUnlock()
94 UnlockContext(WalletModel *wallet, bool valid, bool relock);
97 bool isValid() const { return valid; }
99 // Copy operator and constructor transfer the context
100 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
101 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
105 mutable bool relock; // mutable, as it can be set to false by copying
107 void CopyFrom(const UnlockContext& rhs);
110 UnlockContext requestUnlock();
115 // Wallet has an options model for wallet-specific options
116 // (transaction fee, for example)
117 OptionsModel *optionsModel;
119 AddressTableModel *addressTableModel;
120 TransactionTableModel *transactionTableModel;
122 // Cache some values to be able to detect changes
123 qint64 cachedBalance;
125 qint64 cachedUnconfirmedBalance;
126 qint64 cachedImmatureBalance;
127 qint64 cachedNumTransactions;
128 EncryptionStatus cachedEncryptionStatus;
133 void subscribeToCoreSignals();
134 void unsubscribeFromCoreSignals();
135 void checkBalanceChanged();
138 // Signal that balance in wallet changed
139 void balanceChanged(qint64 balance, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
141 // Number of transactions in wallet changed
142 void numTransactionsChanged(int count);
144 // Encryption status of wallet changed
145 void encryptionStatusChanged(int status);
147 // Signal emitted when wallet needs to be unlocked
148 // It is valid behaviour for listeners to keep the wallet locked after this signal;
149 // this means that the unlocking failed or was cancelled.
150 void requireUnlock();
152 // Asynchronous error notification
153 void error(const QString &title, const QString &message, bool modal);
156 /* Wallet status might have changed */
158 /* New transaction, or transaction changed status */
159 void updateTransaction(const QString &hash, int status);
160 /* New, updated or removed address book entry */
161 void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
162 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
163 void pollBalanceChanged();
167 #endif // WALLETMODEL_H