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
|
|
|
#include "WalletManager.h"
|
2016-02-24 10:25:20 +00:00
|
|
|
#include "Wallet.h"
|
2017-12-08 07:29:28 +00:00
|
|
|
#include "wallet/api/wallet2_api.h"
|
2016-12-16 00:11:37 +00:00
|
|
|
#include "zxcvbn-c/zxcvbn.h"
|
2017-01-23 04:15:49 +00:00
|
|
|
#include "QRCodeImageProvider.h"
|
2016-02-24 10:25:20 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QUrl>
|
2016-08-18 18:55:34 +00:00
|
|
|
#include <QtConcurrent/QtConcurrent>
|
2016-12-13 22:44:44 +00:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QMutexLocker>
|
2017-05-03 12:37:33 +00:00
|
|
|
#include <QString>
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2019-03-27 08:28:42 +00:00
|
|
|
class WalletPassphraseListenerImpl : public Monero::WalletListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WalletPassphraseListenerImpl(WalletManager * mgr): m_mgr(mgr), m_wallet(nullptr) {}
|
|
|
|
|
|
|
|
virtual void moneySpent(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
|
|
|
|
virtual void moneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
|
|
|
|
virtual void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
|
|
|
|
virtual void newBlock(uint64_t height) override { (void) height; };
|
|
|
|
virtual void updated() override {};
|
|
|
|
virtual void refreshed() override {};
|
|
|
|
|
|
|
|
virtual Monero::optional<std::string> onDevicePassphraseRequest(bool on_device) override
|
|
|
|
{
|
|
|
|
qDebug() << __FUNCTION__;
|
|
|
|
if (on_device) return Monero::optional<std::string>();
|
|
|
|
|
|
|
|
m_mgr->onWalletPassphraseNeeded(m_wallet);
|
|
|
|
|
|
|
|
if (m_mgr->m_passphrase_abort)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Passphrase entry abort");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto tmpPass = m_mgr->m_passphrase.toStdString();
|
|
|
|
m_mgr->m_passphrase = QString::null;
|
|
|
|
|
|
|
|
return Monero::optional<std::string>(tmpPass);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDeviceButtonRequest(uint64_t code) override
|
|
|
|
{
|
|
|
|
emit m_mgr->deviceButtonRequest(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDeviceButtonPressed() override
|
|
|
|
{
|
|
|
|
emit m_mgr->deviceButtonPressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onSetWallet(Monero::Wallet * wallet) override
|
|
|
|
{
|
|
|
|
qDebug() << __FUNCTION__;
|
|
|
|
m_wallet = wallet;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WalletManager * m_mgr;
|
2019-05-28 15:55:10 +00:00
|
|
|
Monero::Wallet * m_wallet;
|
2019-03-27 08:28:42 +00:00
|
|
|
};
|
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
WalletManager * WalletManager::m_instance = nullptr;
|
|
|
|
|
|
|
|
WalletManager *WalletManager::instance()
|
|
|
|
{
|
|
|
|
if (!m_instance) {
|
|
|
|
m_instance = new WalletManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
Wallet *WalletManager::createWallet(const QString &path, const QString &password,
|
2018-07-06 09:39:58 +00:00
|
|
|
const QString &language, NetworkType::Type nettype, quint64 kdfRounds)
|
2016-02-24 10:25:20 +00:00
|
|
|
{
|
2016-12-13 22:44:44 +00:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
if (m_currentWallet) {
|
|
|
|
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
|
|
|
|
delete m_currentWallet;
|
|
|
|
}
|
2016-12-13 18:51:07 +00:00
|
|
|
Monero::Wallet * w = m_pimpl->createWallet(path.toStdString(), password.toStdString(),
|
2018-07-06 09:39:58 +00:00
|
|
|
language.toStdString(), static_cast<Monero::NetworkType>(nettype), kdfRounds);
|
2016-12-13 22:44:44 +00:00
|
|
|
m_currentWallet = new Wallet(w);
|
|
|
|
return m_currentWallet;
|
2016-02-29 14:39:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 09:39:58 +00:00
|
|
|
Wallet *WalletManager::openWallet(const QString &path, const QString &password, NetworkType::Type nettype, quint64 kdfRounds)
|
2016-02-29 14:39:39 +00:00
|
|
|
{
|
2016-12-13 22:44:44 +00:00
|
|
|
QMutexLocker locker(&m_mutex);
|
2019-03-27 08:28:42 +00:00
|
|
|
WalletPassphraseListenerImpl tmpListener(this);
|
|
|
|
|
2016-12-13 22:44:44 +00:00
|
|
|
if (m_currentWallet) {
|
|
|
|
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
|
|
|
|
delete m_currentWallet;
|
|
|
|
}
|
2018-03-05 16:19:45 +00:00
|
|
|
qDebug("%s: opening wallet at %s, nettype = %d ",
|
|
|
|
__PRETTY_FUNCTION__, qPrintable(path), nettype);
|
2016-02-29 14:39:39 +00:00
|
|
|
|
2019-03-27 08:28:42 +00:00
|
|
|
Monero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), static_cast<Monero::NetworkType>(nettype), kdfRounds, &tmpListener);
|
|
|
|
w->setListener(nullptr);
|
|
|
|
|
2017-07-04 03:34:09 +00:00
|
|
|
qDebug("%s: opened wallet: %s, status: %d", __PRETTY_FUNCTION__, w->address(0, 0).c_str(), w->status());
|
2016-12-13 22:44:44 +00:00
|
|
|
m_currentWallet = new Wallet(w);
|
2016-08-19 11:44:44 +00:00
|
|
|
|
|
|
|
// move wallet to the GUI thread. Otherwise it wont be emitting signals
|
2016-12-13 22:44:44 +00:00
|
|
|
if (m_currentWallet->thread() != qApp->thread()) {
|
|
|
|
m_currentWallet->moveToThread(qApp->thread());
|
2016-08-19 11:44:44 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 22:44:44 +00:00
|
|
|
return m_currentWallet;
|
2016-02-24 10:25:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 09:39:58 +00:00
|
|
|
void WalletManager::openWalletAsync(const QString &path, const QString &password, NetworkType::Type nettype, quint64 kdfRounds)
|
2016-08-18 18:55:34 +00:00
|
|
|
{
|
2019-06-20 20:28:59 +00:00
|
|
|
m_scheduler.run([this, path, password, nettype, kdfRounds] {
|
|
|
|
emit walletOpened(openWallet(path, password, nettype, kdfRounds));
|
2016-08-18 18:55:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2018-07-06 09:39:58 +00:00
|
|
|
Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, NetworkType::Type nettype, quint64 restoreHeight, quint64 kdfRounds)
|
2016-02-24 10:25:20 +00:00
|
|
|
{
|
2016-12-13 22:44:44 +00:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
if (m_currentWallet) {
|
|
|
|
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
|
|
|
|
delete m_currentWallet;
|
|
|
|
}
|
2018-07-06 09:39:58 +00:00
|
|
|
Monero::Wallet * w = m_pimpl->recoveryWallet(path.toStdString(), "", memo.toStdString(), static_cast<Monero::NetworkType>(nettype), restoreHeight, kdfRounds);
|
2016-12-13 22:44:44 +00:00
|
|
|
m_currentWallet = new Wallet(w);
|
|
|
|
return m_currentWallet;
|
2016-02-29 14:39:39 +00:00
|
|
|
}
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2018-03-05 16:19:45 +00:00
|
|
|
Wallet *WalletManager::createWalletFromKeys(const QString &path, const QString &language, 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, quint64 kdfRounds)
|
2017-01-26 20:49:32 +00:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
if (m_currentWallet) {
|
|
|
|
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
|
|
|
|
delete m_currentWallet;
|
|
|
|
m_currentWallet = NULL;
|
|
|
|
}
|
2018-07-06 09:39:58 +00:00
|
|
|
Monero::Wallet * w = m_pimpl->createWalletFromKeys(path.toStdString(), "", language.toStdString(), static_cast<Monero::NetworkType>(nettype), restoreHeight,
|
|
|
|
address.toStdString(), viewkey.toStdString(), spendkey.toStdString(), kdfRounds);
|
2017-01-26 20:49:32 +00:00
|
|
|
m_currentWallet = new Wallet(w);
|
|
|
|
return m_currentWallet;
|
|
|
|
}
|
|
|
|
|
2018-06-04 08:05:29 +00:00
|
|
|
Wallet *WalletManager::createWalletFromDevice(const QString &path, const QString &password, NetworkType::Type nettype,
|
|
|
|
const QString &deviceName, quint64 restoreHeight, const QString &subaddressLookahead)
|
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2019-03-27 08:28:42 +00:00
|
|
|
WalletPassphraseListenerImpl tmpListener(this);
|
|
|
|
|
2018-06-04 08:05:29 +00:00
|
|
|
if (m_currentWallet) {
|
|
|
|
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
|
|
|
|
delete m_currentWallet;
|
|
|
|
m_currentWallet = NULL;
|
|
|
|
}
|
|
|
|
Monero::Wallet * w = m_pimpl->createWalletFromDevice(path.toStdString(), password.toStdString(), static_cast<Monero::NetworkType>(nettype),
|
2019-03-27 08:28:42 +00:00
|
|
|
deviceName.toStdString(), restoreHeight, subaddressLookahead.toStdString(), 1, &tmpListener);
|
|
|
|
w->setListener(nullptr);
|
|
|
|
|
2018-06-04 08:05:29 +00:00
|
|
|
m_currentWallet = new Wallet(w);
|
2019-03-27 08:28:42 +00:00
|
|
|
|
|
|
|
// move wallet to the GUI thread. Otherwise it wont be emitting signals
|
|
|
|
if (m_currentWallet->thread() != qApp->thread()) {
|
|
|
|
m_currentWallet->moveToThread(qApp->thread());
|
|
|
|
}
|
|
|
|
|
2018-06-04 08:05:29 +00:00
|
|
|
return m_currentWallet;
|
|
|
|
}
|
2016-06-07 13:26:25 +00:00
|
|
|
|
2019-03-27 08:28:42 +00:00
|
|
|
|
|
|
|
void WalletManager::createWalletFromDeviceAsync(const QString &path, const QString &password, NetworkType::Type nettype,
|
|
|
|
const QString &deviceName, quint64 restoreHeight, const QString &subaddressLookahead)
|
|
|
|
{
|
2019-06-20 20:28:59 +00:00
|
|
|
m_scheduler.run([this, path, password, nettype, deviceName, restoreHeight, subaddressLookahead] {
|
|
|
|
Wallet *wallet = createWalletFromDevice(path, password, nettype, deviceName, restoreHeight, subaddressLookahead);
|
|
|
|
emit walletCreated(wallet);
|
|
|
|
});
|
2019-03-27 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 22:44:44 +00:00
|
|
|
QString WalletManager::closeWallet()
|
2016-02-29 14:39:39 +00:00
|
|
|
{
|
2016-12-13 22:44:44 +00:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
QString result;
|
|
|
|
if (m_currentWallet) {
|
2017-07-04 03:34:09 +00:00
|
|
|
result = m_currentWallet->address(0, 0);
|
2016-12-13 22:44:44 +00:00
|
|
|
delete m_currentWallet;
|
|
|
|
} else {
|
|
|
|
qCritical() << "Trying to close non existing wallet " << m_currentWallet;
|
|
|
|
result = "0";
|
|
|
|
}
|
2016-08-18 18:55:34 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-12-13 22:44:44 +00:00
|
|
|
void WalletManager::closeWalletAsync()
|
2016-08-18 18:55:34 +00:00
|
|
|
{
|
2019-06-20 20:28:59 +00:00
|
|
|
m_scheduler.run([this] {
|
|
|
|
emit walletClosed(closeWallet());
|
2016-08-18 18:55:34 +00:00
|
|
|
});
|
2016-02-29 14:39:39 +00:00
|
|
|
}
|
2016-02-24 10:25:20 +00:00
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
bool WalletManager::walletExists(const QString &path) const
|
2016-02-29 14:39:39 +00:00
|
|
|
{
|
2016-06-07 13:26:25 +00:00
|
|
|
return m_pimpl->walletExists(path.toStdString());
|
2016-02-29 14:39:39 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 13:26:25 +00:00
|
|
|
QStringList WalletManager::findWallets(const QString &path)
|
2016-02-29 14:39:39 +00:00
|
|
|
{
|
2016-06-07 13:26:25 +00:00
|
|
|
std::vector<std::string> found_wallets = m_pimpl->findWallets(path.toStdString());
|
|
|
|
QStringList result;
|
|
|
|
for (const auto &w : found_wallets) {
|
|
|
|
result.append(QString::fromStdString(w));
|
|
|
|
}
|
|
|
|
return result;
|
2016-02-29 14:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString WalletManager::errorString() const
|
|
|
|
{
|
|
|
|
return tr("Unknown error");
|
2016-02-24 10:25:20 +00:00
|
|
|
}
|
2016-02-23 15:59:26 +00:00
|
|
|
|
2016-08-23 13:07:52 +00:00
|
|
|
quint64 WalletManager::maximumAllowedAmount() const
|
|
|
|
{
|
2016-12-13 18:51:07 +00:00
|
|
|
return Monero::Wallet::maximumAllowedAmount();
|
2016-08-23 13:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString WalletManager::maximumAllowedAmountAsSting() const
|
|
|
|
{
|
|
|
|
return WalletManager::displayAmount(WalletManager::maximumAllowedAmount());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WalletManager::displayAmount(quint64 amount) const
|
2016-06-08 10:53:24 +00:00
|
|
|
{
|
2016-12-13 18:51:07 +00:00
|
|
|
return QString::fromStdString(Monero::Wallet::displayAmount(amount));
|
2016-06-08 10:53:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-23 13:07:52 +00:00
|
|
|
quint64 WalletManager::amountFromString(const QString &amount) const
|
2016-06-16 14:13:46 +00:00
|
|
|
{
|
2016-12-13 18:51:07 +00:00
|
|
|
return Monero::Wallet::amountFromString(amount.toStdString());
|
2016-06-16 14:13:46 +00:00
|
|
|
}
|
|
|
|
|
2016-08-23 13:07:52 +00:00
|
|
|
quint64 WalletManager::amountFromDouble(double amount) const
|
2016-06-16 14:13:46 +00:00
|
|
|
{
|
2016-12-13 18:51:07 +00:00
|
|
|
return Monero::Wallet::amountFromDouble(amount);
|
2016-06-16 14:13:46 +00:00
|
|
|
}
|
2016-06-07 13:26:25 +00:00
|
|
|
|
2016-10-16 12:57:56 +00:00
|
|
|
bool WalletManager::paymentIdValid(const QString &payment_id) const
|
|
|
|
{
|
2016-12-13 18:51:07 +00:00
|
|
|
return Monero::Wallet::paymentIdValid(payment_id.toStdString());
|
2016-10-16 12:57:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 16:19:45 +00:00
|
|
|
bool WalletManager::addressValid(const QString &address, NetworkType::Type nettype) const
|
2016-10-16 15:54:53 +00:00
|
|
|
{
|
2018-03-05 16:19:45 +00:00
|
|
|
return Monero::Wallet::addressValid(address.toStdString(), static_cast<Monero::NetworkType>(nettype));
|
2016-10-16 15:54:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 16:19:45 +00:00
|
|
|
bool WalletManager::keyValid(const QString &key, const QString &address, bool isViewKey, NetworkType::Type nettype) const
|
2017-01-26 20:49:32 +00:00
|
|
|
{
|
|
|
|
std::string error;
|
2018-03-05 16:19:45 +00:00
|
|
|
if(!Monero::Wallet::keyValid(key.toStdString(), address.toStdString(), isViewKey, static_cast<Monero::NetworkType>(nettype), error)){
|
2017-01-26 20:49:32 +00:00
|
|
|
qDebug() << QString::fromStdString(error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-05 16:19:45 +00:00
|
|
|
QString WalletManager::paymentIdFromAddress(const QString &address, NetworkType::Type nettype) const
|
2016-10-16 15:54:53 +00:00
|
|
|
{
|
2018-03-05 16:19:45 +00:00
|
|
|
return QString::fromStdString(Monero::Wallet::paymentIdFromAddress(address.toStdString(), static_cast<Monero::NetworkType>(nettype)));
|
2016-10-16 15:54:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 22:13:53 +00:00
|
|
|
void WalletManager::setDaemonAddressAsync(const QString &address)
|
2016-11-24 11:14:46 +00:00
|
|
|
{
|
2019-06-20 20:28:59 +00:00
|
|
|
m_scheduler.run([this, address] {
|
2019-05-27 22:13:53 +00:00
|
|
|
m_pimpl->setDaemonAddress(address.toStdString());
|
|
|
|
});
|
2016-11-24 11:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WalletManager::connected() const
|
|
|
|
{
|
|
|
|
return m_pimpl->connected();
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 WalletManager::networkDifficulty() const
|
|
|
|
{
|
|
|
|
return m_pimpl->networkDifficulty();
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 WalletManager::blockchainHeight() const
|
|
|
|
{
|
|
|
|
return m_pimpl->blockchainHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 WalletManager::blockchainTargetHeight() const
|
|
|
|
{
|
|
|
|
return m_pimpl->blockchainTargetHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
double WalletManager::miningHashRate() const
|
|
|
|
{
|
|
|
|
return m_pimpl->miningHashRate();
|
|
|
|
}
|
|
|
|
|
2016-12-28 21:20:05 +00:00
|
|
|
bool WalletManager::isMining() const
|
|
|
|
{
|
2019-05-28 15:46:26 +00:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
if (m_currentWallet == nullptr || !m_currentWallet->connected())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-28 21:20:05 +00:00
|
|
|
return m_pimpl->isMining();
|
|
|
|
}
|
|
|
|
|
2019-06-20 20:28:59 +00:00
|
|
|
void WalletManager::miningStatusAsync()
|
2019-05-30 10:48:57 +00:00
|
|
|
{
|
2019-06-20 20:28:59 +00:00
|
|
|
m_scheduler.run([this] {
|
2019-05-30 10:48:57 +00:00
|
|
|
emit miningStatus(isMining());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:44:37 +00:00
|
|
|
bool WalletManager::startMining(const QString &address, quint32 threads, bool backgroundMining, bool ignoreBattery)
|
2016-12-28 21:20:05 +00:00
|
|
|
{
|
2017-03-02 13:34:11 +00:00
|
|
|
if(threads == 0)
|
|
|
|
threads = 1;
|
2017-03-02 14:44:37 +00:00
|
|
|
return m_pimpl->startMining(address.toStdString(), threads, backgroundMining, ignoreBattery);
|
2016-12-28 21:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WalletManager::stopMining()
|
|
|
|
{
|
|
|
|
return m_pimpl->stopMining();
|
|
|
|
}
|
|
|
|
|
2017-08-06 14:47:11 +00:00
|
|
|
bool WalletManager::localDaemonSynced() const
|
|
|
|
{
|
|
|
|
return blockchainHeight() > 1 && blockchainHeight() >= blockchainTargetHeight();
|
|
|
|
}
|
|
|
|
|
2017-12-11 21:44:01 +00:00
|
|
|
bool WalletManager::isDaemonLocal(const QString &daemon_address) const
|
|
|
|
{
|
|
|
|
return Monero::Utils::isAddressLocal(daemon_address.toStdString());
|
|
|
|
}
|
|
|
|
|
2016-12-17 15:57:42 +00:00
|
|
|
QString WalletManager::resolveOpenAlias(const QString &address) const
|
|
|
|
{
|
|
|
|
bool dnssec_valid = false;
|
|
|
|
std::string res = m_pimpl->resolveOpenAlias(address.toStdString(), dnssec_valid);
|
|
|
|
res = std::string(dnssec_valid ? "true" : "false") + "|" + res;
|
|
|
|
return QString::fromStdString(res);
|
|
|
|
}
|
2018-11-30 03:51:03 +00:00
|
|
|
bool WalletManager::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
|
2017-01-11 03:16:21 +00:00
|
|
|
{
|
2019-05-28 15:46:26 +00:00
|
|
|
QMutexLocker locker(&m_mutex);
|
2017-01-11 03:16:21 +00:00
|
|
|
if (m_currentWallet)
|
|
|
|
return m_currentWallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-17 15:57:42 +00:00
|
|
|
|
2018-11-30 03:51:03 +00:00
|
|
|
QVariantMap WalletManager::parse_uri_to_object(const QString &uri) const
|
|
|
|
{
|
|
|
|
QString address;
|
|
|
|
QString payment_id;
|
2019-01-16 17:49:14 +00:00
|
|
|
uint64_t amount = 0;
|
2018-11-30 03:51:03 +00:00
|
|
|
QString tx_description;
|
|
|
|
QString recipient_name;
|
|
|
|
QVector<QString> unknown_parameters;
|
|
|
|
QString error;
|
|
|
|
|
|
|
|
QVariantMap result;
|
|
|
|
if (this->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error)) {
|
|
|
|
result.insert("address", address);
|
|
|
|
result.insert("payment_id", payment_id);
|
2019-01-16 17:49:14 +00:00
|
|
|
result.insert("amount", amount > 0 ? this->displayAmount(amount) : "");
|
2018-11-30 03:51:03 +00:00
|
|
|
result.insert("tx_description", tx_description);
|
|
|
|
result.insert("recipient_name", recipient_name);
|
|
|
|
} else {
|
|
|
|
result.insert("error", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-08-23 07:32:01 +00:00
|
|
|
void WalletManager::setLogLevel(int logLevel)
|
|
|
|
{
|
2016-12-13 18:51:07 +00:00
|
|
|
Monero::WalletManagerFactory::setLogLevel(logLevel);
|
2016-08-23 07:32:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 21:56:37 +00:00
|
|
|
void WalletManager::setLogCategories(const QString &categories)
|
|
|
|
{
|
|
|
|
Monero::WalletManagerFactory::setLogCategories(categories.toStdString());
|
|
|
|
}
|
|
|
|
|
2016-09-05 19:07:53 +00:00
|
|
|
QString WalletManager::urlToLocalPath(const QUrl &url) const
|
|
|
|
{
|
|
|
|
return QDir::toNativeSeparators(url.toLocalFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
QUrl WalletManager::localPathToUrl(const QString &path) const
|
|
|
|
{
|
|
|
|
return QUrl::fromLocalFile(path);
|
|
|
|
}
|
|
|
|
|
2017-12-24 01:29:08 +00:00
|
|
|
#ifndef DISABLE_PASS_STRENGTH_METER
|
2016-12-16 00:11:37 +00:00
|
|
|
double WalletManager::getPasswordStrength(const QString &password) const
|
|
|
|
{
|
|
|
|
static const char *local_dict[] = {
|
|
|
|
"monero", "fluffypony", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!ZxcvbnInit("zxcvbn.dict")) {
|
|
|
|
fprintf(stderr, "Failed to open zxcvbn.dict\n");
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
double e = ZxcvbnMatch(password.toStdString().c_str(), local_dict, NULL);
|
|
|
|
ZxcvbnUnInit();
|
|
|
|
return e;
|
|
|
|
}
|
2017-12-24 01:29:08 +00:00
|
|
|
#endif
|
2016-12-16 00:11:37 +00:00
|
|
|
|
2017-01-23 04:15:49 +00:00
|
|
|
bool WalletManager::saveQrCode(const QString &code, const QString &path) const
|
|
|
|
{
|
|
|
|
QSize size;
|
|
|
|
// 240 <=> mainLayout.qrCodeSize (Receive.qml)
|
|
|
|
return QRCodeImageProvider::genQrImage(code, &size).scaled(size.expandedTo(QSize(240, 240)), Qt::KeepAspectRatio).save(path, "PNG", 100);
|
|
|
|
}
|
|
|
|
|
2019-06-20 20:28:59 +00:00
|
|
|
void WalletManager::checkUpdatesAsync(const QString &software, const QString &subdir)
|
2017-08-05 22:10:59 +00:00
|
|
|
{
|
2019-06-20 20:28:59 +00:00
|
|
|
m_scheduler.run([this, software, subdir] {
|
|
|
|
emit checkUpdatesComplete(checkUpdates(software, subdir));
|
2017-08-05 22:10:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-19 10:38:03 +00:00
|
|
|
QString WalletManager::checkUpdates(const QString &software, const QString &subdir) const
|
|
|
|
{
|
2017-08-05 22:10:59 +00:00
|
|
|
qDebug() << "Checking for updates";
|
2017-02-19 10:38:03 +00:00
|
|
|
const std::tuple<bool, std::string, std::string, std::string, std::string> result = Monero::WalletManager::checkUpdates(software.toStdString(), subdir.toStdString());
|
|
|
|
if (!std::get<0>(result))
|
|
|
|
return QString("");
|
|
|
|
return QString::fromStdString(std::get<1>(result) + "|" + std::get<2>(result) + "|" + std::get<3>(result) + "|" + std::get<4>(result));
|
|
|
|
}
|
|
|
|
|
2017-05-03 12:37:33 +00:00
|
|
|
bool WalletManager::clearWalletCache(const QString &wallet_path) const
|
|
|
|
{
|
|
|
|
|
|
|
|
QString fileName = wallet_path;
|
|
|
|
// Make sure wallet file is not .keys
|
|
|
|
fileName.replace(".keys","");
|
|
|
|
QFile walletCache(fileName);
|
|
|
|
QString suffix = ".old_cache";
|
|
|
|
QString newFileName = fileName + suffix;
|
|
|
|
|
|
|
|
// create unique file name
|
|
|
|
for (int i = 1; QFile::exists(newFileName); i++) {
|
|
|
|
newFileName = QString("%1%2.%3").arg(fileName).arg(suffix).arg(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return walletCache.rename(newFileName);
|
|
|
|
}
|
|
|
|
|
2019-06-20 20:28:59 +00:00
|
|
|
WalletManager::WalletManager(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_scheduler(this)
|
2016-06-07 13:26:25 +00:00
|
|
|
{
|
2016-12-13 18:51:07 +00:00
|
|
|
m_pimpl = Monero::WalletManagerFactory::getWalletManager();
|
2016-02-23 15:59:26 +00:00
|
|
|
}
|
2019-03-27 08:28:42 +00:00
|
|
|
|
2019-06-20 20:28:59 +00:00
|
|
|
WalletManager::~WalletManager()
|
|
|
|
{
|
|
|
|
m_scheduler.shutdownWaitForFinished();
|
|
|
|
}
|
|
|
|
|
2019-05-28 15:55:10 +00:00
|
|
|
void WalletManager::onWalletPassphraseNeeded(Monero::Wallet *)
|
2019-03-27 08:28:42 +00:00
|
|
|
{
|
|
|
|
m_mutex_pass.lock();
|
|
|
|
m_passphrase_abort = false;
|
|
|
|
emit this->walletPassphraseNeeded();
|
|
|
|
|
|
|
|
m_cond_pass.wait(&m_mutex_pass);
|
|
|
|
m_mutex_pass.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WalletManager::onPassphraseEntered(const QString &passphrase, bool entry_abort)
|
|
|
|
{
|
|
|
|
m_mutex_pass.lock();
|
|
|
|
m_passphrase = passphrase;
|
|
|
|
m_passphrase_abort = entry_abort;
|
|
|
|
|
|
|
|
m_cond_pass.wakeAll();
|
|
|
|
m_mutex_pass.unlock();
|
|
|
|
}
|