2016-02-23 15:59:26 +00:00
|
|
|
#ifndef WALLET_H
|
|
|
|
#define WALLET_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2016-09-26 19:55:25 +00:00
|
|
|
#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 {
|
2016-06-07 13:26:25 +00:00
|
|
|
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;
|
2016-10-02 18:40:40 +00:00
|
|
|
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
|
2016-02-24 10:25:20 +00:00
|
|
|
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)
|
2017-01-22 22:04:46 +00:00
|
|
|
Q_PROPERTY(bool testnet READ testnet)
|
2017-02-23 18:47:58 +00:00
|
|
|
// Q_PROPERTY(ConnectionStatus connected READ connected)
|
2016-10-06 21:47:28 +00:00
|
|
|
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)
|
2016-06-26 15:04:45 +00:00
|
|
|
Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId)
|
2016-10-07 22:24:18 +00:00
|
|
|
Q_PROPERTY(TransactionHistorySortFilterModel * historyModel READ historyModel NOTIFY historyModelChanged)
|
2016-11-26 14:46:42 +00:00
|
|
|
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)
|
2017-01-04 16:25:22 +00:00
|
|
|
Q_PROPERTY(bool viewOnly READ viewOnly)
|
2017-05-02 15:29:35 +00:00
|
|
|
Q_PROPERTY(QString secretViewKey READ getSecretViewKey)
|
|
|
|
Q_PROPERTY(QString publicViewKey READ getPublicViewKey)
|
|
|
|
Q_PROPERTY(QString secretSpendKey READ getSecretSpendKey)
|
|
|
|
Q_PROPERTY(QString publicSpendKey READ getPublicSpendKey)
|
2016-06-08 10:53:24 +00:00
|
|
|
|
2016-02-23 15:59:26 +00:00
|
|
|
public:
|
2016-10-02 18:40:40 +00:00
|
|
|
|
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
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-07 13:26:25 +00:00
|
|
|
};
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2016-06-08 10:53:24 +00:00
|
|
|
Q_ENUM(Status)
|
|
|
|
|
2016-11-07 12:02:27 +00:00
|
|
|
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
|
2016-11-07 12:02:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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-24 10:25:20 +00:00
|
|
|
|
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);
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
//! returns last operation's status
|
2016-06-08 10:53:24 +00:00
|
|
|
Status status() const;
|
2016-06-07 13:26:25 +00:00
|
|
|
|
2017-01-22 22:04:46 +00:00
|
|
|
//! returns true testnet wallet.
|
|
|
|
bool testnet() const;
|
|
|
|
|
2016-11-07 12:02:27 +00:00
|
|
|
//! returns whether the wallet is connected, and version status
|
2017-02-23 18:47:58 +00:00
|
|
|
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
|
|
|
|
2016-10-06 21:47:28 +00:00
|
|
|
//! returns true if wallet was ever synchronized
|
|
|
|
bool synchronized() const;
|
|
|
|
|
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
//! returns last operation's error message
|
2016-06-08 10:53:24 +00:00
|
|
|
QString errorString() const;
|
2016-02-24 10:25:20 +00:00
|
|
|
|
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);
|
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
//! returns wallet's public address
|
2016-06-08 10:53:24 +00:00
|
|
|
QString address() const;
|
2016-06-07 13:26:25 +00:00
|
|
|
|
2016-11-26 14:46:42 +00:00
|
|
|
//! returns wallet file's path
|
|
|
|
QString path() const;
|
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
//! 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
|
|
|
|
2017-02-25 21:16:58 +00:00
|
|
|
// Set daemon rpc user/pass
|
|
|
|
Q_INVOKABLE void setDaemonLogin(const QString &daemonUsername = "", const QString &daemonPassword = "");
|
|
|
|
|
2017-01-04 16:25:22 +00:00
|
|
|
//! 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
|
2016-09-26 19:55:25 +00:00
|
|
|
Q_INVOKABLE quint64 balance() const;
|
2016-06-08 10:53:24 +00:00
|
|
|
|
|
|
|
//! returns unlocked balance
|
2016-09-26 19:55:25 +00:00
|
|
|
Q_INVOKABLE quint64 unlockedBalance() const;
|
|
|
|
|
2017-01-04 16:25:22 +00:00
|
|
|
//! returns if view only wallet
|
|
|
|
Q_INVOKABLE bool viewOnly() const;
|
|
|
|
|
2016-09-26 19:55:25 +00:00
|
|
|
//! 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
|
|
|
|
2016-10-03 21:29:30 +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();
|
|
|
|
|
2016-09-26 19:55:25 +00:00
|
|
|
//! 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
|
2016-06-26 15:04:45 +00:00
|
|
|
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-08 20:23:50 +00:00
|
|
|
|
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);
|
|
|
|
|
2016-11-11 21:54:17 +00:00
|
|
|
//! creates async transaction with all outputs
|
|
|
|
Q_INVOKABLE void createTransactionAllAsync(const QString &dst_addr, const QString &payment_id,
|
|
|
|
quint32 mixin_count, PendingTransaction::Priority priority);
|
|
|
|
|
2016-11-08 20:23:50 +00:00
|
|
|
//! creates sweep unmixable transaction
|
|
|
|
Q_INVOKABLE PendingTransaction * createSweepUnmixableTransaction();
|
|
|
|
|
2016-11-11 21:54:17 +00:00
|
|
|
//! 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
|
2016-10-06 21:47:28 +00:00
|
|
|
TransactionHistory * history() const;
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2016-10-02 18:40:40 +00:00
|
|
|
//! returns transaction history model
|
2016-10-07 20:05:51 +00:00
|
|
|
TransactionHistorySortFilterModel *historyModel() const;
|
2016-10-02 18:40:40 +00:00
|
|
|
|
2016-12-10 01:01:04 +00:00
|
|
|
//! returns Address book
|
|
|
|
AddressBook *addressBook() const;
|
|
|
|
|
|
|
|
//! returns adress book model
|
|
|
|
AddressBookModel *addressBookModel() const;
|
|
|
|
|
2016-06-26 15:04:45 +00:00
|
|
|
//! 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);
|
2016-06-26 15:04:45 +00:00
|
|
|
|
|
|
|
//! saved payment id
|
|
|
|
QString paymentId() const;
|
|
|
|
|
|
|
|
void setPaymentId(const QString &paymentId);
|
|
|
|
|
2016-11-05 23:19:28 +00:00
|
|
|
Q_INVOKABLE bool setUserNote(const QString &txid, const QString ¬e);
|
|
|
|
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
|
|
|
|
2017-03-23 21:54:35 +00:00
|
|
|
// check if fork rules should be used
|
2017-03-26 17:02:18 +00:00
|
|
|
Q_INVOKABLE bool useForkRules(quint8 version, quint64 earlyBlocks = 0) const;
|
2017-03-23 21:54:35 +00:00
|
|
|
|
2017-05-02 15:29:35 +00:00
|
|
|
//! 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());}
|
|
|
|
|
2016-06-08 10:53:24 +00:00
|
|
|
// TODO: setListenter() when it implemented in API
|
2016-06-17 13:35:07 +00:00
|
|
|
signals:
|
2016-09-23 20:51:24 +00:00
|
|
|
// 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();
|
|
|
|
|
2016-09-23 20:51:24 +00:00
|
|
|
void moneySpent(const QString &txId, quint64 amount);
|
|
|
|
void moneyReceived(const QString &txId, quint64 amount);
|
2017-01-12 18:57:30 +00:00
|
|
|
void unconfirmedMoneyReceived(const QString &txId, quint64 amount);
|
2017-01-31 09:32:41 +00:00
|
|
|
void newBlock(quint64 height, quint64 targetHeight);
|
2016-10-07 22:24:18 +00:00
|
|
|
void historyModelChanged() const;
|
2016-09-23 20:51:24 +00:00
|
|
|
|
2016-11-08 15:33:36 +00:00
|
|
|
// emitted when transaction is created async
|
2016-11-08 17:02:07 +00:00
|
|
|
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-11-26 14:34:56 +00:00
|
|
|
|
2016-02-29 14:39:39 +00:00
|
|
|
private:
|
2016-10-02 18:40:40 +00:00
|
|
|
Wallet(QObject * parent = nullptr);
|
2016-12-13 18:51:07 +00:00
|
|
|
Wallet(Monero::Wallet *w, QObject * parent = 0);
|
2016-06-07 13:26:25 +00:00
|
|
|
~Wallet();
|
2016-02-29 14:39:39 +00:00
|
|
|
private:
|
|
|
|
friend class WalletManager;
|
2016-07-13 12:24:40 +00:00
|
|
|
friend class WalletListenerImpl;
|
2016-06-07 13:26:25 +00:00
|
|
|
//! 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;
|
2016-10-02 18:40:40 +00:00
|
|
|
// Used for UI history view
|
2016-10-06 21:47:28 +00:00
|
|
|
mutable TransactionHistoryModel * m_historyModel;
|
2016-10-07 20:05:51 +00:00
|
|
|
mutable TransactionHistorySortFilterModel * m_historySortFilterModel;
|
2016-06-26 15:04:45 +00:00
|
|
|
QString m_paymentId;
|
2016-09-26 19:55:25 +00:00
|
|
|
mutable QTime m_daemonBlockChainHeightTime;
|
|
|
|
mutable quint64 m_daemonBlockChainHeight;
|
|
|
|
int m_daemonBlockChainHeightTtl;
|
2016-11-01 17:14:39 +00:00
|
|
|
mutable QTime m_daemonBlockChainTargetHeightTime;
|
2016-10-03 21:29:30 +00:00
|
|
|
mutable quint64 m_daemonBlockChainTargetHeight;
|
2016-11-01 17:14:39 +00:00
|
|
|
int m_daemonBlockChainTargetHeightTtl;
|
2016-11-26 23:16:09 +00:00
|
|
|
mutable ConnectionStatus m_connectionStatus;
|
2016-11-26 15:31:27 +00:00
|
|
|
int m_connectionStatusTtl;
|
|
|
|
mutable QTime m_connectionStatusTime;
|
2016-11-26 23:16:09 +00:00
|
|
|
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;
|
2017-02-25 21:16:58 +00:00
|
|
|
QString m_daemonUsername;
|
|
|
|
QString m_daemonPassword;
|
2016-02-23 15:59:26 +00:00
|
|
|
};
|
|
|
|
|
2016-10-02 18:40:40 +00:00
|
|
|
|
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
#endif // WALLET_H
|