10 class AddressTableModel;
11 class TransactionTableModel;
14 struct 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,
44 Unencrypted, // !wallet->IsCrypted()
45 Locked, // wallet->IsCrypted() && wallet->IsLocked()
46 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
49 OptionsModel *getOptionsModel();
50 AddressTableModel *getAddressTableModel();
51 TransactionTableModel *getTransactionTableModel();
53 qint64 getBalance() const;
54 qint64 getUnconfirmedBalance() const;
55 int getNumTransactions() const;
56 EncryptionStatus getEncryptionStatus() const;
58 // Check address for validity
59 bool validateAddress(const QString &address);
61 // Return status record for SendCoins, contains error id + information
62 struct SendCoinsReturn
64 SendCoinsReturn(StatusCode status,
66 QString hex=QString()):
67 status(status), fee(fee), hex(hex) {}
69 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
70 QString hex; // is filled with the transaction hash if status is "OK"
73 // Send coins to a list of recipients
74 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
77 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
78 // Passphrase only needed when unlocking
79 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
80 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
82 // RAI object for unlocking wallet, returned by requestUnlock()
86 UnlockContext(WalletModel *wallet, bool valid, bool relock);
89 bool isValid() const { return valid; }
91 // Copy operator and constructor transfer the context
92 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
93 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
97 mutable bool relock; // mutable, as it can be set to false by copying
99 void CopyFrom(const UnlockContext& rhs);
102 UnlockContext requestUnlock();
107 // Wallet has an options model for wallet-specific options
108 // (transaction fee, for example)
109 OptionsModel *optionsModel;
111 AddressTableModel *addressTableModel;
112 TransactionTableModel *transactionTableModel;
114 // Cache some values to be able to detect changes
115 qint64 cachedBalance;
116 qint64 cachedUnconfirmedBalance;
117 qint64 cachedNumTransactions;
118 EncryptionStatus cachedEncryptionStatus;
121 // Signal that balance in wallet changed
122 void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
124 // Number of transactions in wallet changed
125 void numTransactionsChanged(int count);
127 // Encryption status of wallet changed
128 void encryptionStatusChanged(int status);
130 // Signal emitted when wallet needs to be unlocked
131 // It is valid behaviour for listeners to keep the wallet locked after this signal;
132 // this means that the unlocking failed or was cancelled.
133 void requireUnlock();
135 // Asynchronous error notification
136 void error(const QString &title, const QString &message);
145 #endif // WALLETMODEL_H