6 #include "allocators.h" /* for SecureString */
8 #include "walletmodeltransaction.h"
9 #include "paymentrequestplus.h"
12 class AddressTableModel;
13 class TransactionTableModel;
15 class WalletModelTransaction;
21 class SendCoinsRecipient
24 explicit SendCoinsRecipient() : amount(0) { }
25 explicit SendCoinsRecipient(const QString &addr, const QString &label, quint64 amount, const QString &message):
26 address(addr), label(label), amount(amount), message(message) {}
33 // If from a payment request, paymentRequest.IsInitialized() will be true
34 PaymentRequestPlus paymentRequest;
35 QString authenticatedMerchant; // Empty if no authentication or invalid signature/cert/etc.
38 /** Interface to Bitcoin wallet from Qt view code. */
39 class WalletModel : public QObject
44 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
47 enum StatusCode // Returned by sendCoins
53 AmountWithFeeExceedsBalance,
55 TransactionCreationFailed, // Error returned when wallet is still locked
56 TransactionCommitFailed,
62 Unencrypted, // !wallet->IsCrypted()
63 Locked, // wallet->IsCrypted() && wallet->IsLocked()
64 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
67 OptionsModel *getOptionsModel();
68 AddressTableModel *getAddressTableModel();
69 TransactionTableModel *getTransactionTableModel();
71 qint64 getBalance() 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):
88 // prepare transaction for getting txfee before sending coins
89 SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction);
91 // Send coins to a list of recipients
92 SendCoinsReturn sendCoins(WalletModelTransaction &transaction);
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 // RAI object for unlocking wallet, returned by requestUnlock()
106 UnlockContext(WalletModel *wallet, bool valid, bool relock);
109 bool isValid() const { return valid; }
111 // Copy operator and constructor transfer the context
112 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
113 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
117 mutable bool relock; // mutable, as it can be set to false by copying
119 void CopyFrom(const UnlockContext& rhs);
122 UnlockContext requestUnlock();
127 // Wallet has an options model for wallet-specific options
128 // (transaction fee, for example)
129 OptionsModel *optionsModel;
131 AddressTableModel *addressTableModel;
132 TransactionTableModel *transactionTableModel;
134 // Cache some values to be able to detect changes
135 qint64 cachedBalance;
136 qint64 cachedUnconfirmedBalance;
137 qint64 cachedImmatureBalance;
138 qint64 cachedNumTransactions;
139 EncryptionStatus cachedEncryptionStatus;
144 void subscribeToCoreSignals();
145 void unsubscribeFromCoreSignals();
146 void checkBalanceChanged();
149 // Signal that balance in wallet changed
150 void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance);
152 // Number of transactions in wallet changed
153 void numTransactionsChanged(int count);
155 // Encryption status of wallet changed
156 void encryptionStatusChanged(int status);
158 // Signal emitted when wallet needs to be unlocked
159 // It is valid behaviour for listeners to keep the wallet locked after this signal;
160 // this means that the unlocking failed or was cancelled.
161 void requireUnlock();
163 // Asynchronous message notification
164 void message(const QString &title, const QString &message, unsigned int style);
166 // Coins sent: from wallet, to recipient, in (serialized) transaction:
167 void coinsSent(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
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, const QString &purpose, int status);
176 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
177 void pollBalanceChanged();
180 #endif // WALLETMODEL_H