2016-02-23 17:59:26 +02:00
|
|
|
#include "WalletManager.h"
|
2016-02-24 12:25:20 +02:00
|
|
|
#include "Wallet.h"
|
2016-05-17 16:03:59 +03:00
|
|
|
#include "wallet/wallet2_api.h"
|
2016-02-24 12:25:20 +02:00
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
|
|
|
|
|
2016-02-24 12:25:20 +02:00
|
|
|
WalletManager * WalletManager::m_instance = nullptr;
|
|
|
|
|
|
|
|
|
2016-02-29 16:39:39 +02:00
|
|
|
|
2016-02-24 12:25:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
WalletManager *WalletManager::instance()
|
|
|
|
{
|
|
|
|
if (!m_instance) {
|
|
|
|
m_instance = new WalletManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
Wallet *WalletManager::createWallet(const QString &path, const QString &password,
|
2016-06-07 16:26:25 +03:00
|
|
|
const QString &language, bool testnet)
|
2016-02-24 12:25:20 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
Bitmonero::Wallet * w = m_pimpl->createWallet(path.toStdString(), password.toStdString(),
|
|
|
|
language.toStdString(), testnet);
|
|
|
|
Wallet * wallet = new Wallet(w);
|
2016-02-29 16:39:39 +02:00
|
|
|
return wallet;
|
|
|
|
}
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
Wallet *WalletManager::openWallet(const QString &path, const QString &password, bool testnet)
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
|
|
|
// TODO: call the libwallet api here;
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
Bitmonero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), testnet);
|
|
|
|
Wallet * wallet = new Wallet(w);
|
2016-02-24 12:25:20 +02:00
|
|
|
return wallet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, bool testnet)
|
2016-02-24 12:25:20 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
Bitmonero::Wallet * w = m_pimpl->recoveryWallet(path.toStdString(), memo.toStdString(), testnet);
|
|
|
|
Wallet * wallet = new Wallet(w);
|
|
|
|
return wallet;
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
2016-02-24 12:25:20 +02:00
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
|
2016-02-29 16:39:39 +02:00
|
|
|
void WalletManager::closeWallet(Wallet *wallet)
|
|
|
|
{
|
|
|
|
delete wallet;
|
|
|
|
}
|
2016-02-24 12:25:20 +02:00
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
bool WalletManager::walletExists(const QString &path) const
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
return m_pimpl->walletExists(path.toStdString());
|
2016-02-29 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
QStringList WalletManager::findWallets(const QString &path)
|
2016-02-29 16:39:39 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03: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 16:39:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString WalletManager::errorString() const
|
|
|
|
{
|
|
|
|
return tr("Unknown error");
|
2016-02-24 12:25:20 +02:00
|
|
|
}
|
2016-02-23 17:59:26 +02:00
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
bool WalletManager::moveWallet(const QString &src, const QString &dst)
|
2016-02-23 17:59:26 +02:00
|
|
|
{
|
2016-06-07 16:26:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-02-23 17:59:26 +02:00
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
|
|
|
|
QString WalletManager::walletLanguage(const QString &locale)
|
|
|
|
{
|
|
|
|
return "English";
|
|
|
|
}
|
|
|
|
|
2016-06-08 13:53:24 +03:00
|
|
|
QString WalletManager::displayAmount(quint64 amount)
|
|
|
|
{
|
|
|
|
return QString::fromStdString(Bitmonero::Wallet::displayAmount(amount));
|
|
|
|
}
|
|
|
|
|
2016-06-07 16:26:25 +03:00
|
|
|
|
|
|
|
WalletManager::WalletManager(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
m_pimpl = Bitmonero::WalletManagerFactory::getWalletManager();
|
2016-02-23 17:59:26 +02:00
|
|
|
}
|
2016-02-24 12:25:20 +02:00
|
|
|
|
|
|
|
|