8 #include "allocators.h" /* for SecureString */
11 class AddressTableModel;
12 class TransactionTableModel;
25 class SendCoinsRecipient
33 /** Interface to Bitcoin wallet from Qt view code. */
34 class WalletModel : public QObject
39 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
42 enum StatusCode // Returned by sendCoins
48 AmountWithFeeExceedsBalance,
50 TransactionCreationFailed, // Error returned when wallet is still locked
51 TransactionCommitFailed,
57 Unencrypted, // !wallet->IsCrypted()
58 Locked, // wallet->IsCrypted() && wallet->IsLocked()
59 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
62 OptionsModel *getOptionsModel();
63 AddressTableModel *getAddressTableModel();
64 TransactionTableModel *getTransactionTableModel();
66 qint64 getBalance() const;
67 qint64 getBalanceWatchOnly() const;
68 qint64 getStake() const;
69 qint64 getUnconfirmedBalance() const;
70 qint64 getImmatureBalance() const;
71 int getNumTransactions() const;
72 EncryptionStatus getEncryptionStatus() const;
74 // Check address for validity
75 bool validateAddress(const QString &address);
77 // Return status record for SendCoins, contains error id + information
78 struct SendCoinsReturn
80 SendCoinsReturn(StatusCode status=Aborted,
82 QString hex=QString()):
83 status(status), fee(fee), hex(hex) {}
85 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
86 QString hex; // is filled with the transaction hash if status is "OK"
89 // Send coins to a list of recipients
90 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients, const CCoinControl *coinControl=NULL);
93 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
94 // Passphrase only needed when unlocking
95 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
96 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
98 bool backupWallet(const QString &filename);
100 bool dumpWallet(const QString &filename);
101 bool importWallet(const QString &filename);
103 void getStakeWeight(quint64& nMinWeight, quint64& nMaxWeight, quint64& nWeight);
104 void getStakeWeightFromValue(const qint64& nTime, const qint64& nValue, quint64& nWeight);
106 // RAI object for unlocking wallet, returned by requestUnlock()
110 UnlockContext(WalletModel *wallet, bool valid, bool relock);
113 bool isValid() const { return valid; }
115 // Copy operator and constructor transfer the context
116 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
117 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
121 mutable bool relock; // mutable, as it can be set to false by copying
123 void CopyFrom(const UnlockContext& rhs);
126 UnlockContext requestUnlock();
128 bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
129 void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
130 void listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const;
131 bool isLockedCoin(uint256 hash, unsigned int n) const;
132 void lockCoin(COutPoint& output);
133 void unlockCoin(COutPoint& output);
134 void listLockedCoins(std::vector<COutPoint>& vOutpts);
139 // Wallet has an options model for wallet-specific options
140 // (transaction fee, for example)
141 OptionsModel *optionsModel;
143 AddressTableModel *addressTableModel;
144 TransactionTableModel *transactionTableModel;
146 // Cache some values to be able to detect changes
147 qint64 cachedBalance;
149 qint64 cachedUnconfirmedBalance;
150 qint64 cachedImmatureBalance;
151 qint64 cachedNumTransactions;
152 EncryptionStatus cachedEncryptionStatus;
157 void subscribeToCoreSignals();
158 void unsubscribeFromCoreSignals();
159 void checkBalanceChanged();
163 /* Wallet status might have changed */
165 /* New transaction, or transaction changed status */
166 void updateTransaction(const QString &hash, int status);
167 /* New, updated or removed address book entry */
168 void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
169 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
170 void pollBalanceChanged();
173 // Signal that balance in wallet changed
174 void balanceChanged(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
176 // Number of transactions in wallet changed
177 void numTransactionsChanged(int count);
179 // Encryption status of wallet changed
180 void encryptionStatusChanged(int status);
182 // Signal emitted when wallet needs to be unlocked
183 // It is valid behaviour for listeners to keep the wallet locked after this signal;
184 // this means that the unlocking failed or was cancelled.
185 void requireUnlock();
187 // Asynchronous error notification
188 void error(const QString &title, const QString &message, bool modal);
192 #endif // WALLETMODEL_H