diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/libwalletqt/PendingTransaction.cpp | 38 | ||||
| -rw-r--r-- | src/libwalletqt/PendingTransaction.h | 50 | ||||
| -rw-r--r-- | src/libwalletqt/TransactionHistory.cpp | 50 | ||||
| -rw-r--r-- | src/libwalletqt/TransactionHistory.h | 42 | ||||
| -rw-r--r-- | src/libwalletqt/TransactionInfo.cpp | 55 | ||||
| -rw-r--r-- | src/libwalletqt/TransactionInfo.h | 54 | ||||
| -rw-r--r-- | src/libwalletqt/Wallet.cpp | 206 | ||||
| -rw-r--r-- | src/libwalletqt/Wallet.h | 138 | ||||
| -rw-r--r-- | src/libwalletqt/WalletManager.cpp | 158 | ||||
| -rw-r--r-- | src/libwalletqt/WalletManager.h | 107 |
10 files changed, 898 insertions, 0 deletions
diff --git a/src/libwalletqt/PendingTransaction.cpp b/src/libwalletqt/PendingTransaction.cpp new file mode 100644 index 00000000..8c0d8c29 --- /dev/null +++ b/src/libwalletqt/PendingTransaction.cpp @@ -0,0 +1,38 @@ +#include "PendingTransaction.h" + + +PendingTransaction::Status PendingTransaction::status() const +{ + return static_cast<Status>(m_pimpl->status()); +} + +QString PendingTransaction::errorString() const +{ + return QString::fromStdString(m_pimpl->errorString()); +} + +bool PendingTransaction::commit() +{ + return m_pimpl->commit(); +} + +quint64 PendingTransaction::amount() const +{ + return m_pimpl->amount(); +} + +quint64 PendingTransaction::dust() const +{ + return m_pimpl->dust(); +} + +quint64 PendingTransaction::fee() const +{ + return m_pimpl->fee(); +} + +PendingTransaction::PendingTransaction(Bitmonero::PendingTransaction *pt, QObject *parent) + : QObject(parent), m_pimpl(pt) +{ + +} diff --git a/src/libwalletqt/PendingTransaction.h b/src/libwalletqt/PendingTransaction.h new file mode 100644 index 00000000..8f5fca1c --- /dev/null +++ b/src/libwalletqt/PendingTransaction.h @@ -0,0 +1,50 @@ +#ifndef PENDINGTRANSACTION_H +#define PENDINGTRANSACTION_H + +#include <QObject> + +#include <wallet/wallet2_api.h> + +//namespace Bitmonero { +//class PendingTransaction; +//} + +class PendingTransaction : public QObject +{ + Q_OBJECT + Q_PROPERTY(Status status READ status) + Q_PROPERTY(QString errorString READ errorString) + Q_PROPERTY(quint64 amount READ amount) + Q_PROPERTY(quint64 dust READ dust) + Q_PROPERTY(quint64 fee READ fee) + +public: + enum Status { + Status_Ok = Bitmonero::PendingTransaction::Status_Ok, + Status_Error = Bitmonero::PendingTransaction::Status_Error + }; + Q_ENUM(Status) + + enum Priority { + Priority_Low = Bitmonero::PendingTransaction::Priority_Low, + Priority_Medium = Bitmonero::PendingTransaction::Priority_Medium, + Priority_High = Bitmonero::PendingTransaction::Priority_High + }; + Q_ENUM(Priority) + + + Status status() const; + QString errorString() const; + Q_INVOKABLE bool commit(); + quint64 amount() const; + quint64 dust() const; + quint64 fee() const; +private: + explicit PendingTransaction(Bitmonero::PendingTransaction * pt, QObject *parent = 0); + +private: + friend class Wallet; + Bitmonero::PendingTransaction * m_pimpl; +}; + +#endif // PENDINGTRANSACTION_H diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp new file mode 100644 index 00000000..2c2c9f73 --- /dev/null +++ b/src/libwalletqt/TransactionHistory.cpp @@ -0,0 +1,50 @@ +#include "TransactionHistory.h" +#include "TransactionInfo.h" +#include <wallet/wallet2_api.h> + + +int TransactionHistory::count() const +{ + return m_pimpl->count(); +} + +TransactionInfo *TransactionHistory::transaction(int index) +{ + // box up Bitmonero::TransactionInfo + Bitmonero::TransactionInfo * impl = m_pimpl->transaction(index); + TransactionInfo * result = new TransactionInfo(impl, this); + return result; +} + +TransactionInfo *TransactionHistory::transaction(const QString &id) +{ + // box up Bitmonero::TransactionInfo + Bitmonero::TransactionInfo * impl = m_pimpl->transaction(id.toStdString()); + TransactionInfo * result = new TransactionInfo(impl, this); + return result; +} + +QList<TransactionInfo *> TransactionHistory::getAll() const +{ + qDeleteAll(m_tinfo); + m_tinfo.clear(); + TransactionHistory * parent = const_cast<TransactionHistory*>(this); + for (const auto i : m_pimpl->getAll()) { + TransactionInfo * ti = new TransactionInfo(i, parent); + m_tinfo.append(ti); + } + return m_tinfo; +} + +void TransactionHistory::refresh() +{ + // XXX this invalidates previously saved history that might be used by clients + m_pimpl->refresh(); + emit invalidated(); +} + +TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent) + : QObject(parent), m_pimpl(pimpl) +{ + +} diff --git a/src/libwalletqt/TransactionHistory.h b/src/libwalletqt/TransactionHistory.h new file mode 100644 index 00000000..a6287506 --- /dev/null +++ b/src/libwalletqt/TransactionHistory.h @@ -0,0 +1,42 @@ +#ifndef TRANSACTIONHISTORY_H +#define TRANSACTIONHISTORY_H + +#include <QObject> +#include <QList> + +namespace Bitmonero { +class TransactionHistory; +} + +class TransactionInfo; + +class TransactionHistory : public QObject +{ + Q_OBJECT + Q_PROPERTY(int count READ count) + +public: + int count() const; + Q_INVOKABLE TransactionInfo *transaction(int index); + Q_INVOKABLE TransactionInfo * transaction(const QString &id); + Q_INVOKABLE QList<TransactionInfo*> getAll() const; + Q_INVOKABLE void refresh(); + +signals: + void invalidated(); + +public slots: + + +private: + explicit TransactionHistory(Bitmonero::TransactionHistory * pimpl, QObject *parent = 0); + +private: + friend class Wallet; + + Bitmonero::TransactionHistory * m_pimpl; + mutable QList<TransactionInfo*> m_tinfo; + +}; + +#endif // TRANSACTIONHISTORY_H diff --git a/src/libwalletqt/TransactionInfo.cpp b/src/libwalletqt/TransactionInfo.cpp new file mode 100644 index 00000000..192e85e5 --- /dev/null +++ b/src/libwalletqt/TransactionInfo.cpp @@ -0,0 +1,55 @@ +#include "TransactionInfo.h" +#include <QDateTime> + +TransactionInfo::Direction TransactionInfo::direction() const +{ + return static_cast<Direction>(m_pimpl->direction()); +} + +bool TransactionInfo::isPending() const +{ + return m_pimpl->isPending(); +} + +bool TransactionInfo::isFailed() const +{ + return m_pimpl->isFailed(); +} + +quint64 TransactionInfo::amount() const +{ + return m_pimpl->amount(); +} + +quint64 TransactionInfo::fee() const +{ + return m_pimpl->fee(); + +} + +quint64 TransactionInfo::blockHeight() const +{ + return m_pimpl->blockHeight(); +} + +QString TransactionInfo::hash() const +{ + return QString::fromStdString(m_pimpl->hash()); +} + +QString TransactionInfo::timestamp() +{ + QString result = QDateTime::fromTime_t(m_pimpl->timestamp()).toString(Qt::ISODate); + return result; +} + +QString TransactionInfo::paymentId() +{ + return QString::fromStdString(m_pimpl->paymentId()); +} + +TransactionInfo::TransactionInfo(Bitmonero::TransactionInfo *pimpl, QObject *parent) + : QObject(parent), m_pimpl(pimpl) +{ + +} diff --git a/src/libwalletqt/TransactionInfo.h b/src/libwalletqt/TransactionInfo.h new file mode 100644 index 00000000..62c26e2f --- /dev/null +++ b/src/libwalletqt/TransactionInfo.h @@ -0,0 +1,54 @@ +#ifndef TRANSACTIONINFO_H +#define TRANSACTIONINFO_H + +#include <QObject> +#include <wallet/wallet2_api.h> + +class TransactionInfo : public QObject +{ + Q_OBJECT + Q_PROPERTY(Direction direction READ direction) + Q_PROPERTY(bool isPending READ isPending) + Q_PROPERTY(bool isFailed READ isFailed) + Q_PROPERTY(quint64 amount READ amount) + Q_PROPERTY(quint64 fee READ fee) + Q_PROPERTY(quint64 blockHeight READ blockHeight) + Q_PROPERTY(QString hash READ hash) + Q_PROPERTY(QString timestamp READ timestamp) + Q_PROPERTY(QString paymentId READ paymentId) + +public: + enum Direction { + Direction_In = Bitmonero::TransactionInfo::Direction_In, + Direction_Out = Bitmonero::TransactionInfo::Direction_Out + }; + +// TODO: implement as separate class; + +// struct Transfer { +// Transfer(uint64_t _amount, const std::string &address); +// const uint64_t amount; +// const std::string address; +// }; + Direction direction() const; + bool isPending() const; + bool isFailed() const; + quint64 amount() const; + quint64 fee() const; + quint64 blockHeight() const; + //! transaction_id + QString hash() const; + QString timestamp(); + QString paymentId(); + + // TODO: implement it + //! only applicable for output transactions + // virtual const std::vector<Transfer> & transfers() const = 0; +private: + explicit TransactionInfo(Bitmonero::TransactionInfo * pimpl, QObject *parent = 0); +private: + friend class TransactionHistory; + Bitmonero::TransactionInfo * m_pimpl; +}; + +#endif // TRANSACTIONINFO_H diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp new file mode 100644 index 00000000..4c6995cb --- /dev/null +++ b/src/libwalletqt/Wallet.cpp @@ -0,0 +1,206 @@ +#include "Wallet.h" +#include "PendingTransaction.h" +#include "TransactionHistory.h" +#include "wallet/wallet2_api.h" + +#include <QFile> +#include <QDir> +#include <QDebug> +#include <QUrl> +#include <QTimer> + +namespace { + + +} + +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) + qDebug() << __FUNCTION__; + } + + virtual void moneyReceived(const std::string &txId, uint64_t amount) + { + // TODO + Q_UNUSED(txId) + Q_UNUSED(amount) + qDebug() << __FUNCTION__; + } + + virtual void updated() + { + qDebug() << __FUNCTION__; + emit m_wallet->updated(); + } + + // called when wallet refreshed by background thread or explicitly + virtual void refreshed() + { + qDebug() << __FUNCTION__; + emit m_wallet->refreshed(); + } + +private: + Wallet * m_wallet; +}; + + + +QString Wallet::getSeed() const +{ + return QString::fromStdString(m_walletImpl->seed()); +} + +QString Wallet::getSeedLanguage() const +{ + return QString::fromStdString(m_walletImpl->getSeedLanguage()); +} + +void Wallet::setSeedLanguage(const QString &lang) +{ + m_walletImpl->setSeedLanguage(lang.toStdString()); +} + +Wallet::Status Wallet::status() const +{ + return static_cast<Status>(m_walletImpl->status()); +} + +bool Wallet::connected() const +{ + return m_walletImpl->connected(); +} + +QString Wallet::errorString() const +{ + return QString::fromStdString(m_walletImpl->errorString()); +} + +bool Wallet::setPassword(const QString &password) +{ + return m_walletImpl->setPassword(password.toStdString()); +} + +QString Wallet::address() const +{ + return QString::fromStdString(m_walletImpl->address()); +} + +bool Wallet::store(const QString &path) +{ + return m_walletImpl->store(path.toStdString()); +} + +bool Wallet::init(const QString &daemonAddress, quint64 upperTransactionLimit) +{ + return m_walletImpl->init(daemonAddress.toStdString(), upperTransactionLimit); +} + +void Wallet::initAsync(const QString &daemonAddress, quint64 upperTransactionLimit) +{ + m_walletImpl->initAsync(daemonAddress.toStdString(), upperTransactionLimit); +} + +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() +{ + bool result = m_walletImpl->refresh(); + if (result) + emit updated(); + return result; +} + +void Wallet::refreshAsync() +{ + m_walletImpl->refreshAsync(); +} + +PendingTransaction *Wallet::createTransaction(const QString &dst_addr, const QString &payment_id, + quint64 amount, quint32 mixin_count, + PendingTransaction::Priority priority) +{ + Bitmonero::PendingTransaction * ptImpl = m_walletImpl->createTransaction( + dst_addr.toStdString(), payment_id.toStdString(), amount, mixin_count, + static_cast<Bitmonero::PendingTransaction::Priority>(priority)); + 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; +} + + +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; +} + + +Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) + : QObject(parent), m_walletImpl(w), m_history(nullptr) +{ + m_walletImpl->setListener(new WalletListenerImpl(this)); +} + +Wallet::~Wallet() +{ + Bitmonero::WalletManagerFactory::getWalletManager()->closeWallet(m_walletImpl); +} diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h new file mode 100644 index 00000000..feba75e0 --- /dev/null +++ b/src/libwalletqt/Wallet.h @@ -0,0 +1,138 @@ +#ifndef WALLET_H +#define WALLET_H + +#include <QObject> + +#include "wallet/wallet2_api.h" // we need to have an access to the Bitmonero::Wallet::Status enum here; +#include "PendingTransaction.h" // we need to have an access to the PendingTransaction::Priority enum here; + + +namespace Bitmonero { + class Wallet; // forward declaration +} + + +class TransactionHistory; + +class Wallet : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString seed READ getSeed) + Q_PROPERTY(QString seedLanguage READ getSeedLanguage) + Q_PROPERTY(Status status READ status) + Q_PROPERTY(bool connected READ connected) + Q_PROPERTY(QString errorString READ errorString) + Q_PROPERTY(QString address READ address) + Q_PROPERTY(quint64 balance READ balance) + Q_PROPERTY(quint64 unlockedBalance READ unlockedBalance) + Q_PROPERTY(TransactionHistory * history READ history) + Q_PROPERTY(QString paymentId READ paymentId WRITE setPaymentId) + + +public: + enum Status { + Status_Ok = Bitmonero::Wallet::Status_Ok, + Status_Error = Bitmonero::Wallet::Status_Error + }; + + Q_ENUM(Status) + + //! returns mnemonic seed + QString getSeed() const; + + //! returns seed language + QString getSeedLanguage() const; + + //! set seed language + Q_INVOKABLE void setSeedLanguage(const QString &lang); + + //! returns last operation's status + Status status() const; + + //! returns of wallet connected + bool connected() const; + + //! returns last operation's error message + QString errorString() const; + + //! changes the password using existing parameters (path, seed, seed lang) + Q_INVOKABLE bool setPassword(const QString &password); + + //! returns wallet's public address + QString address() const; + + //! saves wallet to the file by given path + Q_INVOKABLE bool store(const QString &path); + + //! initializes wallet + Q_INVOKABLE bool init(const QString &daemonAddress, quint64 upperTransactionLimit); + + //! initializes wallet asynchronously + Q_INVOKABLE void initAsync(const QString &daemonAddress, quint64 upperTransactionLimit); + + //! connects to daemon + Q_INVOKABLE bool connectToDaemon(); + + //! indicates id daemon is trusted + Q_INVOKABLE void setTrustedDaemon(bool arg); + + //! returns balance + quint64 balance() const; + + //! returns unlocked balance + quint64 unlockedBalance() const; + + //! refreshes the wallet + Q_INVOKABLE bool refresh(); + + + //! refreshes the wallet asynchronously + Q_INVOKABLE void refreshAsync(); + + //! creates transaction + Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id, + quint64 amount, quint32 mixin_count, + PendingTransaction::Priority priority); + //! deletes transaction and frees memory + Q_INVOKABLE void disposeTransaction(PendingTransaction * t); + + //! returns transaction history + TransactionHistory * history(); + + //! generate payment id + Q_INVOKABLE QString generatePaymentId() const; + + //! integrated address + Q_INVOKABLE QString integratedAddress(const QString &paymentId) const; + + + //! saved payment id + QString paymentId() const; + + void setPaymentId(const QString &paymentId); + + // TODO: setListenter() when it implemented in API +signals: + void updated(); + + // emitted when refresh process finished (could take a long time) + // signalling only after we + void refreshed(); + + +private: + Wallet(Bitmonero::Wallet *w, QObject * parent = 0); + ~Wallet(); + +private: + friend class WalletManager; + friend class WalletListenerImpl; + //! libwallet's + Bitmonero::Wallet * m_walletImpl; + // history lifetime managed by wallet; + TransactionHistory * m_history; + QString m_paymentId; + +}; + +#endif // WALLET_H diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp new file mode 100644 index 00000000..a9f332a3 --- /dev/null +++ b/src/libwalletqt/WalletManager.cpp @@ -0,0 +1,158 @@ +#include "WalletManager.h" +#include "Wallet.h" +#include "wallet/wallet2_api.h" +#include <QFile> +#include <QFileInfo> +#include <QDir> +#include <QDebug> +#include <QUrl> +#include <QtConcurrent/QtConcurrent> + +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, + const QString &language, bool testnet) +{ + Bitmonero::Wallet * w = m_pimpl->createWallet(path.toStdString(), password.toStdString(), + language.toStdString(), testnet); + Wallet * wallet = new Wallet(w); + return wallet; +} + +Wallet *WalletManager::openWallet(const QString &path, const QString &password, bool testnet) +{ + qDebug("%s: opening wallet at %s, testnet = %d ", + __PRETTY_FUNCTION__, qPrintable(path), testnet); + + Bitmonero::Wallet * w = m_pimpl->openWallet(path.toStdString(), password.toStdString(), testnet); + qDebug("%s: opened wallet: %s, status: %d", __PRETTY_FUNCTION__, w->address().c_str(), w->status()); + Wallet * wallet = new Wallet(w); + + // move wallet to the GUI thread. Otherwise it wont be emitting signals + if (wallet->thread() != qApp->thread()) { + wallet->moveToThread(qApp->thread()); + } + + return wallet; +} + +void WalletManager::openWalletAsync(const QString &path, const QString &password, bool testnet) +{ + QFuture<Wallet*> future = QtConcurrent::run(this, &WalletManager::openWallet, + path, password, testnet); + QFutureWatcher<Wallet*> * watcher = new QFutureWatcher<Wallet*>(); + watcher->setFuture(future); + connect(watcher, &QFutureWatcher<Wallet*>::finished, + this, [this, watcher]() { + QFuture<Wallet*> future = watcher->future(); + watcher->deleteLater(); + emit walletOpened(future.result()); + }); +} + + +Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, bool testnet) +{ + Bitmonero::Wallet * w = m_pimpl->recoveryWallet(path.toStdString(), memo.toStdString(), testnet); + Wallet * wallet = new Wallet(w); + return wallet; +} + + +QString WalletManager::closeWallet(Wallet *wallet) +{ + QString result = wallet->address(); + delete wallet; + return result; +} + +void WalletManager::closeWalletAsync(Wallet *wallet) +{ + QFuture<QString> future = QtConcurrent::run(this, &WalletManager::closeWallet, + wallet); + QFutureWatcher<QString> * watcher = new QFutureWatcher<QString>(); + watcher->setFuture(future); + + connect(watcher, &QFutureWatcher<QString>::finished, + this, [this, watcher]() { + QFuture<QString> future = watcher->future(); + watcher->deleteLater(); + emit walletClosed(future.result()); + }); +} + +bool WalletManager::walletExists(const QString &path) const +{ + return m_pimpl->walletExists(path.toStdString()); +} + +QStringList WalletManager::findWallets(const QString &path) +{ + 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; +} + +QString WalletManager::errorString() const +{ + return tr("Unknown error"); +} + +bool WalletManager::moveWallet(const QString &src, const QString &dst) +{ + return true; +} + + +QString WalletManager::walletLanguage(const QString &locale) +{ + return "English"; +} + +quint64 WalletManager::maximumAllowedAmount() const +{ + return Bitmonero::Wallet::maximumAllowedAmount(); +} + +QString WalletManager::maximumAllowedAmountAsSting() const +{ + return WalletManager::displayAmount(WalletManager::maximumAllowedAmount()); +} + +QString WalletManager::displayAmount(quint64 amount) const +{ + return QString::fromStdString(Bitmonero::Wallet::displayAmount(amount)); +} + +quint64 WalletManager::amountFromString(const QString &amount) const +{ + return Bitmonero::Wallet::amountFromString(amount.toStdString()); +} + +quint64 WalletManager::amountFromDouble(double amount) const +{ + return Bitmonero::Wallet::amountFromDouble(amount); +} + +void WalletManager::setLogLevel(int logLevel) +{ + Bitmonero::WalletManagerFactory::setLogLevel(logLevel); +} + +WalletManager::WalletManager(QObject *parent) : QObject(parent) +{ + m_pimpl = Bitmonero::WalletManagerFactory::getWalletManager(); +} diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h new file mode 100644 index 00000000..3629242a --- /dev/null +++ b/src/libwalletqt/WalletManager.h @@ -0,0 +1,107 @@ +#ifndef WALLETMANAGER_H +#define WALLETMANAGER_H + +#include <QObject> +#include <wallet/wallet2_api.h> + +class Wallet; +namespace Bitmonero { + class WalletManager; +} + +class WalletManager : public QObject +{ + Q_OBJECT + +public: + enum LogLevel { + LogLevel_Silent = Bitmonero::WalletManagerFactory::LogLevel_Silent, + LogLevel_0 = Bitmonero::WalletManagerFactory::LogLevel_0, + LogLevel_1 = Bitmonero::WalletManagerFactory::LogLevel_1, + LogLevel_2 = Bitmonero::WalletManagerFactory::LogLevel_2, + LogLevel_3 = Bitmonero::WalletManagerFactory::LogLevel_3, + LogLevel_4 = Bitmonero::WalletManagerFactory::LogLevel_4, + LogLevel_Min = Bitmonero::WalletManagerFactory::LogLevel_Min, + LogLevel_Max = Bitmonero::WalletManagerFactory::LogLevel_Max, + }; + + static WalletManager * instance(); + // wizard: createWallet path; + Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password, + const QString &language, bool testnet = false); + + /*! + * \brief openWallet - opens wallet by given path + * \param path - wallet filename + * \param password - wallet password. Empty string in wallet isn't password protected + * \param testnet - determines if we running testnet + * \return wallet object pointer + */ + Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, bool testnet = false); + + /*! + * \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal + * emitted when wallet opened; + */ + Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, bool testnet = false); + + // wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = "" + Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo, + bool testnet = false); + + /*! + * \brief closeWallet - closes wallet and frees memory + * \param wallet + * \return wallet address + */ + Q_INVOKABLE QString closeWallet(Wallet * wallet); + + /*! + * \brief closeWalletAsync - asynchronous version of "closeWallet" + * \param wallet - wallet pointer; + */ + Q_INVOKABLE void closeWalletAsync(Wallet * wallet); + + //! checks is given filename is a wallet; + Q_INVOKABLE bool walletExists(const QString &path) const; + + //! returns list with wallet's filenames, if found by given path + Q_INVOKABLE QStringList findWallets(const QString &path); + + //! returns error description in human language + Q_INVOKABLE QString errorString() const; + + + // wizard: both "create" and "recovery" paths. + // TODO: probably move it to "Wallet" interface + Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst); + //! returns libwallet language name for given locale + Q_INVOKABLE QString walletLanguage(const QString &locale); + + + //! since we can't call static method from QML, move it to this class + Q_INVOKABLE QString displayAmount(quint64 amount) const; + Q_INVOKABLE quint64 amountFromString(const QString &amount) const; + Q_INVOKABLE quint64 amountFromDouble(double amount) const; + Q_INVOKABLE quint64 maximumAllowedAmount() const; + + // QML JS engine doesn't support unsigned integers + Q_INVOKABLE QString maximumAllowedAmountAsSting() const; + + void setLogLevel(int logLevel); + +signals: + + void walletOpened(Wallet * wallet); + void walletClosed(const QString &walletAddress); + +public slots: +private: + + explicit WalletManager(QObject *parent = 0); + static WalletManager * m_instance; + Bitmonero::WalletManager * m_pimpl; + +}; + +#endif // WALLETMANAGER_H |
