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 getStakeStats(float &nKernelsRate, float &nCoinDaysRate);
107 void getStakeWeightFromValue(const int64_t& nTime, const int64_t& nValue, uint64_t& nWeight);
109 // RAI object for unlocking wallet, returned by requestUnlock()
113 UnlockContext(WalletModel *wallet, bool valid, bool relock, bool mintflag);
116 bool isValid() const { return valid; }
118 // Copy operator and constructor transfer the context
119 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
120 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
124 mutable bool relock; // mutable, as it can be set to false by copying
127 void CopyFrom(const UnlockContext& rhs);
130 UnlockContext requestUnlock();
132 bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
133 void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
134 void listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const;
135 bool isLockedCoin(uint256 hash, unsigned int n) const;
136 void lockCoin(COutPoint& output);
137 void unlockCoin(COutPoint& output);
138 void listLockedCoins(std::vector<COutPoint>& vOutpts);
140 CWallet* getWallet();
146 // Wallet has an options model for wallet-specific options
147 // (transaction fee, for example)
148 OptionsModel *optionsModel;
150 AddressTableModel *addressTableModel;
151 MintingTableModel *mintingTableModel;
152 TransactionTableModel *transactionTableModel;
154 // Cache some values to be able to detect changes
155 qint64 cachedBalance;
157 qint64 cachedUnconfirmedBalance;
158 qint64 cachedImmatureBalance;
159 qint64 cachedNumTransactions;
160 EncryptionStatus cachedEncryptionStatus;
165 void subscribeToCoreSignals();
166 void unsubscribeFromCoreSignals();
167 void checkBalanceChanged();
170 /* Wallet status might have changed */
172 /* New transaction, or transaction changed status */
173 void updateTransaction(const QString &hash, int status);
174 /* New, updated or removed address book entry */
175 void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
176 /* Watchonly added */
177 void updateWatchOnlyFlag(bool fHaveWatchonly);
178 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
179 void pollBalanceChanged();
182 // Signal that balance in wallet changed
183 void balanceChanged(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
185 // Number of transactions in wallet changed
186 void numTransactionsChanged(int count);
188 // Encryption status of wallet changed
189 void encryptionStatusChanged(int status);
191 // Signal emitted when wallet needs to be unlocked
192 // It is valid behaviour for listeners to keep the wallet locked after this signal;
193 // this means that the unlocking failed or was cancelled.
194 void requireUnlock();
196 // Asynchronous error notification
197 void error(const QString &title, const QString &message, bool modal);
199 // Watch-only address added
200 void notifyWatchonlyChanged(bool fHaveWatchonly);
204 #endif // WALLETMODEL_H