2016-02-23 17:59:26 +02:00
|
|
|
#include "Wallet.h"
|
2016-06-08 13:53:24 +03:00
|
|
|
#include "PendingTransaction.h"
|
2017-01-12 21:53:27 +02:00
|
|
|
#include "UnsignedTransaction.h"
|
2016-06-08 13:53:24 +03:00
|
|
|
#include "TransactionHistory.h"
|
2016-12-10 03:01:04 +02:00
|
|
|
#include "AddressBook.h"
|
2017-07-04 06:34:09 +03:00
|
|
|
#include "Subaddress.h"
|
2019-01-14 14:25:59 +02:00
|
|
|
#include "SubaddressAccount.h"
|
2016-10-02 21:40:40 +03:00
|
|
|
#include "model/TransactionHistoryModel.h"
|
2016-10-07 23:05:51 +03:00
|
|
|
#include "model/TransactionHistorySortFilterModel.h"
|
2016-12-10 03:01:04 +02:00
|
|
|
#include "model/AddressBookModel.h"
|
2017-07-04 06:34:09 +03:00
|
|
|
#include "model/SubaddressModel.h"
|
2019-01-14 14:25:59 +02:00
|
|
|
#include "model/SubaddressAccountModel.h"
|
2017-12-08 09:29:28 +02:00
|
|
|
#include "wallet/api/wallet2_api.h"
|
2016-06-07 16:26:25 +03:00
|
|
|
|
2016-02-29 16:39:39 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QUrl>
|
2016-06-17 16:35:07 +03:00
|
|
|
#include <QTimer>
|
2016-11-08 17:33:36 +02:00
|
|
|
#include <QtConcurrent/QtConcurrent>
|
2016-12-10 03:01:04 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QVector>
|
2017-01-31 11:32:41 +02:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QMutexLocker>
|
2016-02-29 16:39:39 +02:00
|
|
|
|
|
|
|
namespace {
|
2017-02-23 20:47:58 +02:00
|
|
|
static const int DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS = 5;
|
2017-02-24 19:07:46 +02:00
|
|
|
static const int DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS = 30;
|
2016-11-26 17:31:27 +02:00
|
|
|
static const int WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS = 5;
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
2016-12-13 20:51:07 +02:00
|
|
|
class WalletListenerImpl : public Monero::WalletListener
|
2016-07-13 15:24:40 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
WalletListenerImpl(Wallet * w)
|
|
|
|
: m_wallet(w)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void moneySpent(const std::string &txId, uint64_t amount)
|
|
|
|
{
|
2016-07-14 13:09:39 +03:00
|
|
|
qDebug() << __FUNCTION__;
|
2016-09-23 23:51:24 +03:00
|
|
|
emit m_wallet->moneySpent(QString::fromStdString(txId), amount);
|
2016-07-13 15:24:40 +03:00
|
|
|
}
|
|
|
|
|
2016-09-23 23:51:24 +03:00
|
|
|
|
2016-07-13 15:24:40 +03:00
|
|
|
virtual void moneyReceived(const std::string &txId, uint64_t amount)
|
|
|
|
{
|
2016-09-23 23:51:24 +03:00
|
|
|
qDebug() << __FUNCTION__;
|
|
|
|
emit m_wallet->moneyReceived(QString::fromStdString(txId), amount);
|
|
|
|
}
|
|
|
|
|
2017-01-12 20:57:30 +02:00
|
|
|
virtual void unconfirmedMoneyReceived(const std::string &txId, uint64_t amount)
|
|
|
|
{
|
|
|
|
qDebug() << __FUNCTION__;
|
|
|
|
emit m_wallet->unconfirmedMoneyReceived(QString::fromStdString(txId), amount);
|
|
|
|
}
|
|
|
|
|
2016-09-23 23:51:24 +03:00
|
|
|
virtual void newBlock(uint64_t height)
|
|
|
|
{
|
2016-09-26 22:55:25 +03:00
|
|
|
// qDebug() << __FUNCTION__;
|
2017-01-31 11:32:41 +02:00
|
|
|
emit m_wallet->newBlock(height, m_wallet->daemonBlockChainTargetHeight());
|
2016-07-13 15:24:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void updated()
|
|
|
|
{
|
|
|
|
emit m_wallet->updated();
|
|
|
|
}
|
|
|
|
|
|
|
|
// called when wallet refreshed by background thread or explicitly
|
|
|
|
virtual void refreshed()
|
|
|
|
{
|
2016-07-14 13:09:39 +03:00
|
|
|
qDebug() << __FUNCTION__;
|
2016-07-13 15:24:40 +03:00
|
|
|
emit m_wallet->refreshed();
|
|
|
|
}
|
|
|
|
|
2019-03-27 10:28:42 +02:00
|
|
|
virtual void onDeviceButtonRequest(uint64_t code) override
|
|
|
|
{
|
|
|
|
emit m_wallet->deviceButtonRequest(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDeviceButtonPressed() override
|
|
|
|
{
|
|
|
|
emit m_wallet->deviceButtonPressed();
|
|
|
|
}
|
|
|
|
|
2016-07-13 15:24:40 +03:00
|
|
|
private:
|
|
|
|
Wallet * m_wallet;
|
|
|
|
};
|
|
|
|
|
2016-10-02 21:40:40 +03:00
|
|
|
Wallet::Wallet(QObject * parent)
|
|
|
|
: Wallet(nullptr, parent)
|
|
|
|
{
|
|
|
|
}
|
2016-02-29 16:39:39 +02:00
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
QString Wallet::getSeed() const
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
return QString::fromStdString(m_walletImpl->seed());
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
QString Wallet::getSeedLanguage() const
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
return QString::fromStdString(m_walletImpl->getSeedLanguage());
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
void Wallet::setSeedLanguage(const QString &lang)
|
2016-02-24 12:25:20 +02:00
|
|
|
{
|
2016-06-08 13:53:24 +03:00
|
|
|
m_walletImpl->setSeedLanguage(lang.toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
Wallet::Status Wallet::status() const
|
|
|
|
{
|
|
|
|
return static_cast<Status>(m_walletImpl->status());
|
2016-02-24 12:25:20 +02:00
|
|
|
}
|
|
|
|
|
2018-03-05 18:19:45 +02:00
|
|
|
NetworkType::Type Wallet::nettype() const
|
2017-01-23 00:04:46 +02:00
|
|
|
{
|
2018-03-05 18:19:45 +02:00
|
|
|
return static_cast<NetworkType::Type>(m_walletImpl->nettype());
|
2017-01-23 00:04:46 +02:00
|
|
|
}
|
|
|
|
|
2017-01-31 11:32:41 +02:00
|
|
|
|
|
|
|
void Wallet::updateConnectionStatusAsync()
|
2016-07-14 13:09:39 +03:00
|
|
|
{
|
2017-01-31 11:32:41 +02:00
|
|
|
QFuture<Monero::Wallet::ConnectionStatus> future = QtConcurrent::run(m_walletImpl, &Monero::Wallet::connected);
|
|
|
|
QFutureWatcher<Monero::Wallet::ConnectionStatus> *connectionWatcher = new QFutureWatcher<Monero::Wallet::ConnectionStatus>();
|
|
|
|
|
|
|
|
connect(connectionWatcher, &QFutureWatcher<Monero::Wallet::ConnectionStatus>::finished, [=]() {
|
|
|
|
QFuture<Monero::Wallet::ConnectionStatus> future = connectionWatcher->future();
|
|
|
|
connectionWatcher->deleteLater();
|
|
|
|
ConnectionStatus newStatus = static_cast<ConnectionStatus>(future.result());
|
2017-02-05 14:49:25 +02:00
|
|
|
if (newStatus != m_connectionStatus || !m_initialized) {
|
|
|
|
m_initialized = true;
|
2016-11-26 17:31:27 +02:00
|
|
|
m_connectionStatus = newStatus;
|
2017-02-23 20:47:58 +02:00
|
|
|
qDebug() << "NEW STATUS " << newStatus;
|
2017-01-31 11:32:41 +02:00
|
|
|
emit connectionStatusChanged(newStatus);
|
2016-11-26 17:31:27 +02:00
|
|
|
}
|
2017-01-31 11:32:41 +02:00
|
|
|
// Release lock
|
|
|
|
m_connectionStatusRunning = false;
|
|
|
|
});
|
|
|
|
connectionWatcher->setFuture(future);
|
|
|
|
}
|
|
|
|
|
|
|
|
Wallet::ConnectionStatus Wallet::connected(bool forceCheck)
|
|
|
|
{
|
|
|
|
// cache connection status
|
|
|
|
if (forceCheck || !m_initialized || (m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl && !m_connectionStatusRunning) || m_connectionStatusTime.elapsed() > 30000) {
|
2017-01-31 11:34:18 +02:00
|
|
|
qDebug() << "Checking connection status";
|
2017-01-31 11:32:41 +02:00
|
|
|
m_connectionStatusRunning = true;
|
2016-11-26 17:31:27 +02:00
|
|
|
m_connectionStatusTime.restart();
|
2017-01-31 11:32:41 +02:00
|
|
|
updateConnectionStatusAsync();
|
2016-11-26 16:34:56 +02:00
|
|
|
}
|
2016-11-26 17:31:27 +02:00
|
|
|
|
|
|
|
return m_connectionStatus;
|
2016-07-14 13:09:39 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 00:47:28 +03:00
|
|
|
bool Wallet::synchronized() const
|
|
|
|
{
|
|
|
|
return m_walletImpl->synchronized();
|
|
|
|
}
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
QString Wallet::errorString() const
|
2016-02-24 12:25:20 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
return QString::fromStdString(m_walletImpl->errorString());
|
2016-02-24 12:25:20 +02:00
|
|
|
}
|
|
|
|
|
2016-02-29 16:39:39 +02:00
|
|
|
bool Wallet::setPassword(const QString &password)
|
2016-02-24 12:25:20 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
return m_walletImpl->setPassword(password.toStdString());
|
2016-02-23 17:59:26 +02:00
|
|
|
}
|
2016-02-29 16:39:39 +02:00
|
|
|
|
2017-07-04 06:34:09 +03:00
|
|
|
QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2017-07-04 06:34:09 +03:00
|
|
|
return QString::fromStdString(m_walletImpl->address(accountIndex, addressIndex));
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
2016-11-26 16:46:42 +02:00
|
|
|
QString Wallet::path() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(m_walletImpl->path());
|
|
|
|
}
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
bool Wallet::store(const QString &path)
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
return m_walletImpl->store(path.toStdString());
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
2018-06-04 11:05:29 +03:00
|
|
|
bool Wallet::init(const QString &daemonAddress, quint64 upperTransactionLimit, bool isRecovering, bool isRecoveringFromDevice, quint64 restoreHeight)
|
2016-06-08 13:53:24 +03:00
|
|
|
{
|
2017-01-31 11:32:41 +02:00
|
|
|
qDebug() << "init non async";
|
2016-10-10 22:36:57 +03:00
|
|
|
if (isRecovering){
|
|
|
|
qDebug() << "RESTORING";
|
|
|
|
m_walletImpl->setRecoveringFromSeed(true);
|
2018-06-04 11:05:29 +03:00
|
|
|
}
|
|
|
|
if (isRecoveringFromDevice){
|
|
|
|
qDebug() << "RESTORING FROM DEVICE";
|
|
|
|
m_walletImpl->setRecoveringFromDevice(true);
|
|
|
|
}
|
|
|
|
if (isRecovering || isRecoveringFromDevice) {
|
2016-10-10 22:36:57 +03:00
|
|
|
m_walletImpl->setRefreshFromBlockHeight(restoreHeight);
|
|
|
|
}
|
2017-02-25 23:16:58 +02:00
|
|
|
m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit, m_daemonUsername.toStdString(), m_daemonPassword.toStdString());
|
2017-01-31 11:32:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-25 23:16:58 +02:00
|
|
|
void Wallet::setDaemonLogin(const QString &daemonUsername, const QString &daemonPassword)
|
|
|
|
{
|
|
|
|
// store daemon login
|
|
|
|
m_daemonUsername = daemonUsername;
|
|
|
|
m_daemonPassword = daemonPassword;
|
|
|
|
}
|
|
|
|
|
2018-06-04 11:05:29 +03:00
|
|
|
void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLimit, bool isRecovering, bool isRecoveringFromDevice, quint64 restoreHeight)
|
2017-01-31 11:32:41 +02:00
|
|
|
{
|
|
|
|
qDebug() << "initAsync: " + daemonAddress;
|
2017-02-05 14:49:25 +02:00
|
|
|
// Change status to disconnected if connected
|
|
|
|
if(m_connectionStatus != Wallet::ConnectionStatus_Disconnected) {
|
|
|
|
m_connectionStatus = Wallet::ConnectionStatus_Disconnected;
|
|
|
|
emit connectionStatusChanged(m_connectionStatus);
|
|
|
|
}
|
2017-01-31 11:32:41 +02:00
|
|
|
|
|
|
|
QFuture<bool> future = QtConcurrent::run(this, &Wallet::init,
|
2018-06-04 11:05:29 +03:00
|
|
|
daemonAddress, upperTransactionLimit, isRecovering, isRecoveringFromDevice, restoreHeight);
|
2017-01-31 11:32:41 +02:00
|
|
|
QFutureWatcher<bool> * watcher = new QFutureWatcher<bool>();
|
|
|
|
|
|
|
|
connect(watcher, &QFutureWatcher<bool>::finished,
|
|
|
|
this, [this, watcher, daemonAddress, upperTransactionLimit, isRecovering, restoreHeight]() {
|
|
|
|
QFuture<bool> future = watcher->future();
|
|
|
|
watcher->deleteLater();
|
|
|
|
if(future.result()){
|
2017-10-24 19:05:55 +03:00
|
|
|
emit walletCreationHeightChanged();
|
2017-01-31 11:32:41 +02:00
|
|
|
qDebug() << "init async finished - starting refresh";
|
|
|
|
connected(true);
|
|
|
|
m_walletImpl->startRefresh();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
watcher->setFuture(future);
|
2016-07-14 13:09:39 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 18:25:22 +02:00
|
|
|
//! create a view only wallet
|
|
|
|
bool Wallet::createViewOnly(const QString &path, const QString &password) const
|
|
|
|
{
|
|
|
|
// Create path
|
|
|
|
QDir d = QFileInfo(path).absoluteDir();
|
|
|
|
d.mkpath(d.absolutePath());
|
|
|
|
return m_walletImpl->createWatchOnly(path.toStdString(),password.toStdString(),m_walletImpl->getSeedLanguage());
|
|
|
|
}
|
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
bool Wallet::connectToDaemon()
|
|
|
|
{
|
|
|
|
return m_walletImpl->connectToDaemon();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallet::setTrustedDaemon(bool arg)
|
|
|
|
{
|
|
|
|
m_walletImpl->setTrustedDaemon(arg);
|
|
|
|
}
|
|
|
|
|
2017-01-04 18:25:22 +02:00
|
|
|
bool Wallet::viewOnly() const
|
|
|
|
{
|
|
|
|
return m_walletImpl->watchOnly();
|
|
|
|
}
|
|
|
|
|
2017-07-04 06:34:09 +03:00
|
|
|
quint64 Wallet::balance(quint32 accountIndex) const
|
2016-06-08 13:53:24 +03:00
|
|
|
{
|
2017-07-04 06:34:09 +03:00
|
|
|
return m_walletImpl->balance(accountIndex);
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|
|
|
|
|
2017-07-04 06:34:09 +03:00
|
|
|
quint64 Wallet::balanceAll() const
|
2016-06-08 13:53:24 +03:00
|
|
|
{
|
2017-07-04 06:34:09 +03:00
|
|
|
return m_walletImpl->balanceAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 Wallet::unlockedBalance(quint32 accountIndex) const
|
|
|
|
{
|
|
|
|
return m_walletImpl->unlockedBalance(accountIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 Wallet::unlockedBalanceAll() const
|
|
|
|
{
|
|
|
|
return m_walletImpl->unlockedBalanceAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 Wallet::currentSubaddressAccount() const
|
|
|
|
{
|
|
|
|
return m_currentSubaddressAccount;
|
|
|
|
}
|
|
|
|
void Wallet::switchSubaddressAccount(quint32 accountIndex)
|
|
|
|
{
|
|
|
|
if (accountIndex < numSubaddressAccounts())
|
|
|
|
{
|
|
|
|
m_currentSubaddressAccount = accountIndex;
|
|
|
|
m_subaddress->refresh(m_currentSubaddressAccount);
|
|
|
|
m_history->refresh(m_currentSubaddressAccount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Wallet::addSubaddressAccount(const QString& label)
|
|
|
|
{
|
|
|
|
m_walletImpl->addSubaddressAccount(label.toStdString());
|
|
|
|
switchSubaddressAccount(numSubaddressAccounts() - 1);
|
|
|
|
}
|
|
|
|
quint32 Wallet::numSubaddressAccounts() const
|
|
|
|
{
|
|
|
|
return m_walletImpl->numSubaddressAccounts();
|
|
|
|
}
|
|
|
|
quint32 Wallet::numSubaddresses(quint32 accountIndex) const
|
|
|
|
{
|
|
|
|
return m_walletImpl->numSubaddresses(accountIndex);
|
|
|
|
}
|
|
|
|
void Wallet::addSubaddress(const QString& label)
|
|
|
|
{
|
|
|
|
m_walletImpl->addSubaddress(currentSubaddressAccount(), label.toStdString());
|
|
|
|
}
|
|
|
|
QString Wallet::getSubaddressLabel(quint32 accountIndex, quint32 addressIndex) const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(m_walletImpl->getSubaddressLabel(accountIndex, addressIndex));
|
|
|
|
}
|
|
|
|
void Wallet::setSubaddressLabel(quint32 accountIndex, quint32 addressIndex, const QString &label)
|
|
|
|
{
|
|
|
|
m_walletImpl->setSubaddressLabel(accountIndex, addressIndex, label.toStdString());
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 22:55:25 +03:00
|
|
|
quint64 Wallet::blockChainHeight() const
|
|
|
|
{
|
|
|
|
return m_walletImpl->blockChainHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 Wallet::daemonBlockChainHeight() const
|
|
|
|
{
|
|
|
|
// cache daemon blockchain height for some time (60 seconds by default)
|
|
|
|
|
|
|
|
if (m_daemonBlockChainHeight == 0
|
|
|
|
|| m_daemonBlockChainHeightTime.elapsed() / 1000 > m_daemonBlockChainHeightTtl) {
|
|
|
|
m_daemonBlockChainHeight = m_walletImpl->daemonBlockChainHeight();
|
|
|
|
m_daemonBlockChainHeightTime.restart();
|
|
|
|
}
|
|
|
|
return m_daemonBlockChainHeight;
|
|
|
|
}
|
|
|
|
|
2016-10-04 00:29:30 +03:00
|
|
|
quint64 Wallet::daemonBlockChainTargetHeight() const
|
|
|
|
{
|
2017-02-24 19:07:46 +02:00
|
|
|
if (m_daemonBlockChainTargetHeight <= 1
|
2016-11-01 19:14:39 +02:00
|
|
|
|| m_daemonBlockChainTargetHeightTime.elapsed() / 1000 > m_daemonBlockChainTargetHeightTtl) {
|
|
|
|
m_daemonBlockChainTargetHeight = m_walletImpl->daemonBlockChainTargetHeight();
|
2017-01-31 11:32:41 +02:00
|
|
|
|
2016-12-12 23:51:20 +02:00
|
|
|
// Target height is set to 0 if daemon is synced.
|
|
|
|
// Use current height from daemon when target height < current height
|
|
|
|
if (m_daemonBlockChainTargetHeight < m_daemonBlockChainHeight){
|
|
|
|
m_daemonBlockChainTargetHeight = m_daemonBlockChainHeight;
|
|
|
|
}
|
2016-11-01 19:14:39 +02:00
|
|
|
m_daemonBlockChainTargetHeightTime.restart();
|
|
|
|
}
|
|
|
|
|
2016-10-04 00:29:30 +03:00
|
|
|
return m_daemonBlockChainTargetHeight;
|
|
|
|
}
|
|
|
|
|
2018-05-15 00:43:52 +03:00
|
|
|
bool Wallet::exportKeyImages(const QString& path)
|
|
|
|
{
|
|
|
|
return m_walletImpl->exportKeyImages(path.toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wallet::importKeyImages(const QString& path)
|
|
|
|
{
|
|
|
|
return m_walletImpl->importKeyImages(path.toStdString());
|
|
|
|
}
|
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
bool Wallet::refresh()
|
|
|
|
{
|
2016-06-17 16:35:07 +03:00
|
|
|
bool result = m_walletImpl->refresh();
|
2017-07-04 06:34:09 +03:00
|
|
|
m_history->refresh(currentSubaddressAccount());
|
|
|
|
m_subaddress->refresh(currentSubaddressAccount());
|
2019-01-14 14:25:59 +02:00
|
|
|
m_subaddressAccount->getAll(true);
|
2016-06-17 16:35:07 +03:00
|
|
|
if (result)
|
|
|
|
emit updated();
|
|
|
|
return result;
|
2016-06-08 13:53:24 +03:00
|
|
|
}
|
|
|
|
|
2016-07-13 15:24:40 +03:00
|
|
|
void Wallet::refreshAsync()
|
|
|
|
{
|
2017-01-31 11:32:41 +02:00
|
|
|
qDebug() << "refresh async";
|
2016-07-13 15:24:40 +03:00
|
|
|
m_walletImpl->refreshAsync();
|
|
|
|
}
|
|
|
|
|
2016-09-26 22:55:25 +03:00
|
|
|
void Wallet::setAutoRefreshInterval(int seconds)
|
|
|
|
{
|
|
|
|
m_walletImpl->setAutoRefreshInterval(seconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Wallet::autoRefreshInterval() const
|
|
|
|
{
|
|
|
|
return m_walletImpl->autoRefreshInterval();
|
|
|
|
}
|
|
|
|
|
2017-02-25 20:49:09 +02:00
|
|
|
void Wallet::startRefresh() const
|
|
|
|
{
|
|
|
|
m_walletImpl->startRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallet::pauseRefresh() const
|
|
|
|
{
|
|
|
|
m_walletImpl->pauseRefresh();
|
|
|
|
}
|
|
|
|
|
2016-06-26 18:04:45 +03:00
|
|
|
PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QString &payment_id,
|
2016-06-27 15:45:48 +03:00
|
|
|
quint64 amount, quint32 mixin_count,
|
|
|
|
PendingTransaction::Priority priority)
|
2016-06-08 13:53:24 +03:00
|
|
|
{
|
2017-07-04 06:34:09 +03:00
|
|
|
std::set<uint32_t> subaddr_indices;
|
2016-12-13 20:51:07 +02:00
|
|
|
Monero::PendingTransaction * ptImpl = m_walletImpl->createTransaction(
|
2016-06-27 15:45:48 +03:00
|
|
|
dst_addr.toStdString(), payment_id.toStdString(), amount, mixin_count,
|
2017-07-04 06:34:09 +03:00
|
|
|
static_cast<Monero::PendingTransaction::Priority>(priority), currentSubaddressAccount(), subaddr_indices);
|
2016-11-08 20:48:41 +02:00
|
|
|
PendingTransaction * result = new PendingTransaction(ptImpl,0);
|
2016-06-08 13:53:24 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-08 17:33:36 +02:00
|
|
|
void Wallet::createTransactionAsync(const QString &dst_addr, const QString &payment_id,
|
|
|
|
quint64 amount, quint32 mixin_count,
|
|
|
|
PendingTransaction::Priority priority)
|
|
|
|
{
|
|
|
|
QFuture<PendingTransaction*> future = QtConcurrent::run(this, &Wallet::createTransaction,
|
|
|
|
dst_addr, payment_id,amount, mixin_count, priority);
|
|
|
|
QFutureWatcher<PendingTransaction*> * watcher = new QFutureWatcher<PendingTransaction*>();
|
2017-01-31 11:32:41 +02:00
|
|
|
|
2016-11-08 17:33:36 +02:00
|
|
|
connect(watcher, &QFutureWatcher<PendingTransaction*>::finished,
|
2016-11-08 19:02:07 +02:00
|
|
|
this, [this, watcher,dst_addr,payment_id,mixin_count]() {
|
2016-11-08 17:33:36 +02:00
|
|
|
QFuture<PendingTransaction*> future = watcher->future();
|
|
|
|
watcher->deleteLater();
|
2016-11-08 19:02:07 +02:00
|
|
|
emit transactionCreated(future.result(),dst_addr,payment_id,mixin_count);
|
2016-11-08 17:33:36 +02:00
|
|
|
});
|
2017-01-31 11:32:41 +02:00
|
|
|
watcher->setFuture(future);
|
2016-11-08 17:33:36 +02:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:00:43 +02:00
|
|
|
PendingTransaction *Wallet::createTransactionAll(const QString &dst_addr, const QString &payment_id,
|
|
|
|
quint32 mixin_count, PendingTransaction::Priority priority)
|
|
|
|
{
|
2017-07-04 06:34:09 +03:00
|
|
|
std::set<uint32_t> subaddr_indices;
|
2016-12-13 20:51:07 +02:00
|
|
|
Monero::PendingTransaction * ptImpl = m_walletImpl->createTransaction(
|
|
|
|
dst_addr.toStdString(), payment_id.toStdString(), Monero::optional<uint64_t>(), mixin_count,
|
2017-07-04 06:34:09 +03:00
|
|
|
static_cast<Monero::PendingTransaction::Priority>(priority), currentSubaddressAccount(), subaddr_indices);
|
2016-11-09 15:00:43 +02:00
|
|
|
PendingTransaction * result = new PendingTransaction(ptImpl, this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-11 23:54:17 +02:00
|
|
|
void Wallet::createTransactionAllAsync(const QString &dst_addr, const QString &payment_id,
|
|
|
|
quint32 mixin_count,
|
|
|
|
PendingTransaction::Priority priority)
|
|
|
|
{
|
|
|
|
QFuture<PendingTransaction*> future = QtConcurrent::run(this, &Wallet::createTransactionAll,
|
|
|
|
dst_addr, payment_id, mixin_count, priority);
|
|
|
|
QFutureWatcher<PendingTransaction*> * watcher = new QFutureWatcher<PendingTransaction*>();
|
2017-01-31 11:32:41 +02:00
|
|
|
|
2016-11-11 23:54:17 +02:00
|
|
|
connect(watcher, &QFutureWatcher<PendingTransaction*>::finished,
|
|
|
|
this, [this, watcher,dst_addr,payment_id,mixin_count]() {
|
|
|
|
QFuture<PendingTransaction*> future = watcher->future();
|
|
|
|
watcher->deleteLater();
|
|
|
|
emit transactionCreated(future.result(),dst_addr,payment_id,mixin_count);
|
|
|
|
});
|
2017-01-31 11:32:41 +02:00
|
|
|
watcher->setFuture(future);
|
2016-11-11 23:54:17 +02:00
|
|
|
}
|
|
|
|
|
2016-11-08 22:23:50 +02:00
|
|
|
PendingTransaction *Wallet::createSweepUnmixableTransaction()
|
|
|
|
{
|
2016-12-13 20:51:07 +02:00
|
|
|
Monero::PendingTransaction * ptImpl = m_walletImpl->createSweepUnmixableTransaction();
|
2016-11-08 22:23:50 +02:00
|
|
|
PendingTransaction * result = new PendingTransaction(ptImpl, this);
|
|
|
|
return result;
|
|
|
|
}
|
2016-11-08 17:33:36 +02:00
|
|
|
|
2016-11-11 23:54:17 +02:00
|
|
|
void Wallet::createSweepUnmixableTransactionAsync()
|
|
|
|
{
|
|
|
|
QFuture<PendingTransaction*> future = QtConcurrent::run(this, &Wallet::createSweepUnmixableTransaction);
|
|
|
|
QFutureWatcher<PendingTransaction*> * watcher = new QFutureWatcher<PendingTransaction*>();
|
2017-01-31 11:32:41 +02:00
|
|
|
|
2016-11-11 23:54:17 +02:00
|
|
|
connect(watcher, &QFutureWatcher<PendingTransaction*>::finished,
|
|
|
|
this, [this, watcher]() {
|
|
|
|
QFuture<PendingTransaction*> future = watcher->future();
|
|
|
|
watcher->deleteLater();
|
|
|
|
emit transactionCreated(future.result(),"","",0);
|
|
|
|
});
|
2017-01-31 11:32:41 +02:00
|
|
|
watcher->setFuture(future);
|
2016-11-11 23:54:17 +02:00
|
|
|
}
|
|
|
|
|
2017-01-12 21:53:27 +02:00
|
|
|
UnsignedTransaction * Wallet::loadTxFile(const QString &fileName)
|
|
|
|
{
|
|
|
|
qDebug() << "Trying to sign " << fileName;
|
|
|
|
Monero::UnsignedTransaction * ptImpl = m_walletImpl->loadUnsignedTx(fileName.toStdString());
|
2017-01-14 00:43:34 +02:00
|
|
|
UnsignedTransaction * result = new UnsignedTransaction(ptImpl, m_walletImpl, this);
|
2017-01-12 21:53:27 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wallet::submitTxFile(const QString &fileName) const
|
|
|
|
{
|
|
|
|
qDebug() << "Trying to submit " << fileName;
|
2017-01-14 00:43:34 +02:00
|
|
|
if (!m_walletImpl->submitTransaction(fileName.toStdString()))
|
|
|
|
return false;
|
|
|
|
// import key images
|
|
|
|
return m_walletImpl->importKeyImages(fileName.toStdString() + "_keyImages");
|
2017-01-12 21:53:27 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
void Wallet::disposeTransaction(PendingTransaction *t)
|
|
|
|
{
|
|
|
|
m_walletImpl->disposeTransaction(t->m_pimpl);
|
|
|
|
delete t;
|
|
|
|
}
|
|
|
|
|
2017-01-12 21:53:27 +02:00
|
|
|
void Wallet::disposeTransaction(UnsignedTransaction *t)
|
|
|
|
{
|
|
|
|
delete t;
|
|
|
|
}
|
|
|
|
|
2016-10-07 00:47:28 +03:00
|
|
|
TransactionHistory *Wallet::history() const
|
2016-06-08 13:53:24 +03:00
|
|
|
{
|
|
|
|
return m_history;
|
|
|
|
}
|
|
|
|
|
2016-10-07 23:05:51 +03:00
|
|
|
TransactionHistorySortFilterModel *Wallet::historyModel() const
|
2016-10-02 21:40:40 +03:00
|
|
|
{
|
|
|
|
if (!m_historyModel) {
|
2016-10-07 00:47:28 +03:00
|
|
|
Wallet * w = const_cast<Wallet*>(this);
|
|
|
|
m_historyModel = new TransactionHistoryModel(w);
|
2016-10-02 21:40:40 +03:00
|
|
|
m_historyModel->setTransactionHistory(this->history());
|
2016-10-07 23:05:51 +03:00
|
|
|
m_historySortFilterModel = new TransactionHistorySortFilterModel(w);
|
|
|
|
m_historySortFilterModel->setSourceModel(m_historyModel);
|
2019-01-10 12:08:57 +02:00
|
|
|
m_historySortFilterModel->setSortRole(TransactionHistoryModel::TransactionBlockHeightRole);
|
|
|
|
m_historySortFilterModel->sort(0, Qt::DescendingOrder);
|
2016-10-02 21:40:40 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 23:05:51 +03:00
|
|
|
return m_historySortFilterModel;
|
2016-10-02 21:40:40 +03:00
|
|
|
}
|
|
|
|
|
2016-12-10 03:01:04 +02:00
|
|
|
AddressBook *Wallet::addressBook() const
|
|
|
|
{
|
|
|
|
return m_addressBook;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressBookModel *Wallet::addressBookModel() const
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!m_addressBookModel) {
|
|
|
|
Wallet * w = const_cast<Wallet*>(this);
|
|
|
|
m_addressBookModel = new AddressBookModel(w,m_addressBook);
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_addressBookModel;
|
|
|
|
}
|
|
|
|
|
2017-07-04 06:34:09 +03:00
|
|
|
Subaddress *Wallet::subaddress()
|
|
|
|
{
|
|
|
|
return m_subaddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubaddressModel *Wallet::subaddressModel()
|
|
|
|
{
|
|
|
|
if (!m_subaddressModel) {
|
|
|
|
m_subaddressModel = new SubaddressModel(this, m_subaddress);
|
|
|
|
}
|
|
|
|
return m_subaddressModel;
|
|
|
|
}
|
2016-02-29 16:39:39 +02:00
|
|
|
|
2019-01-14 14:25:59 +02:00
|
|
|
SubaddressAccount *Wallet::subaddressAccount() const
|
|
|
|
{
|
|
|
|
return m_subaddressAccount;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubaddressAccountModel *Wallet::subaddressAccountModel() const
|
|
|
|
{
|
|
|
|
if (!m_subaddressAccountModel) {
|
|
|
|
Wallet * w = const_cast<Wallet*>(this);
|
|
|
|
m_subaddressAccountModel = new SubaddressAccountModel(w,m_subaddressAccount);
|
|
|
|
}
|
|
|
|
return m_subaddressAccountModel;
|
|
|
|
}
|
|
|
|
|
2016-06-26 18:04:45 +03:00
|
|
|
QString Wallet::generatePaymentId() const
|
|
|
|
{
|
2016-12-13 20:51:07 +02:00
|
|
|
return QString::fromStdString(Monero::Wallet::genPaymentId());
|
2016-06-26 18:04:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallet::integratedAddress(const QString &paymentId) const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(m_walletImpl->integratedAddress(paymentId.toStdString()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallet::paymentId() const
|
|
|
|
{
|
|
|
|
return m_paymentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallet::setPaymentId(const QString &paymentId)
|
|
|
|
{
|
|
|
|
m_paymentId = paymentId;
|
|
|
|
}
|
|
|
|
|
2016-11-06 01:19:28 +02:00
|
|
|
bool Wallet::setUserNote(const QString &txid, const QString ¬e)
|
|
|
|
{
|
|
|
|
return m_walletImpl->setUserNote(txid.toStdString(), note.toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallet::getUserNote(const QString &txid) const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(m_walletImpl->getUserNote(txid.toStdString()));
|
|
|
|
}
|
2016-02-29 16:39:39 +02:00
|
|
|
|
2016-11-06 20:27:08 +02:00
|
|
|
QString Wallet::getTxKey(const QString &txid) const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(m_walletImpl->getTxKey(txid.toStdString()));
|
|
|
|
}
|
|
|
|
|
2017-09-12 11:42:00 +03:00
|
|
|
QString Wallet::checkTxKey(const QString &txid, const QString &tx_key, const QString &address)
|
|
|
|
{
|
|
|
|
uint64_t received;
|
|
|
|
bool in_pool;
|
|
|
|
uint64_t confirmations;
|
|
|
|
bool success = m_walletImpl->checkTxKey(txid.toStdString(), tx_key.toStdString(), address.toStdString(), received, in_pool, confirmations);
|
|
|
|
std::string result = std::string(success ? "true" : "false") + "|" + QString::number(received).toStdString() + "|" + std::string(in_pool ? "true" : "false") + "|" + QString::number(confirmations).toStdString();
|
|
|
|
return QString::fromStdString(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallet::getTxProof(const QString &txid, const QString &address, const QString &message) const
|
|
|
|
{
|
2017-11-20 09:24:29 +02:00
|
|
|
std::string result = m_walletImpl->getTxProof(txid.toStdString(), address.toStdString(), message.toStdString());
|
|
|
|
if (result.empty())
|
|
|
|
result = "error|" + m_walletImpl->errorString();
|
|
|
|
return QString::fromStdString(result);
|
2017-09-12 11:42:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallet::checkTxProof(const QString &txid, const QString &address, const QString &message, const QString &signature)
|
|
|
|
{
|
|
|
|
bool good;
|
|
|
|
uint64_t received;
|
|
|
|
bool in_pool;
|
|
|
|
uint64_t confirmations;
|
|
|
|
bool success = m_walletImpl->checkTxProof(txid.toStdString(), address.toStdString(), message.toStdString(), signature.toStdString(), good, received, in_pool, confirmations);
|
|
|
|
std::string result = std::string(success ? "true" : "false") + "|" + std::string(good ? "true" : "false") + "|" + QString::number(received).toStdString() + "|" + std::string(in_pool ? "true" : "false") + "|" + QString::number(confirmations).toStdString();
|
|
|
|
return QString::fromStdString(result);
|
|
|
|
}
|
|
|
|
|
2017-11-20 09:12:36 +02:00
|
|
|
Q_INVOKABLE QString Wallet::getSpendProof(const QString &txid, const QString &message) const
|
|
|
|
{
|
|
|
|
std::string result = m_walletImpl->getSpendProof(txid.toStdString(), message.toStdString());
|
|
|
|
if (result.empty())
|
|
|
|
result = "error|" + m_walletImpl->errorString();
|
|
|
|
return QString::fromStdString(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_INVOKABLE QString Wallet::checkSpendProof(const QString &txid, const QString &message, const QString &signature) const
|
|
|
|
{
|
|
|
|
bool good;
|
|
|
|
bool success = m_walletImpl->checkSpendProof(txid.toStdString(), message.toStdString(), signature.toStdString(), good);
|
|
|
|
std::string result = std::string(success ? "true" : "false") + "|" + std::string(!success ? m_walletImpl->errorString() : good ? "true" : "false");
|
|
|
|
return QString::fromStdString(result);
|
|
|
|
}
|
|
|
|
|
2016-11-08 12:06:34 +02:00
|
|
|
QString Wallet::signMessage(const QString &message, bool filename) const
|
|
|
|
{
|
|
|
|
if (filename) {
|
|
|
|
QFile file(message);
|
|
|
|
uchar *data = NULL;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return "";
|
|
|
|
quint64 size = file.size();
|
|
|
|
if (size == 0) {
|
|
|
|
file.close();
|
|
|
|
return QString::fromStdString(m_walletImpl->signMessage(std::string()));
|
|
|
|
}
|
|
|
|
data = file.map(0, size);
|
|
|
|
if (!data) {
|
|
|
|
file.close();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
std::string signature = m_walletImpl->signMessage(std::string((const char*)data, size));
|
|
|
|
file.unmap(data);
|
|
|
|
file.close();
|
|
|
|
return QString::fromStdString(signature);
|
|
|
|
}
|
|
|
|
catch (const std::exception &e) {
|
|
|
|
if (data)
|
|
|
|
file.unmap(data);
|
|
|
|
file.close();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return QString::fromStdString(m_walletImpl->signMessage(message.toStdString()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wallet::verifySignedMessage(const QString &message, const QString &address, const QString &signature, bool filename) const
|
|
|
|
{
|
|
|
|
if (filename) {
|
|
|
|
QFile file(message);
|
|
|
|
uchar *data = NULL;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return false;
|
|
|
|
quint64 size = file.size();
|
|
|
|
if (size == 0) {
|
|
|
|
file.close();
|
|
|
|
return m_walletImpl->verifySignedMessage(std::string(), address.toStdString(), signature.toStdString());
|
|
|
|
}
|
|
|
|
data = file.map(0, size);
|
|
|
|
if (!data) {
|
|
|
|
file.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool ret = m_walletImpl->verifySignedMessage(std::string((const char*)data, size), address.toStdString(), signature.toStdString());
|
|
|
|
file.unmap(data);
|
|
|
|
file.close();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
catch (const std::exception &e) {
|
|
|
|
if (data)
|
|
|
|
file.unmap(data);
|
|
|
|
file.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return m_walletImpl->verifySignedMessage(message.toStdString(), address.toStdString(), signature.toStdString());
|
|
|
|
}
|
|
|
|
}
|
2017-01-11 05:16:21 +02:00
|
|
|
bool Wallet::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)
|
|
|
|
{
|
|
|
|
std::string s_address, s_payment_id, s_tx_description, s_recipient_name, s_error;
|
|
|
|
std::vector<std::string> s_unknown_parameters;
|
|
|
|
bool res= m_walletImpl->parse_uri(uri.toStdString(), s_address, s_payment_id, amount, s_tx_description, s_recipient_name, s_unknown_parameters, s_error);
|
|
|
|
if(res)
|
|
|
|
{
|
|
|
|
address = QString::fromStdString(s_address);
|
|
|
|
payment_id = QString::fromStdString(s_payment_id);
|
|
|
|
tx_description = QString::fromStdString(s_tx_description);
|
|
|
|
recipient_name = QString::fromStdString(s_recipient_name);
|
|
|
|
for( const auto &p : s_unknown_parameters )
|
|
|
|
unknown_parameters.append(QString::fromStdString(p));
|
|
|
|
}
|
|
|
|
error = QString::fromStdString(s_error);
|
|
|
|
return res;
|
|
|
|
}
|
2016-11-08 12:06:34 +02:00
|
|
|
|
2017-01-12 23:28:37 +02:00
|
|
|
bool Wallet::rescanSpent()
|
|
|
|
{
|
|
|
|
return m_walletImpl->rescanSpent();
|
|
|
|
}
|
|
|
|
|
2017-03-23 23:54:35 +02:00
|
|
|
bool Wallet::useForkRules(quint8 required_version, quint64 earlyBlocks) const
|
|
|
|
{
|
2017-03-26 20:02:18 +03:00
|
|
|
if(m_connectionStatus == Wallet::ConnectionStatus_Disconnected)
|
|
|
|
return false;
|
|
|
|
try {
|
|
|
|
return m_walletImpl->useForkRules(required_version,earlyBlocks);
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
qDebug() << e.what();
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-23 23:54:35 +02:00
|
|
|
}
|
|
|
|
|
2017-10-23 19:33:10 +03:00
|
|
|
void Wallet::setWalletCreationHeight(quint64 height)
|
|
|
|
{
|
|
|
|
m_walletImpl->setRefreshFromBlockHeight(height);
|
|
|
|
emit walletCreationHeightChanged();
|
|
|
|
}
|
|
|
|
|
2017-08-24 12:30:50 +03:00
|
|
|
QString Wallet::getDaemonLogPath() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(m_walletImpl->getDefaultDataDir()) + "/bitmonero.log";
|
|
|
|
}
|
|
|
|
|
2018-09-30 11:12:44 +03:00
|
|
|
bool Wallet::blackballOutput(const QString &amount, const QString &offset)
|
2018-03-07 02:01:53 +02:00
|
|
|
{
|
2018-09-30 11:12:44 +03:00
|
|
|
return m_walletImpl->blackballOutput(amount.toStdString(), offset.toStdString());
|
2018-03-07 02:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Wallet::blackballOutputs(const QList<QString> &pubkeys, bool add)
|
|
|
|
{
|
|
|
|
std::vector<std::string> std_pubkeys;
|
|
|
|
foreach (const QString &pubkey, pubkeys) {
|
|
|
|
std_pubkeys.push_back(pubkey.toStdString());
|
|
|
|
}
|
|
|
|
return m_walletImpl->blackballOutputs(std_pubkeys, add);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wallet::blackballOutputs(const QString &filename, bool add)
|
|
|
|
{
|
|
|
|
QFile file(filename);
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return false;
|
|
|
|
QList<QString> outputs;
|
|
|
|
QTextStream in(&file);
|
|
|
|
while (!in.atEnd()) {
|
|
|
|
outputs.push_back(in.readLine());
|
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
return blackballOutputs(outputs, add);
|
|
|
|
}
|
|
|
|
catch (const std::exception &e) {
|
|
|
|
file.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 11:12:44 +03:00
|
|
|
bool Wallet::unblackballOutput(const QString &amount, const QString &offset)
|
2018-03-07 02:01:53 +02:00
|
|
|
{
|
2018-09-30 11:12:44 +03:00
|
|
|
return m_walletImpl->unblackballOutput(amount.toStdString(), offset.toStdString());
|
2018-03-07 02:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallet::getRing(const QString &key_image)
|
|
|
|
{
|
|
|
|
std::vector<uint64_t> cring;
|
|
|
|
if (!m_walletImpl->getRing(key_image.toStdString(), cring))
|
|
|
|
return "";
|
|
|
|
QString ring = "";
|
|
|
|
for (uint64_t out: cring)
|
|
|
|
{
|
|
|
|
if (!ring.isEmpty())
|
|
|
|
ring = ring + " ";
|
|
|
|
QString s;
|
|
|
|
s.setNum(out);
|
|
|
|
ring = ring + s;
|
|
|
|
}
|
|
|
|
return ring;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Wallet::getRings(const QString &txid)
|
|
|
|
{
|
|
|
|
std::vector<std::pair<std::string, std::vector<uint64_t>>> crings;
|
|
|
|
if (!m_walletImpl->getRings(txid.toStdString(), crings))
|
|
|
|
return "";
|
|
|
|
QString ring = "";
|
|
|
|
for (const auto &cring: crings)
|
|
|
|
{
|
|
|
|
if (!ring.isEmpty())
|
|
|
|
ring = ring + "|";
|
|
|
|
ring = ring + QString::fromStdString(cring.first) + " absolute";
|
|
|
|
for (uint64_t out: cring.second)
|
|
|
|
{
|
|
|
|
ring = ring + " ";
|
|
|
|
QString s;
|
|
|
|
s.setNum(out);
|
|
|
|
ring = ring + s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ring;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Wallet::setRing(const QString &key_image, const QString &ring, bool relative)
|
|
|
|
{
|
|
|
|
std::vector<uint64_t> cring;
|
|
|
|
QStringList strOuts = ring.split(" ");
|
|
|
|
foreach(QString str, strOuts)
|
|
|
|
{
|
|
|
|
uint64_t out;
|
|
|
|
bool ok;
|
|
|
|
out = str.toULong(&ok);
|
|
|
|
if (ok)
|
|
|
|
cring.push_back(out);
|
|
|
|
}
|
|
|
|
return m_walletImpl->setRing(key_image.toStdString(), cring, relative);
|
|
|
|
}
|
|
|
|
|
2018-03-16 13:55:56 +02:00
|
|
|
void Wallet::segregatePreForkOutputs(bool segregate)
|
|
|
|
{
|
|
|
|
m_walletImpl->segregatePreForkOutputs(segregate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallet::segregationHeight(quint64 height)
|
|
|
|
{
|
|
|
|
m_walletImpl->segregationHeight(height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wallet::keyReuseMitigation2(bool mitigation)
|
|
|
|
{
|
|
|
|
m_walletImpl->keyReuseMitigation2(mitigation);
|
|
|
|
}
|
|
|
|
|
2016-12-13 20:51:07 +02:00
|
|
|
Wallet::Wallet(Monero::Wallet *w, QObject *parent)
|
2016-09-26 22:55:25 +03:00
|
|
|
: QObject(parent)
|
|
|
|
, m_walletImpl(w)
|
|
|
|
, m_history(nullptr)
|
2016-10-02 21:40:40 +03:00
|
|
|
, m_historyModel(nullptr)
|
2016-12-10 03:01:04 +02:00
|
|
|
, m_addressBook(nullptr)
|
|
|
|
, m_addressBookModel(nullptr)
|
2017-07-04 06:34:09 +03:00
|
|
|
, m_subaddress(nullptr)
|
|
|
|
, m_subaddressModel(nullptr)
|
2019-01-14 14:25:59 +02:00
|
|
|
, m_subaddressAccount(nullptr)
|
|
|
|
, m_subaddressAccountModel(nullptr)
|
2016-09-26 22:55:25 +03:00
|
|
|
, m_daemonBlockChainHeight(0)
|
|
|
|
, m_daemonBlockChainHeightTtl(DAEMON_BLOCKCHAIN_HEIGHT_CACHE_TTL_SECONDS)
|
2016-11-01 19:14:39 +02:00
|
|
|
, m_daemonBlockChainTargetHeight(0)
|
|
|
|
, m_daemonBlockChainTargetHeightTtl(DAEMON_BLOCKCHAIN_TARGET_HEIGHT_CACHE_TTL_SECONDS)
|
2016-11-26 17:31:27 +02:00
|
|
|
, m_connectionStatusTtl(WALLET_CONNECTION_STATUS_CACHE_TTL_SECONDS)
|
2017-07-04 06:34:09 +03:00
|
|
|
, m_currentSubaddressAccount(0)
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2016-10-04 23:12:58 +03:00
|
|
|
m_history = new TransactionHistory(m_walletImpl->history(), this);
|
2016-12-10 03:01:04 +02:00
|
|
|
m_addressBook = new AddressBook(m_walletImpl->addressBook(), this);
|
2017-07-04 06:34:09 +03:00
|
|
|
m_subaddress = new Subaddress(m_walletImpl->subaddress(), this);
|
2019-01-14 14:25:59 +02:00
|
|
|
m_subaddressAccount = new SubaddressAccount(m_walletImpl->subaddressAccount(), this);
|
2018-04-04 18:59:45 +03:00
|
|
|
m_walletListener = new WalletListenerImpl(this);
|
|
|
|
m_walletImpl->setListener(m_walletListener);
|
2016-11-26 16:34:56 +02:00
|
|
|
m_connectionStatus = Wallet::ConnectionStatus_Disconnected;
|
2016-11-26 17:31:27 +02:00
|
|
|
// start cache timers
|
|
|
|
m_connectionStatusTime.restart();
|
|
|
|
m_daemonBlockChainHeightTime.restart();
|
|
|
|
m_daemonBlockChainTargetHeightTime.restart();
|
2016-11-26 18:01:59 +02:00
|
|
|
m_initialized = false;
|
2017-01-31 11:32:41 +02:00
|
|
|
m_connectionStatusRunning = false;
|
2017-02-25 23:16:58 +02:00
|
|
|
m_daemonUsername = "";
|
|
|
|
m_daemonPassword = "";
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
Wallet::~Wallet()
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2016-10-30 19:09:28 +02:00
|
|
|
qDebug("~Wallet: Closing wallet");
|
2017-08-06 17:44:32 +03:00
|
|
|
delete m_addressBook;
|
|
|
|
m_addressBook = NULL;
|
2016-12-10 03:01:04 +02:00
|
|
|
|
2016-11-18 23:40:58 +02:00
|
|
|
delete m_history;
|
2017-02-25 01:19:37 +02:00
|
|
|
m_history = NULL;
|
2017-07-04 06:34:09 +03:00
|
|
|
delete m_addressBook;
|
|
|
|
m_addressBook = NULL;
|
|
|
|
delete m_subaddress;
|
|
|
|
m_subaddress = NULL;
|
2019-01-14 14:25:59 +02:00
|
|
|
delete m_subaddressAccount;
|
|
|
|
m_subaddressAccount = NULL;
|
2016-12-15 14:18:04 +02:00
|
|
|
//Monero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl);
|
2017-10-22 17:15:14 +03:00
|
|
|
if(status() == Status_Critical)
|
|
|
|
qDebug("Not storing wallet cache");
|
|
|
|
else if( m_walletImpl->store(""))
|
|
|
|
qDebug("Wallet cache stored successfully");
|
|
|
|
else
|
|
|
|
qDebug("Error storing wallet cache");
|
2016-12-15 14:18:04 +02:00
|
|
|
delete m_walletImpl;
|
2017-02-25 01:19:37 +02:00
|
|
|
m_walletImpl = NULL;
|
2018-04-04 18:59:45 +03:00
|
|
|
delete m_walletListener;
|
|
|
|
m_walletListener = NULL;
|
2016-12-15 14:18:04 +02:00
|
|
|
qDebug("m_walletImpl deleted");
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|