monero-gui/src/libwalletqt/Wallet.cpp

207 lines
4.4 KiB
C++
Raw Normal View History

2016-02-23 17:59:26 +02:00
#include "Wallet.h"
2016-06-08 13:53:24 +03:00
#include "PendingTransaction.h"
#include "TransactionHistory.h"
#include "wallet/wallet2_api.h"
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-02-29 16:39:39 +02:00
namespace {
}
2016-07-13 15:24:40 +03:00
class WalletListenerImpl : public Bitmonero::WalletListener
{
public:
WalletListenerImpl(Wallet * w)
: m_wallet(w)
{
}
virtual void moneySpent(const std::string &txId, uint64_t amount)
{
// TODO
Q_UNUSED(txId)
Q_UNUSED(amount)
2016-07-14 13:09:39 +03:00
qDebug() << __FUNCTION__;
2016-07-13 15:24:40 +03:00
}
virtual void moneyReceived(const std::string &txId, uint64_t amount)
{
// TODO
Q_UNUSED(txId)
Q_UNUSED(amount)
2016-07-14 13:09:39 +03:00
qDebug() << __FUNCTION__;
2016-07-13 15:24:40 +03:00
}
virtual void updated()
{
2016-07-14 13:09:39 +03:00
qDebug() << __FUNCTION__;
2016-07-13 15:24:40 +03:00
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();
}
private:
Wallet * m_wallet;
};
2016-02-29 16:39:39 +02:00
QString Wallet::getSeed() const
2016-02-29 16:39:39 +02:00
{
return QString::fromStdString(m_walletImpl->seed());
2016-02-29 16:39:39 +02:00
}
QString Wallet::getSeedLanguage() const
2016-02-29 16:39:39 +02: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-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-07-14 13:09:39 +03:00
bool Wallet::connected() const
{
return m_walletImpl->connected();
}
QString Wallet::errorString() const
{
return QString::fromStdString(m_walletImpl->errorString());
}
2016-02-29 16:39:39 +02:00
bool Wallet::setPassword(const QString &password)
{
return m_walletImpl->setPassword(password.toStdString());
2016-02-23 17:59:26 +02:00
}
2016-02-29 16:39:39 +02:00
QString Wallet::address() const
2016-02-29 16:39:39 +02:00
{
return QString::fromStdString(m_walletImpl->address());
2016-02-29 16:39:39 +02:00
}
bool Wallet::store(const QString &path)
2016-02-29 16:39:39 +02:00
{
return m_walletImpl->store(path.toStdString());
2016-02-29 16:39:39 +02:00
}
2016-06-08 13:53:24 +03:00
bool Wallet::init(const QString &daemonAddress, quint64 upperTransactionLimit)
{
return m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit);
}
2016-07-14 13:09:39 +03:00
void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLimit)
{
m_walletImpl->initAsync(daemonAddress.toStdString(), upperTransactionLimit);
}
2016-06-08 13:53:24 +03:00
bool Wallet::connectToDaemon()
{
return m_walletImpl->connectToDaemon();
}
void Wallet::setTrustedDaemon(bool arg)
{
m_walletImpl->setTrustedDaemon(arg);
}
quint64 Wallet::balance() const
{
return m_walletImpl->balance();
}
quint64 Wallet::unlockedBalance() const
{
return m_walletImpl->unlockedBalance();
}
bool Wallet::refresh()
{
2016-06-17 16:35:07 +03:00
bool result = m_walletImpl->refresh();
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()
{
m_walletImpl->refreshAsync();
}
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
{
Bitmonero::PendingTransaction * ptImpl = m_walletImpl->createTransaction(
2016-06-27 15:45:48 +03:00
dst_addr.toStdString(), payment_id.toStdString(), amount, mixin_count,
static_cast<Bitmonero::PendingTransaction::Priority>(priority));
2016-06-08 13:53:24 +03:00
PendingTransaction * result = new PendingTransaction(ptImpl, this);
return result;
}
void Wallet::disposeTransaction(PendingTransaction *t)
{
m_walletImpl->disposeTransaction(t->m_pimpl);
delete t;
}
TransactionHistory *Wallet::history()
{
if (!m_history) {
Bitmonero::TransactionHistory * impl = m_walletImpl->history();
m_history = new TransactionHistory(impl, this);
}
return m_history;
}
2016-02-29 16:39:39 +02:00
QString Wallet::generatePaymentId() const
{
return QString::fromStdString(Bitmonero::Wallet::genPaymentId());
}
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-02-29 16:39:39 +02:00
Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent)
2016-06-08 13:53:24 +03:00
: QObject(parent), m_walletImpl(w), m_history(nullptr)
2016-02-29 16:39:39 +02:00
{
2016-07-14 13:09:39 +03:00
m_walletImpl->setListener(new WalletListenerImpl(this));
2016-02-29 16:39:39 +02:00
}
Wallet::~Wallet()
2016-02-29 16:39:39 +02:00
{
Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl);
2016-02-29 16:39:39 +02:00
}