Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletmodel.h
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_QT_WALLETMODEL_H | #ifndef BITCOIN_QT_WALLETMODEL_H | ||||
#define BITCOIN_QT_WALLETMODEL_H | #define BITCOIN_QT_WALLETMODEL_H | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "paymentrequestplus.h" | #include "paymentrequestplus.h" | ||||
#include "walletmodeltransaction.h" | #include "walletmodeltransaction.h" | ||||
#include "interface/wallet.h" | |||||
#include "support/allocators/secure.h" | #include "support/allocators/secure.h" | ||||
#include <map> | #include <map> | ||||
#include <vector> | #include <vector> | ||||
#include <QObject> | #include <QObject> | ||||
class AddressTableModel; | class AddressTableModel; | ||||
class OptionsModel; | class OptionsModel; | ||||
class PlatformStyle; | class PlatformStyle; | ||||
class RecentRequestsTableModel; | class RecentRequestsTableModel; | ||||
class TransactionTableModel; | class TransactionTableModel; | ||||
class WalletModelTransaction; | class WalletModelTransaction; | ||||
class CCoinControl; | class CCoinControl; | ||||
class CKeyID; | class CKeyID; | ||||
class COutPoint; | class COutPoint; | ||||
class COutput; | class COutput; | ||||
class CPubKey; | class CPubKey; | ||||
class CWallet; | |||||
class uint256; | class uint256; | ||||
namespace interface { | |||||
class Node; | |||||
} // namespace interface | |||||
QT_BEGIN_NAMESPACE | QT_BEGIN_NAMESPACE | ||||
class QTimer; | class QTimer; | ||||
QT_END_NAMESPACE | QT_END_NAMESPACE | ||||
class SendCoinsRecipient { | class SendCoinsRecipient { | ||||
public: | public: | ||||
explicit SendCoinsRecipient() | explicit SendCoinsRecipient() | ||||
: amount(), fSubtractFeeFromAmount(false), | : amount(), fSubtractFeeFromAmount(false), | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
}; | }; | ||||
/** Interface to Bitcoin wallet from Qt view code. */ | /** Interface to Bitcoin wallet from Qt view code. */ | ||||
class WalletModel : public QObject { | class WalletModel : public QObject { | ||||
Q_OBJECT | Q_OBJECT | ||||
public: | public: | ||||
explicit WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, | explicit WalletModel(std::unique_ptr<interface::Wallet> wallet, | ||||
interface::Node &node, | |||||
const PlatformStyle *platformStyle, | |||||
OptionsModel *optionsModel, QObject *parent = nullptr); | OptionsModel *optionsModel, QObject *parent = nullptr); | ||||
~WalletModel(); | ~WalletModel(); | ||||
// Returned by sendCoins | // Returned by sendCoins | ||||
enum StatusCode { | enum StatusCode { | ||||
OK, | OK, | ||||
InvalidAmount, | InvalidAmount, | ||||
InvalidAddress, | InvalidAddress, | ||||
Show All 16 Lines | enum EncryptionStatus { | ||||
Unlocked | Unlocked | ||||
}; | }; | ||||
OptionsModel *getOptionsModel(); | OptionsModel *getOptionsModel(); | ||||
AddressTableModel *getAddressTableModel(); | AddressTableModel *getAddressTableModel(); | ||||
TransactionTableModel *getTransactionTableModel(); | TransactionTableModel *getTransactionTableModel(); | ||||
RecentRequestsTableModel *getRecentRequestsTableModel(); | RecentRequestsTableModel *getRecentRequestsTableModel(); | ||||
CWallet *getWallet() const { return wallet; }; | |||||
Amount getBalance(const CCoinControl *coinControl = nullptr) const; | |||||
Amount getUnconfirmedBalance() const; | |||||
Amount getImmatureBalance() const; | |||||
bool haveWatchOnly() const; | |||||
Amount getWatchBalance() const; | |||||
Amount getWatchUnconfirmedBalance() const; | |||||
Amount getWatchImmatureBalance() const; | |||||
EncryptionStatus getEncryptionStatus() const; | EncryptionStatus getEncryptionStatus() const; | ||||
// Check address for validity | // Check address for validity | ||||
bool validateAddress(const QString &address); | bool validateAddress(const QString &address); | ||||
// Return status record for SendCoins, contains error id + information | // Return status record for SendCoins, contains error id + information | ||||
struct SendCoinsReturn { | struct SendCoinsReturn { | ||||
SendCoinsReturn(StatusCode _status = OK, | SendCoinsReturn(StatusCode _status = OK, | ||||
Show All 12 Lines | public: | ||||
// Wallet encryption | // Wallet encryption | ||||
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase); | bool setWalletEncrypted(bool encrypted, const SecureString &passphrase); | ||||
// Passphrase only needed when unlocking | // Passphrase only needed when unlocking | ||||
bool setWalletLocked(bool locked, | bool setWalletLocked(bool locked, | ||||
const SecureString &passPhrase = SecureString()); | const SecureString &passPhrase = SecureString()); | ||||
bool changePassphrase(const SecureString &oldPass, | bool changePassphrase(const SecureString &oldPass, | ||||
const SecureString &newPass); | const SecureString &newPass); | ||||
// Wallet backup | |||||
bool backupWallet(const QString &filename); | |||||
// RAI object for unlocking wallet, returned by requestUnlock() | // RAI object for unlocking wallet, returned by requestUnlock() | ||||
class UnlockContext { | class UnlockContext { | ||||
public: | public: | ||||
UnlockContext(WalletModel *wallet, bool valid, bool relock); | UnlockContext(WalletModel *wallet, bool valid, bool relock); | ||||
~UnlockContext(); | ~UnlockContext(); | ||||
bool isValid() const { return valid; } | bool isValid() const { return valid; } | ||||
Show All 11 Lines | private: | ||||
// mutable, as it can be set to false by copying | // mutable, as it can be set to false by copying | ||||
mutable bool relock; | mutable bool relock; | ||||
void CopyFrom(const UnlockContext &rhs); | void CopyFrom(const UnlockContext &rhs); | ||||
}; | }; | ||||
UnlockContext requestUnlock(); | UnlockContext requestUnlock(); | ||||
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const; | |||||
bool IsSpendable(const CTxDestination &dest) const; | |||||
bool getPrivKey(const CKeyID &address, CKey &vchPrivKeyOut) const; | |||||
void getOutputs(const std::vector<COutPoint> &vOutpoints, | |||||
std::vector<COutput> &vOutputs); | |||||
bool isSpent(const COutPoint &outpoint) const; | |||||
void listCoins(std::map<QString, std::vector<COutput>> &mapCoins) const; | |||||
bool isLockedCoin(const TxId &txid, uint32_t n) const; | |||||
void lockCoin(COutPoint &output); | |||||
void unlockCoin(COutPoint &output); | |||||
void listLockedCoins(std::vector<COutPoint> &vOutpts); | |||||
void loadReceiveRequests(std::vector<std::string> &vReceiveRequests); | void loadReceiveRequests(std::vector<std::string> &vReceiveRequests); | ||||
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, | bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, | ||||
const std::string &sRequest); | const std::string &sRequest); | ||||
bool transactionCanBeAbandoned(const TxId &txid) const; | |||||
bool abandonTransaction(const TxId &txid) const; | |||||
static bool isWalletEnabled(); | static bool isWalletEnabled(); | ||||
bool hdEnabled() const; | interface::Node &node() const { | ||||
return m_node; | |||||
} | |||||
interface::Wallet &wallet() const { | |||||
return *m_wallet; | |||||
} | |||||
const CChainParams &getChainParams() const; | const CChainParams &getChainParams() const; | ||||
QString getWalletName() const; | QString getWalletName() const; | ||||
static bool isMultiwallet(); | bool isMultiwallet(); | ||||
private: | private: | ||||
CWallet *wallet; | std::unique_ptr<interface::Wallet> m_wallet; | ||||
std::unique_ptr<interface::Handler> m_handler_status_changed; | |||||
std::unique_ptr<interface::Handler> m_handler_address_book_changed; | |||||
std::unique_ptr<interface::Handler> m_handler_transaction_changed; | |||||
std::unique_ptr<interface::Handler> m_handler_show_progress; | |||||
std::unique_ptr<interface::Handler> m_handler_watch_only_changed; | |||||
interface::Node &m_node; | |||||
bool fHaveWatchOnly; | bool fHaveWatchOnly; | ||||
bool fForceCheckBalanceChanged; | bool fForceCheckBalanceChanged; | ||||
// Wallet has an options model for wallet-specific options (transaction fee, | // Wallet has an options model for wallet-specific options (transaction fee, | ||||
// for example) | // for example) | ||||
OptionsModel *optionsModel; | OptionsModel *optionsModel; | ||||
AddressTableModel *addressTableModel; | AddressTableModel *addressTableModel; | ||||
TransactionTableModel *transactionTableModel; | TransactionTableModel *transactionTableModel; | ||||
RecentRequestsTableModel *recentRequestsTableModel; | RecentRequestsTableModel *recentRequestsTableModel; | ||||
// Cache some values to be able to detect changes | // Cache some values to be able to detect changes | ||||
Amount cachedBalance; | interface::WalletBalances m_cached_balances; | ||||
Amount cachedUnconfirmedBalance; | |||||
Amount cachedImmatureBalance; | |||||
Amount cachedWatchOnlyBalance; | |||||
Amount cachedWatchUnconfBalance; | |||||
Amount cachedWatchImmatureBalance; | |||||
EncryptionStatus cachedEncryptionStatus; | EncryptionStatus cachedEncryptionStatus; | ||||
int cachedNumBlocks; | int cachedNumBlocks; | ||||
QTimer *pollTimer; | QTimer *pollTimer; | ||||
void subscribeToCoreSignals(); | void subscribeToCoreSignals(); | ||||
void unsubscribeFromCoreSignals(); | void unsubscribeFromCoreSignals(); | ||||
void checkBalanceChanged(); | void checkBalanceChanged(const interface::WalletBalances &new_balances); | ||||
Q_SIGNALS: | Q_SIGNALS: | ||||
// Signal that balance in wallet changed | // Signal that balance in wallet changed | ||||
void balanceChanged(const Amount balance, const Amount unconfirmedBalance, | void balanceChanged(const Amount balance, const Amount unconfirmedBalance, | ||||
const Amount immatureBalance, | const Amount immatureBalance, | ||||
const Amount watchOnlyBalance, | const Amount watchOnlyBalance, | ||||
const Amount watchUnconfBalance, | const Amount watchUnconfBalance, | ||||
const Amount watchImmatureBalance); | const Amount watchImmatureBalance); | ||||
// Encryption status of wallet changed | // Encryption status of wallet changed | ||||
void encryptionStatusChanged(); | void encryptionStatusChanged(); | ||||
// Signal emitted when wallet needs to be unlocked | // Signal emitted when wallet needs to be unlocked | ||||
// It is valid behaviour for listeners to keep the wallet locked after this | // It is valid behaviour for listeners to keep the wallet locked after this | ||||
// signal; this means that the unlocking failed or was cancelled. | // signal; this means that the unlocking failed or was cancelled. | ||||
void requireUnlock(); | void requireUnlock(); | ||||
// Fired when a message should be reported to the user | // Fired when a message should be reported to the user | ||||
void message(const QString &title, const QString &message, | void message(const QString &title, const QString &message, | ||||
unsigned int style); | unsigned int style); | ||||
// Coins sent: from wallet, to recipient, in (serialized) transaction: | // Coins sent: from wallet, to recipient, in (serialized) transaction: | ||||
void coinsSent(CWallet *wallet, SendCoinsRecipient recipient, | void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, | ||||
QByteArray transaction); | QByteArray transaction); | ||||
// Show progress dialog e.g. for rescan | // Show progress dialog e.g. for rescan | ||||
void showProgress(const QString &title, int nProgress); | void showProgress(const QString &title, int nProgress); | ||||
// Watch-only address added | // Watch-only address added | ||||
void notifyWatchonlyChanged(bool fHaveWatchonly); | void notifyWatchonlyChanged(bool fHaveWatchonly); | ||||
Show All 18 Lines |