8 #include "allocators.h" /* for SecureString */
11 class AddressTableModel;
12 class TransactionTableModel;
13 class MintingTableModel;
26 class SendCoinsRecipient
34 /** Interface to Bitcoin wallet from Qt view code. */
35 class WalletModel : public QObject
40 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
43 enum StatusCode // Returned by sendCoins
49 AmountWithFeeExceedsBalance,
51 TransactionCreationFailed, // Error returned when wallet is still locked
52 TransactionCommitFailed,
58 Unencrypted, // !wallet->IsCrypted()
59 Locked, // wallet->IsCrypted() && wallet->IsLocked()
60 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
63 OptionsModel *getOptionsModel();
64 AddressTableModel *getAddressTableModel();
65 MintingTableModel *getMintingTableModel();
66 TransactionTableModel *getTransactionTableModel();
68 bool haveWatchOnly() const;
69 qint64 getBalance() const;
70 qint64 getBalanceWatchOnly() const;
71 qint64 getStake() const;
72 qint64 getUnconfirmedBalance() const;
73 qint64 getImmatureBalance() const;
74 int getNumTransactions() const;
75 EncryptionStatus getEncryptionStatus() const;
77 // Check address for validity
78 bool validateAddress(const QString &address);
80 // Return status record for SendCoins, contains error id + information
81 struct SendCoinsReturn
83 SendCoinsReturn(StatusCode status=Aborted,
85 QString hex=QString()):
86 status(status), fee(fee), hex(hex) {}
88 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
89 QString hex; // is filled with the transaction hash if status is "OK"
92 // Send coins to a list of recipients
93 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients, const CCoinControl *coinControl=NULL);
96 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
97 // Passphrase only needed when unlocking
98 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
99 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
101 bool backupWallet(const QString &filename);
103 bool dumpWallet(const QString &filename);
104 bool importWallet(const QString &filename);
106 void getStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight);
108 // RAI object for unlocking wallet, returned by requestUnlock()
112 UnlockContext(WalletModel *wallet, bool valid, bool relock, bool mintflag);
115 bool isValid() const { return valid; }
117 // Copy operator and constructor transfer the context
118 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
119 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
123 mutable bool relock; // mutable, as it can be set to false by copying
126 void CopyFrom(const UnlockContext& rhs);
129 UnlockContext requestUnlock();
131 bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
132 void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
133 void listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const;
134 bool isLockedCoin(uint256 hash, unsigned int n) const;
135 void lockCoin(COutPoint& output);
136 void unlockCoin(COutPoint& output);
137 void listLockedCoins(std::vector<COutPoint>& vOutpts);
139 CWallet* getWallet();
145 // Wallet has an options model for wallet-specific options
146 // (transaction fee, for example)
147 OptionsModel *optionsModel;
149 AddressTableModel *addressTableModel;
150 MintingTableModel *mintingTableModel;
151 TransactionTableModel *transactionTableModel;
153 // Cache some values to be able to detect changes
154 qint64 cachedBalance;
156 qint64 cachedUnconfirmedBalance;
157 qint64 cachedImmatureBalance;
158 qint64 cachedNumTransactions;
159 EncryptionStatus cachedEncryptionStatus;
164 void subscribeToCoreSignals();
165 void unsubscribeFromCoreSignals();
166 void checkBalanceChanged();
169 /* Wallet status might have changed */
171 /* New transaction, or transaction changed status */
172 void updateTransaction(const QString &hash, int status);
173 /* New, updated or removed address book entry */
174 void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
175 /* Watchonly added */
176 void updateWatchOnlyFlag(bool fHaveWatchonly);
177 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
178 void pollBalanceChanged();
181 // Signal that balance in wallet changed
182 void balanceChanged(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
184 // Number of transactions in wallet changed
185 void numTransactionsChanged(int count);
187 // Encryption status of wallet changed
188 void encryptionStatusChanged(int status);
190 // Signal emitted when wallet needs to be unlocked
191 // It is valid behaviour for listeners to keep the wallet locked after this signal;
192 // this means that the unlocking failed or was cancelled.
193 void requireUnlock();
195 // Asynchronous error notification
196 void error(const QString &title, const QString &message, bool modal);
198 // Watch-only address added
199 void notifyWatchonlyChanged(bool fHaveWatchonly);
203 #endif // WALLETMODEL_H