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 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;
124 qint64 cachedUnconfirmedBalance;
125 qint64 cachedImmatureBalance;
126 qint64 cachedNumTransactions;
127 EncryptionStatus cachedEncryptionStatus;
132 void subscribeToCoreSignals();
133 void unsubscribeFromCoreSignals();
134 void checkBalanceChanged();
137 // Signal that balance in wallet changed
138 void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance);
140 // Number of transactions in wallet changed
141 void numTransactionsChanged(int count);
143 // Encryption status of wallet changed
144 void encryptionStatusChanged(int status);
146 // Signal emitted when wallet needs to be unlocked
147 // It is valid behaviour for listeners to keep the wallet locked after this signal;
148 // this means that the unlocking failed or was cancelled.
149 void requireUnlock();
151 // Asynchronous message notification
152 void message(const QString &title, const QString &message, unsigned int style);
155 /* Wallet status might have changed */
157 /* New transaction, or transaction changed status */
158 void updateTransaction(const QString &hash, int status);
159 /* New, updated or removed address book entry */
160 void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
161 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
162 void pollBalanceChanged();
165 #endif // WALLETMODEL_H