9 class AddressTableModel;
10 class TransactionTableModel;
13 struct SendCoinsRecipient
20 // Interface to Bitcoin wallet from Qt view code
21 class WalletModel : public QObject
25 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
27 enum StatusCode // Returned by sendCoins
33 AmountWithFeeExceedsBalance,
35 TransactionCreationFailed, // Error returned when wallet is still locked
36 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 // RAI object for unlocking wallet, returned by requestUnlock()
85 UnlockContext(WalletModel *wallet, bool valid, bool relock);
88 bool isValid() const { return valid; }
90 // Copy operator and constructor transfer the context
91 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
92 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
96 mutable bool relock; // mutable, as it can be set to false by copying
98 void CopyFrom(const UnlockContext& rhs);
101 UnlockContext requestUnlock();
106 // Wallet has an options model for wallet-specific options
107 // (transaction fee, for example)
108 OptionsModel *optionsModel;
110 AddressTableModel *addressTableModel;
111 TransactionTableModel *transactionTableModel;
113 // Cache some values to be able to detect changes
114 qint64 cachedBalance;
115 qint64 cachedUnconfirmedBalance;
116 qint64 cachedNumTransactions;
117 EncryptionStatus cachedEncryptionStatus;
120 // Signal that balance in wallet changed
121 void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
123 // Number of transactions in wallet changed
124 void numTransactionsChanged(int count);
126 // Encryption status of wallet changed
127 void encryptionStatusChanged(int status);
129 // Signal emitted when wallet needs to be unlocked
130 // It is valid behaviour for listeners to keep the wallet locked after this signal;
131 // this means that the unlocking failed or was cancelled.
132 void requireUnlock();
134 // Asynchronous error notification
135 void error(const QString &title, const QString &message);
144 #endif // WALLETMODEL_H