2019-05-01 20:53:04 +00:00
|
|
|
// Copyright (c) 2014-2019, The Monero Project
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2016-02-23 15:59:26 +00:00
|
|
|
#ifndef WALLETMANAGER_H
|
|
|
|
#define WALLETMANAGER_H
|
|
|
|
|
2018-11-30 03:51:03 +00:00
|
|
|
#include <QVariant>
|
2016-02-23 15:59:26 +00:00
|
|
|
#include <QObject>
|
2016-09-05 19:07:53 +00:00
|
|
|
#include <QUrl>
|
2017-12-08 07:29:28 +00:00
|
|
|
#include <wallet/api/wallet2_api.h>
|
2016-12-13 22:44:44 +00:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QPointer>
|
2019-03-27 08:28:42 +00:00
|
|
|
#include <QWaitCondition>
|
|
|
|
#include <QMutex>
|
2018-03-05 16:19:45 +00:00
|
|
|
#include "NetworkType.h"
|
2016-02-23 15:59:26 +00:00
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
class Wallet;
|
2016-12-13 18:51:07 +00:00
|
|
|
namespace Monero {
|
2016-06-07 13:26:25 +00:00
|
|
|
class WalletManager;
|
|
|
|
}
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2016-02-23 15:59:26 +00:00
|
|
|
class WalletManager : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2016-11-24 11:14:46 +00:00
|
|
|
Q_PROPERTY(bool connected READ connected)
|
2016-08-23 13:07:52 +00:00
|
|
|
|
2016-02-23 15:59:26 +00:00
|
|
|
public:
|
2016-08-23 07:32:01 +00:00
|
|
|
enum LogLevel {
|
2016-12-13 18:51:07 +00:00
|
|
|
LogLevel_Silent = Monero::WalletManagerFactory::LogLevel_Silent,
|
|
|
|
LogLevel_0 = Monero::WalletManagerFactory::LogLevel_0,
|
|
|
|
LogLevel_1 = Monero::WalletManagerFactory::LogLevel_1,
|
|
|
|
LogLevel_2 = Monero::WalletManagerFactory::LogLevel_2,
|
|
|
|
LogLevel_3 = Monero::WalletManagerFactory::LogLevel_3,
|
|
|
|
LogLevel_4 = Monero::WalletManagerFactory::LogLevel_4,
|
|
|
|
LogLevel_Min = Monero::WalletManagerFactory::LogLevel_Min,
|
|
|
|
LogLevel_Max = Monero::WalletManagerFactory::LogLevel_Max,
|
2016-08-23 07:32:01 +00:00
|
|
|
};
|
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
static WalletManager * instance();
|
2016-02-29 14:39:39 +00:00
|
|
|
// wizard: createWallet path;
|
2016-02-24 10:25:20 +00:00
|
|
|
Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
|
2018-07-06 09:39:58 +00:00
|
|
|
const QString &language, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
2016-08-18 18:55:34 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief openWallet - opens wallet by given path
|
|
|
|
* \param path - wallet filename
|
|
|
|
* \param password - wallet password. Empty string in wallet isn't password protected
|
2018-03-05 16:19:45 +00:00
|
|
|
* \param nettype - type of network the wallet is running on
|
2016-08-18 18:55:34 +00:00
|
|
|
* \return wallet object pointer
|
|
|
|
*/
|
2018-07-06 09:39:58 +00:00
|
|
|
Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
2016-02-29 14:39:39 +00:00
|
|
|
|
2016-08-18 18:55:34 +00:00
|
|
|
/*!
|
|
|
|
* \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal
|
|
|
|
* emitted when wallet opened;
|
|
|
|
*/
|
2018-07-06 09:39:58 +00:00
|
|
|
Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype = NetworkType::MAINNET, quint64 kdfRounds = 1);
|
2016-08-18 18:55:34 +00:00
|
|
|
|
2016-02-29 14:39:39 +00:00
|
|
|
// wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
|
|
|
|
Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo,
|
2018-07-06 09:39:58 +00:00
|
|
|
NetworkType::Type nettype = NetworkType::MAINNET, quint64 restoreHeight = 0, quint64 kdfRounds = 1);
|
2016-02-23 15:59:26 +00:00
|
|
|
|
2017-01-26 20:49:32 +00:00
|
|
|
Q_INVOKABLE Wallet * createWalletFromKeys(const QString &path,
|
|
|
|
const QString &language,
|
2018-03-05 16:19:45 +00:00
|
|
|
NetworkType::Type nettype,
|
2017-01-26 20:49:32 +00:00
|
|
|
const QString &address,
|
|
|
|
const QString &viewkey,
|
|
|
|
const QString &spendkey = "",
|
2018-07-06 09:39:58 +00:00
|
|
|
quint64 restoreHeight = 0,
|
|
|
|
quint64 kdfRounds = 1);
|
2017-01-26 20:49:32 +00:00
|
|
|
|
2018-06-04 08:05:29 +00:00
|
|
|
Q_INVOKABLE Wallet * createWalletFromDevice(const QString &path,
|
|
|
|
const QString &password,
|
|
|
|
NetworkType::Type nettype,
|
|
|
|
const QString &deviceName,
|
|
|
|
quint64 restoreHeight = 0,
|
|
|
|
const QString &subaddressLookahead = "");
|
2019-03-27 08:28:42 +00:00
|
|
|
|
|
|
|
Q_INVOKABLE void createWalletFromDeviceAsync(const QString &path,
|
|
|
|
const QString &password,
|
|
|
|
NetworkType::Type nettype,
|
|
|
|
const QString &deviceName,
|
|
|
|
quint64 restoreHeight = 0,
|
|
|
|
const QString &subaddressLookahead = "");
|
2016-08-18 18:55:34 +00:00
|
|
|
/*!
|
2016-12-13 22:44:44 +00:00
|
|
|
* \brief closeWallet - closes current open wallet and frees memory
|
2016-08-18 18:55:34 +00:00
|
|
|
* \return wallet address
|
|
|
|
*/
|
2016-12-13 22:44:44 +00:00
|
|
|
Q_INVOKABLE QString closeWallet();
|
2016-08-18 18:55:34 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief closeWalletAsync - asynchronous version of "closeWallet"
|
|
|
|
*/
|
2016-12-13 22:44:44 +00:00
|
|
|
Q_INVOKABLE void closeWalletAsync();
|
2016-02-29 14:39:39 +00:00
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
//! checks is given filename is a wallet;
|
|
|
|
Q_INVOKABLE bool walletExists(const QString &path) const;
|
2016-02-29 14:39:39 +00:00
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
//! returns list with wallet's filenames, if found by given path
|
|
|
|
Q_INVOKABLE QStringList findWallets(const QString &path);
|
2016-02-29 14:39:39 +00:00
|
|
|
|
|
|
|
//! returns error description in human language
|
|
|
|
Q_INVOKABLE QString errorString() const;
|
2016-06-07 13:26:25 +00:00
|
|
|
|
2016-06-08 10:53:24 +00:00
|
|
|
//! since we can't call static method from QML, move it to this class
|
2016-08-23 13:07:52 +00:00
|
|
|
Q_INVOKABLE QString displayAmount(quint64 amount) const;
|
|
|
|
Q_INVOKABLE quint64 amountFromString(const QString &amount) const;
|
|
|
|
Q_INVOKABLE quint64 amountFromDouble(double amount) const;
|
|
|
|
Q_INVOKABLE quint64 maximumAllowedAmount() const;
|
|
|
|
|
|
|
|
// QML JS engine doesn't support unsigned integers
|
|
|
|
Q_INVOKABLE QString maximumAllowedAmountAsSting() const;
|
2016-06-16 14:13:46 +00:00
|
|
|
|
2016-10-16 12:57:56 +00:00
|
|
|
Q_INVOKABLE bool paymentIdValid(const QString &payment_id) const;
|
2018-03-05 16:19:45 +00:00
|
|
|
Q_INVOKABLE bool addressValid(const QString &address, NetworkType::Type nettype) const;
|
|
|
|
Q_INVOKABLE bool keyValid(const QString &key, const QString &address, bool isViewKey, NetworkType::Type nettype) const;
|
2017-01-26 20:49:32 +00:00
|
|
|
|
2018-03-05 16:19:45 +00:00
|
|
|
Q_INVOKABLE QString paymentIdFromAddress(const QString &address, NetworkType::Type nettype) const;
|
2016-10-16 12:57:56 +00:00
|
|
|
|
2019-05-27 22:13:53 +00:00
|
|
|
Q_INVOKABLE void setDaemonAddressAsync(const QString &address);
|
2016-11-24 11:14:46 +00:00
|
|
|
Q_INVOKABLE bool connected() const;
|
|
|
|
Q_INVOKABLE quint64 networkDifficulty() const;
|
|
|
|
Q_INVOKABLE quint64 blockchainHeight() const;
|
|
|
|
Q_INVOKABLE quint64 blockchainTargetHeight() const;
|
|
|
|
Q_INVOKABLE double miningHashRate() const;
|
2017-08-06 14:47:11 +00:00
|
|
|
Q_INVOKABLE bool localDaemonSynced() const;
|
2017-12-11 21:44:01 +00:00
|
|
|
Q_INVOKABLE bool isDaemonLocal(const QString &daemon_address) const;
|
2016-11-24 11:14:46 +00:00
|
|
|
|
2019-05-30 10:48:57 +00:00
|
|
|
Q_INVOKABLE void miningStatusAsync() const;
|
2017-03-02 14:44:37 +00:00
|
|
|
Q_INVOKABLE bool startMining(const QString &address, quint32 threads, bool backgroundMining, bool ignoreBattery);
|
2016-12-28 21:20:05 +00:00
|
|
|
Q_INVOKABLE bool stopMining();
|
|
|
|
|
2016-09-05 19:07:53 +00:00
|
|
|
// QML missing such functionality, implementing these helpers here
|
|
|
|
Q_INVOKABLE QString urlToLocalPath(const QUrl &url) const;
|
|
|
|
Q_INVOKABLE QUrl localPathToUrl(const QString &path) const;
|
|
|
|
|
2017-01-09 12:45:00 +00:00
|
|
|
Q_INVOKABLE void setLogLevel(int logLevel);
|
2017-01-16 21:56:37 +00:00
|
|
|
Q_INVOKABLE void setLogCategories(const QString &categories);
|
2016-08-23 07:32:01 +00:00
|
|
|
|
2016-11-10 19:55:44 +00:00
|
|
|
Q_INVOKABLE quint64 add(quint64 x, quint64 y) const { return x + y; }
|
|
|
|
Q_INVOKABLE quint64 sub(quint64 x, quint64 y) const { return x - y; }
|
|
|
|
Q_INVOKABLE qint64 addi(qint64 x, qint64 y) const { return x + y; }
|
|
|
|
Q_INVOKABLE qint64 subi(qint64 x, qint64 y) const { return x - y; }
|
|
|
|
|
2017-12-24 01:29:08 +00:00
|
|
|
#ifndef DISABLE_PASS_STRENGTH_METER
|
2016-12-16 00:11:37 +00:00
|
|
|
Q_INVOKABLE double getPasswordStrength(const QString &password) const;
|
2017-12-24 01:29:08 +00:00
|
|
|
#endif
|
2016-12-16 00:11:37 +00:00
|
|
|
|
2016-12-17 15:57:42 +00:00
|
|
|
Q_INVOKABLE QString resolveOpenAlias(const QString &address) const;
|
2018-11-30 03:51:03 +00:00
|
|
|
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) const;
|
|
|
|
Q_INVOKABLE QVariantMap parse_uri_to_object(const QString &uri) const;
|
2017-01-23 04:15:49 +00:00
|
|
|
Q_INVOKABLE bool saveQrCode(const QString &, const QString &) const;
|
2017-08-05 22:10:59 +00:00
|
|
|
Q_INVOKABLE void checkUpdatesAsync(const QString &software, const QString &subdir) const;
|
2017-02-19 10:38:03 +00:00
|
|
|
Q_INVOKABLE QString checkUpdates(const QString &software, const QString &subdir) const;
|
2016-12-17 15:57:42 +00:00
|
|
|
|
2017-05-03 12:37:33 +00:00
|
|
|
// clear/rename wallet cache
|
|
|
|
Q_INVOKABLE bool clearWalletCache(const QString &fileName) const;
|
|
|
|
|
2019-03-27 08:28:42 +00:00
|
|
|
Q_INVOKABLE void onWalletPassphraseNeeded(Monero::Wallet * wallet);
|
|
|
|
Q_INVOKABLE void onPassphraseEntered(const QString &passphrase, bool entry_abort=false);
|
|
|
|
|
2016-02-23 15:59:26 +00:00
|
|
|
signals:
|
|
|
|
|
2016-08-18 18:55:34 +00:00
|
|
|
void walletOpened(Wallet * wallet);
|
2019-03-27 08:28:42 +00:00
|
|
|
void walletCreated(Wallet * wallet);
|
|
|
|
void walletPassphraseNeeded();
|
|
|
|
void deviceButtonRequest(quint64 buttonCode);
|
|
|
|
void deviceButtonPressed();
|
2016-08-18 18:55:34 +00:00
|
|
|
void walletClosed(const QString &walletAddress);
|
2017-08-05 22:10:59 +00:00
|
|
|
void checkUpdatesComplete(const QString &result) const;
|
2019-05-30 10:48:57 +00:00
|
|
|
void miningStatus(bool isMining) const;
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2016-08-18 18:55:34 +00:00
|
|
|
public slots:
|
2016-02-24 10:25:20 +00:00
|
|
|
private:
|
2019-03-27 08:28:42 +00:00
|
|
|
friend class WalletPassphraseListenerImpl;
|
2016-06-07 13:26:25 +00:00
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
explicit WalletManager(QObject *parent = 0);
|
2019-05-30 10:48:57 +00:00
|
|
|
|
|
|
|
bool isMining() const;
|
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
static WalletManager * m_instance;
|
2016-12-13 18:51:07 +00:00
|
|
|
Monero::WalletManager * m_pimpl;
|
2019-05-28 15:46:26 +00:00
|
|
|
mutable QMutex m_mutex;
|
2016-12-13 22:44:44 +00:00
|
|
|
QPointer<Wallet> m_currentWallet;
|
2016-06-07 13:26:25 +00:00
|
|
|
|
2019-03-27 08:28:42 +00:00
|
|
|
QWaitCondition m_cond_pass;
|
|
|
|
QMutex m_mutex_pass;
|
|
|
|
QString m_passphrase;
|
|
|
|
bool m_passphrase_abort;
|
2016-02-23 15:59:26 +00:00
|
|
|
};
|
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
#endif // WALLETMANAGER_H
|