6 #include "allocators.h" /* for SecureString */
9 class AddressTableModel;
10 class TransactionTableModel;
13 class SendCoinsRecipient
21 /** Interface to Bitcoin wallet from Qt view code. */
22 class WalletModel : public QObject
26 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
28 enum StatusCode // Returned by sendCoins
34 AmountWithFeeExceedsBalance,
36 TransactionCreationFailed, // Error returned when wallet is still locked
37 TransactionCommitFailed,
43 Unencrypted, // !wallet->IsCrypted()
44 Locked, // wallet->IsCrypted() && wallet->IsLocked()
45 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
48 OptionsModel *getOptionsModel();
49 AddressTableModel *getAddressTableModel();
50 TransactionTableModel *getTransactionTableModel();
52 qint64 getBalance() const;
53 qint64 getUnconfirmedBalance() const;
54 int getNumTransactions() const;
55 EncryptionStatus getEncryptionStatus() const;
57 // Check address for validity
58 bool validateAddress(const QString &address);
60 // Return status record for SendCoins, contains error id + information
61 struct SendCoinsReturn
63 SendCoinsReturn(StatusCode status,
65 QString hex=QString()):
66 status(status), fee(fee), hex(hex) {}
68 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
69 QString hex; // is filled with the transaction hash if status is "OK"
72 // Send coins to a list of recipients
73 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
76 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
77 // Passphrase only needed when unlocking
78 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
79 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
81 bool backupWallet(const QString &filename);
83 // RAI object for unlocking wallet, returned by requestUnlock()
87 UnlockContext(WalletModel *wallet, bool valid, bool relock);
90 bool isValid() const { return valid; }
92 // Copy operator and constructor transfer the context
93 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
94 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
98 mutable bool relock; // mutable, as it can be set to false by copying
100 void CopyFrom(const UnlockContext& rhs);
103 UnlockContext requestUnlock();
108 // Wallet has an options model for wallet-specific options
109 // (transaction fee, for example)
110 OptionsModel *optionsModel;
112 AddressTableModel *addressTableModel;
113 TransactionTableModel *transactionTableModel;
115 // Cache some values to be able to detect changes
116 qint64 cachedBalance;
117 qint64 cachedUnconfirmedBalance;
118 qint64 cachedNumTransactions;
119 EncryptionStatus cachedEncryptionStatus;
122 // Signal that balance in wallet changed
123 void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
125 // Number of transactions in wallet changed
126 void numTransactionsChanged(int count);
128 // Encryption status of wallet changed
129 void encryptionStatusChanged(int status);
131 // Signal emitted when wallet needs to be unlocked
132 // It is valid behaviour for listeners to keep the wallet locked after this signal;
133 // this means that the unlocking failed or was cancelled.
134 void requireUnlock();
136 // Asynchronous error notification
137 void error(const QString &title, const QString &message, bool modal);
141 void updateAddressList();
145 #endif // WALLETMODEL_H