8 class AddressTableModel;
9 class TransactionTableModel;
12 struct SendCoinsRecipient
19 /** Interface to Bitcoin wallet from Qt view code. */
20 class WalletModel : public QObject
24 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
26 enum StatusCode // Returned by sendCoins
32 AmountWithFeeExceedsBalance,
34 TransactionCreationFailed, // Error returned when wallet is still locked
35 TransactionCommitFailed,
42 Unencrypted, // !wallet->IsCrypted()
43 Locked, // wallet->IsCrypted() && wallet->IsLocked()
44 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
47 OptionsModel *getOptionsModel();
48 AddressTableModel *getAddressTableModel();
49 TransactionTableModel *getTransactionTableModel();
51 qint64 getBalance() const;
52 qint64 getUnconfirmedBalance() const;
53 int getNumTransactions() const;
54 EncryptionStatus getEncryptionStatus() const;
56 // Check address for validity
57 bool validateAddress(const QString &address);
59 // Return status record for SendCoins, contains error id + information
60 struct SendCoinsReturn
62 SendCoinsReturn(StatusCode status,
64 QString hex=QString()):
65 status(status), fee(fee), hex(hex) {}
67 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
68 QString hex; // is filled with the transaction hash if status is "OK"
71 // Send coins to a list of recipients
72 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients);
75 bool setWalletEncrypted(bool encrypted, const std::string &passphrase);
76 // Passphrase only needed when unlocking
77 bool setWalletLocked(bool locked, const std::string &passPhrase=std::string());
78 bool changePassphrase(const std::string &oldPass, const std::string &newPass);
80 // RAI object for unlocking wallet, returned by requestUnlock()
84 UnlockContext(WalletModel *wallet, bool valid, bool relock);
87 bool isValid() const { return valid; }
89 // Copy operator and constructor transfer the context
90 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
91 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
95 mutable bool relock; // mutable, as it can be set to false by copying
97 void CopyFrom(const UnlockContext& rhs);
100 UnlockContext requestUnlock();
105 // Wallet has an options model for wallet-specific options
106 // (transaction fee, for example)
107 OptionsModel *optionsModel;
109 AddressTableModel *addressTableModel;
110 TransactionTableModel *transactionTableModel;
112 // Cache some values to be able to detect changes
113 qint64 cachedBalance;
114 qint64 cachedUnconfirmedBalance;
115 qint64 cachedNumTransactions;
116 EncryptionStatus cachedEncryptionStatus;
119 // Signal that balance in wallet changed
120 void balanceChanged(qint64 balance, qint64 unconfirmedBalance);
122 // Number of transactions in wallet changed
123 void numTransactionsChanged(int count);
125 // Encryption status of wallet changed
126 void encryptionStatusChanged(int status);
128 // Signal emitted when wallet needs to be unlocked
129 // It is valid behaviour for listeners to keep the wallet locked after this signal;
130 // this means that the unlocking failed or was cancelled.
131 void requireUnlock();
133 // Asynchronous error notification
134 void error(const QString &title, const QString &message);
143 #endif // WALLETMODEL_H