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 qint64 getBalance() const;
69 qint64 getBalanceWatchOnly() const;
70 qint64 getStake() const;
71 qint64 getUnconfirmedBalance() const;
72 qint64 getImmatureBalance() const;
73 int getNumTransactions() const;
74 EncryptionStatus getEncryptionStatus() const;
76 // Check address for validity
77 bool validateAddress(const QString &address);
79 // Return status record for SendCoins, contains error id + information
80 struct SendCoinsReturn
82 SendCoinsReturn(StatusCode status=Aborted,
84 QString hex=QString()):
85 status(status), fee(fee), hex(hex) {}
87 qint64 fee; // is used in case status is "AmountWithFeeExceedsBalance"
88 QString hex; // is filled with the transaction hash if status is "OK"
91 // Send coins to a list of recipients
92 SendCoinsReturn sendCoins(const QList<SendCoinsRecipient> &recipients, const CCoinControl *coinControl=NULL);
95 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
96 // Passphrase only needed when unlocking
97 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
98 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
100 bool backupWallet(const QString &filename);
102 bool dumpWallet(const QString &filename);
103 bool importWallet(const QString &filename);
105 void getStakeStats(float &nKernelsRate, float &nCoinDaysRate);
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);
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
125 void CopyFrom(const UnlockContext& rhs);
128 UnlockContext requestUnlock();
130 bool getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const;
131 void getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs);
132 void listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const;
133 bool isLockedCoin(uint256 hash, unsigned int n) const;
134 void lockCoin(COutPoint& output);
135 void unlockCoin(COutPoint& output);
136 void listLockedCoins(std::vector<COutPoint>& vOutpts);
138 CWallet* getWallet();
143 // Wallet has an options model for wallet-specific options
144 // (transaction fee, for example)
145 OptionsModel *optionsModel;
147 AddressTableModel *addressTableModel;
148 MintingTableModel *mintingTableModel;
149 TransactionTableModel *transactionTableModel;
151 // Cache some values to be able to detect changes
152 qint64 cachedBalance;
154 qint64 cachedUnconfirmedBalance;
155 qint64 cachedImmatureBalance;
156 qint64 cachedNumTransactions;
157 EncryptionStatus cachedEncryptionStatus;
162 void subscribeToCoreSignals();
163 void unsubscribeFromCoreSignals();
164 void checkBalanceChanged();
168 /* Wallet status might have changed */
170 /* New transaction, or transaction changed status */
171 void updateTransaction(const QString &hash, int status);
172 /* New, updated or removed address book entry */
173 void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
174 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
175 void pollBalanceChanged();
178 // Signal that balance in wallet changed
179 void balanceChanged(qint64 total, qint64 watchOnly, qint64 stake, qint64 unconfirmedBalance, qint64 immatureBalance);
181 // Number of transactions in wallet changed
182 void numTransactionsChanged(int count);
184 // Encryption status of wallet changed
185 void encryptionStatusChanged(int status);
187 // Signal emitted when wallet needs to be unlocked
188 // It is valid behaviour for listeners to keep the wallet locked after this signal;
189 // this means that the unlocking failed or was cancelled.
190 void requireUnlock();
192 // Asynchronous error notification
193 void error(const QString &title, const QString &message, bool modal);
197 #endif // WALLETMODEL_H