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 SendCoinsRecipient() : amount(0) { }
30 // If from a payment request, paymentRequest.IsInitialized() will be true
31 PaymentRequestPlus paymentRequest;
32 QString authenticatedMerchant; // Empty if no authentication or invalid signature/cert/etc.
35 /** Interface to Bitcoin wallet from Qt view code. */
36 class WalletModel : public QObject
41 explicit WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent = 0);
44 enum StatusCode // Returned by sendCoins
50 AmountWithFeeExceedsBalance,
52 TransactionCreationFailed, // Error returned when wallet is still locked
53 TransactionCommitFailed,
59 Unencrypted, // !wallet->IsCrypted()
60 Locked, // wallet->IsCrypted() && wallet->IsLocked()
61 Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
64 OptionsModel *getOptionsModel();
65 AddressTableModel *getAddressTableModel();
66 TransactionTableModel *getTransactionTableModel();
68 qint64 getBalance() 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):
85 // prepare transaction for getting txfee before sending coins
86 SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction);
88 // Send coins to a list of recipients
89 SendCoinsReturn sendCoins(WalletModelTransaction &transaction);
92 bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
93 // Passphrase only needed when unlocking
94 bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString());
95 bool changePassphrase(const SecureString &oldPass, const SecureString &newPass);
97 bool backupWallet(const QString &filename);
99 // RAI object for unlocking wallet, returned by requestUnlock()
103 UnlockContext(WalletModel *wallet, bool valid, bool relock);
106 bool isValid() const { return valid; }
108 // Copy operator and constructor transfer the context
109 UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
110 UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
114 mutable bool relock; // mutable, as it can be set to false by copying
116 void CopyFrom(const UnlockContext& rhs);
119 UnlockContext requestUnlock();
124 // Wallet has an options model for wallet-specific options
125 // (transaction fee, for example)
126 OptionsModel *optionsModel;
128 AddressTableModel *addressTableModel;
129 TransactionTableModel *transactionTableModel;
131 // Cache some values to be able to detect changes
132 qint64 cachedBalance;
133 qint64 cachedUnconfirmedBalance;
134 qint64 cachedImmatureBalance;
135 qint64 cachedNumTransactions;
136 EncryptionStatus cachedEncryptionStatus;
141 void subscribeToCoreSignals();
142 void unsubscribeFromCoreSignals();
143 void checkBalanceChanged();
146 // Signal that balance in wallet changed
147 void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance);
149 // Number of transactions in wallet changed
150 void numTransactionsChanged(int count);
152 // Encryption status of wallet changed
153 void encryptionStatusChanged(int status);
155 // Signal emitted when wallet needs to be unlocked
156 // It is valid behaviour for listeners to keep the wallet locked after this signal;
157 // this means that the unlocking failed or was cancelled.
158 void requireUnlock();
160 // Asynchronous message notification
161 void message(const QString &title, const QString &message, unsigned int style);
163 // Coins sent: from wallet, to recipient, in (serialized) transaction:
164 void coinsSent(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
167 /* Wallet status might have changed */
169 /* New transaction, or transaction changed status */
170 void updateTransaction(const QString &hash, int status);
171 /* New, updated or removed address book entry */
172 void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
173 /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
174 void pollBalanceChanged();
177 #endif // WALLETMODEL_H