monero-gui/src/libwalletqt/Wallet.h

306 lines
11 KiB
C
Raw Normal View History

2016-02-23 15:59:26 +00:00
#ifndef WALLET_H
#define WALLET_H
#include <QObject>
#include <QTime>
2017-01-31 09:32:41 +00:00
#include <QMutex>
#include <QtConcurrent/QtConcurrent>
2016-02-23 15:59:26 +00:00
2016-12-13 18:51:07 +00:00
#include "wallet/wallet2_api.h" // we need to have an access to the Monero::Wallet::Status enum here;
2016-06-27 12:45:48 +00:00
#include "PendingTransaction.h" // we need to have an access to the PendingTransaction::Priority enum here;
2017-01-12 19:53:27 +00:00
#include "UnsignedTransaction.h"
2016-06-27 12:45:48 +00:00
2016-12-13 18:51:07 +00:00
namespace Monero {
class Wallet; // forward declaration
}
2016-06-08 10:53:24 +00:00
2016-06-27 12:45:48 +00:00
2016-06-08 10:53:24 +00:00
class TransactionHistory;
class TransactionHistoryModel;
2016-10-07 20:05:51 +00:00
class TransactionHistorySortFilterModel;
2016-12-10 01:01:04 +00:00
class AddressBook;
class AddressBookModel;
2016-06-08 10:53:24 +00:00
2016-02-23 15:59:26 +00:00
class Wallet : public QObject
{
Q_OBJECT
Q_PROPERTY(QString seed READ getSeed)
2016-06-08 10:53:24 +00:00
Q_PROPERTY(QString seedLanguage READ getSeedLanguage)
Q_PROPERTY(Status status READ status)
Q_PROPERTY(bool testnet READ testnet)
// Q_PROPERTY(ConnectionStatus connected READ connected)
Q_PROPERTY(bool synchronized READ synchronized)
2016-06-08 10:53:24 +00:00
Q_PROPERTY(QString errorString READ errorString)
Q_PROPERTY(QString address READ address)
Q_PROPERTY(quint64 balance READ balance)
Q_PROPERTY(quint64 unlockedBalance READ unlockedBalance)
Q_PROPERTY(TransactionHistory * history READ history)
Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId)
Q_PROPERTY(TransactionHistorySortFilterModel * historyModel READ historyModel NOTIFY historyModelChanged)
Q_PROPERTY(QString path READ path)
2016-12-10 01:01:04 +00:00
Q_PROPERTY(AddressBookModel * addressBookModel READ addressBookModel)
Q_PROPERTY(AddressBook * addressBook READ addressBook)
Q_PROPERTY(bool viewOnly READ viewOnly)
Q_PROPERTY(QString secretViewKey READ getSecretViewKey)
Q_PROPERTY(QString publicViewKey READ getPublicViewKey)
Q_PROPERTY(QString secretSpendKey READ getSecretSpendKey)
Q_PROPERTY(QString publicSpendKey READ getPublicSpendKey)
2017-08-24 09:30:50 +00:00
Q_PROPERTY(QString daemonLogPath READ getDaemonLogPath CONSTANT)
Q_PROPERTY(QString walletLogPath READ getWalletLogPath CONSTANT)
2016-06-08 10:53:24 +00:00
2016-02-23 15:59:26 +00:00
public:
enum Status {
2016-12-13 18:51:07 +00:00
Status_Ok = Monero::Wallet::Status_Ok,
2016-12-10 01:01:04 +00:00
Status_Error = Monero::Wallet::Status_Error,
Status_Critical = Monero::Wallet::Status_Critical
};
2016-06-08 10:53:24 +00:00
Q_ENUM(Status)
enum ConnectionStatus {
2016-12-13 18:51:07 +00:00
ConnectionStatus_Connected = Monero::Wallet::ConnectionStatus_Connected,
ConnectionStatus_Disconnected = Monero::Wallet::ConnectionStatus_Disconnected,
ConnectionStatus_WrongVersion = Monero::Wallet::ConnectionStatus_WrongVersion
};
Q_ENUM(ConnectionStatus)
2016-02-29 14:39:39 +00:00
//! returns mnemonic seed
2016-06-08 10:53:24 +00:00
QString getSeed() const;
2016-02-29 14:39:39 +00:00
//! returns seed language
2016-06-08 10:53:24 +00:00
QString getSeedLanguage() const;
//! set seed language
Q_INVOKABLE void setSeedLanguage(const QString &lang);
//! returns last operation's status
2016-06-08 10:53:24 +00:00
Status status() const;
//! returns true testnet wallet.
bool testnet() const;
//! returns whether the wallet is connected, and version status
Q_INVOKABLE ConnectionStatus connected(bool forceCheck = false);
2017-01-31 09:32:41 +00:00
void updateConnectionStatusAsync();
2016-07-14 10:09:39 +00:00
//! returns true if wallet was ever synchronized
bool synchronized() const;
//! returns last operation's error message
2016-06-08 10:53:24 +00:00
QString errorString() const;
2016-02-29 14:39:39 +00:00
//! changes the password using existing parameters (path, seed, seed lang)
Q_INVOKABLE bool setPassword(const QString &password);
//! returns wallet's public address
2016-06-08 10:53:24 +00:00
QString address() const;
//! returns wallet file's path
QString path() const;
//! saves wallet to the file by given path
2016-11-10 11:23:43 +00:00
//! empty path stores in current location
Q_INVOKABLE bool store(const QString &path = "");
2016-02-29 14:39:39 +00:00
2016-06-08 10:53:24 +00:00
//! initializes wallet
2017-01-31 09:32:41 +00:00
Q_INVOKABLE bool init(const QString &daemonAddress, quint64 upperTransactionLimit = 0, bool isRecovering = false, quint64 restoreHeight = 0);
2016-06-08 10:53:24 +00:00
2016-07-14 10:09:39 +00:00
//! initializes wallet asynchronously
2017-01-31 09:32:41 +00:00
Q_INVOKABLE void initAsync(const QString &daemonAddress, quint64 upperTransactionLimit = 0, bool isRecovering = false, quint64 restoreHeight = 0);
2016-07-14 10:09:39 +00:00
// Set daemon rpc user/pass
Q_INVOKABLE void setDaemonLogin(const QString &daemonUsername = "", const QString &daemonPassword = "");
//! create a view only wallet
Q_INVOKABLE bool createViewOnly(const QString &path, const QString &password) const;
2016-06-08 10:53:24 +00:00
//! connects to daemon
Q_INVOKABLE bool connectToDaemon();
//! indicates id daemon is trusted
Q_INVOKABLE void setTrustedDaemon(bool arg);
//! returns balance
Q_INVOKABLE quint64 balance() const;
2016-06-08 10:53:24 +00:00
//! returns unlocked balance
Q_INVOKABLE quint64 unlockedBalance() const;
//! returns if view only wallet
Q_INVOKABLE bool viewOnly() const;
//! returns current wallet's block height
//! (can be less than daemon's blockchain height when wallet sync in progress)
Q_INVOKABLE quint64 blockChainHeight() const;
//! returns daemon's blockchain height
Q_INVOKABLE quint64 daemonBlockChainHeight() const;
2016-06-08 10:53:24 +00:00
//! returns daemon's blockchain target height
Q_INVOKABLE quint64 daemonBlockChainTargetHeight() const;
2016-06-08 10:53:24 +00:00
//! refreshes the wallet
Q_INVOKABLE bool refresh();
2016-07-13 12:24:40 +00:00
//! refreshes the wallet asynchronously
Q_INVOKABLE void refreshAsync();
//! setup auto-refresh interval in seconds
Q_INVOKABLE void setAutoRefreshInterval(int seconds);
//! return auto-refresh interval in seconds
Q_INVOKABLE int autoRefreshInterval() const;
2017-02-25 18:49:09 +00:00
// pause/resume refresh
Q_INVOKABLE void startRefresh() const;
Q_INVOKABLE void pauseRefresh() const;
2016-06-08 10:53:24 +00:00
//! creates transaction
Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id,
2016-06-27 12:45:48 +00:00
quint64 amount, quint32 mixin_count,
2016-06-28 19:37:14 +00:00
PendingTransaction::Priority priority);
2016-11-09 13:00:43 +00:00
2016-11-08 15:33:36 +00:00
//! creates async transaction
Q_INVOKABLE void createTransactionAsync(const QString &dst_addr, const QString &payment_id,
quint64 amount, quint32 mixin_count,
PendingTransaction::Priority priority);
2016-11-09 13:00:43 +00:00
//! creates transaction with all outputs
Q_INVOKABLE PendingTransaction * createTransactionAll(const QString &dst_addr, const QString &payment_id,
quint32 mixin_count, PendingTransaction::Priority priority);
//! creates async transaction with all outputs
Q_INVOKABLE void createTransactionAllAsync(const QString &dst_addr, const QString &payment_id,
quint32 mixin_count, PendingTransaction::Priority priority);
//! creates sweep unmixable transaction
Q_INVOKABLE PendingTransaction * createSweepUnmixableTransaction();
//! creates async sweep unmixable transaction
Q_INVOKABLE void createSweepUnmixableTransactionAsync();
2017-01-12 19:53:27 +00:00
//! Sign a transfer from file
Q_INVOKABLE UnsignedTransaction * loadTxFile(const QString &fileName);
//! Submit a transfer from file
Q_INVOKABLE bool submitTxFile(const QString &fileName) const;
2016-06-08 10:53:24 +00:00
//! deletes transaction and frees memory
Q_INVOKABLE void disposeTransaction(PendingTransaction * t);
2017-01-12 19:53:27 +00:00
//! deletes unsigned transaction and frees memory
Q_INVOKABLE void disposeTransaction(UnsignedTransaction * t);
2016-06-08 10:53:24 +00:00
//! returns transaction history
TransactionHistory * history() const;
//! returns transaction history model
2016-10-07 20:05:51 +00:00
TransactionHistorySortFilterModel *historyModel() const;
2016-12-10 01:01:04 +00:00
//! returns Address book
AddressBook *addressBook() const;
//! returns adress book model
AddressBookModel *addressBookModel() const;
//! generate payment id
Q_INVOKABLE QString generatePaymentId() const;
//! integrated address
Q_INVOKABLE QString integratedAddress(const QString &paymentId) const;
2016-11-08 10:06:34 +00:00
//! signing a message
Q_INVOKABLE QString signMessage(const QString &message, bool filename = false) const;
//! verify a signed message
Q_INVOKABLE bool verifySignedMessage(const QString &message, const QString &address, const QString &signature, bool filename = false) const;
2017-01-11 03:16:21 +00:00
//! Parse URI
Q_INVOKABLE bool parse_uri(const QString &uri, QString &address, QString &payment_id, uint64_t &amount, QString &tx_description, QString &recipient_name, QVector<QString> &unknown_parameters, QString &error);
//! saved payment id
QString paymentId() const;
void setPaymentId(const QString &paymentId);
Q_INVOKABLE bool setUserNote(const QString &txid, const QString &note);
Q_INVOKABLE QString getUserNote(const QString &txid) const;
2016-11-06 18:27:08 +00:00
Q_INVOKABLE QString getTxKey(const QString &txid) const;
2017-01-12 21:28:37 +00:00
// Rescan spent outputs
Q_INVOKABLE bool rescanSpent();
2016-11-06 18:27:08 +00:00
// check if fork rules should be used
Q_INVOKABLE bool useForkRules(quint8 version, quint64 earlyBlocks = 0) const;
//! Get wallet keys
QString getSecretViewKey() const {return QString::fromStdString(m_walletImpl->secretViewKey());}
QString getPublicViewKey() const {return QString::fromStdString(m_walletImpl->publicViewKey());}
QString getSecretSpendKey() const {return QString::fromStdString(m_walletImpl->secretSpendKey());}
QString getPublicSpendKey() const {return QString::fromStdString(m_walletImpl->publicSpendKey());}
2017-08-24 09:30:50 +00:00
QString getDaemonLogPath() const;
QString getWalletLogPath() const;
2016-06-08 10:53:24 +00:00
// TODO: setListenter() when it implemented in API
2016-06-17 13:35:07 +00:00
signals:
// emitted on every event happened with wallet
// (money sent/received, new block)
2016-06-17 13:35:07 +00:00
void updated();
2016-07-13 12:24:40 +00:00
// emitted when refresh process finished (could take a long time)
// signalling only after we
void refreshed();
void moneySpent(const QString &txId, quint64 amount);
void moneyReceived(const QString &txId, quint64 amount);
void unconfirmedMoneyReceived(const QString &txId, quint64 amount);
2017-01-31 09:32:41 +00:00
void newBlock(quint64 height, quint64 targetHeight);
void historyModelChanged() const;
2016-11-08 15:33:36 +00:00
// emitted when transaction is created async
void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount);
2016-02-29 14:39:39 +00:00
2017-01-31 09:32:41 +00:00
void connectionStatusChanged(ConnectionStatus status) const;
2016-02-29 14:39:39 +00:00
private:
Wallet(QObject * parent = nullptr);
2016-12-13 18:51:07 +00:00
Wallet(Monero::Wallet *w, QObject * parent = 0);
~Wallet();
2016-02-29 14:39:39 +00:00
private:
friend class WalletManager;
2016-07-13 12:24:40 +00:00
friend class WalletListenerImpl;
//! libwallet's
2016-12-13 18:51:07 +00:00
Monero::Wallet * m_walletImpl;
2016-06-08 10:53:24 +00:00
// history lifetime managed by wallet;
TransactionHistory * m_history;
// Used for UI history view
mutable TransactionHistoryModel * m_historyModel;
2016-10-07 20:05:51 +00:00
mutable TransactionHistorySortFilterModel * m_historySortFilterModel;
QString m_paymentId;
mutable QTime m_daemonBlockChainHeightTime;
mutable quint64 m_daemonBlockChainHeight;
int m_daemonBlockChainHeightTtl;
2016-11-01 17:14:39 +00:00
mutable QTime m_daemonBlockChainTargetHeightTime;
mutable quint64 m_daemonBlockChainTargetHeight;
2016-11-01 17:14:39 +00:00
int m_daemonBlockChainTargetHeightTtl;
mutable ConnectionStatus m_connectionStatus;
2016-11-26 15:31:27 +00:00
int m_connectionStatusTtl;
mutable QTime m_connectionStatusTime;
mutable bool m_initialized;
2016-12-10 01:01:04 +00:00
AddressBook * m_addressBook;
mutable AddressBookModel * m_addressBookModel;
2017-01-31 09:32:41 +00:00
QMutex m_connectionStatusMutex;
bool m_connectionStatusRunning;
QString m_daemonUsername;
QString m_daemonPassword;
2016-02-23 15:59:26 +00:00
};
#endif // WALLET_H