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