aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-08-31 21:10:31 +0200
committerRiccardo Spagni <ric@spagni.net>2016-08-31 21:10:31 +0200
commit9662f464074b2cb57d7e95e852adc090cf8b8a25 (patch)
tree74565538e30ffce8b1d12fcd5eac7026eb84d320 /src
parent0429aac7adb73742dad85120b537ef1f6f4edf8a (diff)
parent6d2e1a8ca386fce3389730c5748cadc39382b49f (diff)
downloadmonzero-gui-9662f464074b2cb57d7e95e852adc090cf8b8a25.tar.gz
monzero-gui-9662f464074b2cb57d7e95e852adc090cf8b8a25.tar.xz
monzero-gui-9662f464074b2cb57d7e95e852adc090cf8b8a25.zip
Merge pull request #6
c519c7e Fix typo (dEBRUYNE-1) 5d17513 Fix typo (dEBRUYNE-1) 93285c2 Fix typo (dEBRUYNE-1) f66a765 Fix typo (dEBRUYNE-1) f8f1d28 Fix typo (dEBRUYNE-1) cb6bcdf Fix typo (dEBRUYNE-1) efba470 Fix typo (dEBRUYNE-1) 1cc7d35 Fix typo (dEBRUYNE-1) 497a6b8 Restored build by using develop bitmonero (Ilya Kitaev) 4fa8ad3 Transfer page: validate amount (Ilya Kitaev) 23c4c95 Update README.md (ferretinjapan) 57ad092 Update README.md with linux build instructions (ferretinjapan) 376db6c Display "processing.." splashscreen while wallet initializing (Ilya Kitaev) 6b9afcf extra debug logging (Ilya Kitaev) 8d93f01 WalletManager::openWalletAsync integrating with UI (Ilya Kitaev) d3234bb WalletManager::openWalletAsync in progress (Ilya Kitaev) c126930 Ask for password in wallet is password protected. closes #26 (Ilya Kitaev) 6f1343a ask user for the password if wallet is password-protected (Ilya Kitaev) fc7a7dd BasicPanel: embedding/reusing "Transfer" page (Ilya Kitaev) 983317b Basic view: real wallet's balance (Ilya Kitaev) d0a5339 Removed: hardcoded "Monero - Donations" (Ilya Kitaev) b199c5f bugfix: empty transfer page (Ilya Kitaev) a3fc55e mac application icon (Ilya Kitaev) 35d7661 Windows application icon (Ilya Kitaev) 4ee5d78 Deploy additional mingw dependencies (Ilya Kitaev) 7c33ea9 msys64 deploy fix (Ilya Kitaev) f640809 macdeployqt app bundle crash fixed. (Ilya Kitaev) 9cd73df Translations are separate qm files (Ilya Kitaev) 1b35a1a build automation script. tested on macos (Ilya Kitaev) c7c06a5 removing "bitmonero" directory in "distclean" target (Ilya Kitaev) aa0ea18 translation files moved to resources (Ilya Kitaev) e5d5a60 Wizard refactoring (Ilya Kitaev) ecf8441 cleaning "auto-generated" bitmonero directory on "make clean". closes #22 (Ilya Kitaev) 32ebf18 dynamic translation support. closes #24 (Ilya Kitaev) 39b88da Apply translation for "normal" mode (Ilya Kitaev) a933983 TranslationManager, Russian translation example (Ilya Kitaev) de7bd2e Polish translation file (Ilya Kitaev) 5737114 update/build transations with release build. closes #23 (Ilya Kitaev) b0f77c8 separate LIBS sections for macx, linux and win32 (Ilya Kitaev) 8b26bc4 Update network status dynamically (closes #17) (Ilya Kitaev) 71da777 Init wallet asynchronously (Ilya Kitaev) 7df82af New flags images, added IT,RU,ZH translation files (Ilya Kitaev) d9f031e Async API integration in progress (Ilya Kitaev) c027922 fixed multicore build; statically link boost, libcrypto and libssl for Linux; (Ilya Kitaev) 5b1ab69 Mac OSX build steps added (Ilya Kitaev) fca82f3 Cross-plaftorm number of cpu cores (Ilya Kitaev) da43e9a "Compiling" section stub added to documentation (Ilya Kitaev) d880441 MSYS2/Win64 build fixed (Ilya Kitaev) 0c09342 Fixed for MSYS2 build (Ilya Kitaev) f846935 Fix typo (dEBRUYNE-1) a594e25 Clean up text (dEBRUYNE-1) 39cb75e Send money: confirmation popups added (Ilya Kitaev) 409c570 Priority aka fee multiplier integrated (Ilya Kitaev) 17f38a9 Added "Receive" page. Hide all pages except "Transfer" and "Receive". (Ilya Kitaev) 88d9be9 Lazy loading for the tweets (Ilya Kitaev) 37c1c0b disable right panel by default, don't perform Twitter https call if panel is disabled (Riccardo Spagni) 2696e49 mixin count for Wallet::createTransaction (Ilya Kitaev) e3985da Transfer page: priority dropdown hidded (Ilya Kitaev) 8ac86a8 Balance on UI updated by the signal (Ilya Kitaev) eaf5924 basic "send money" functionality implemented in GUI (Ilya Kitaev) 3ddd9be main application: initialize wallet, display balance (Ilya Kitaev) 2151f13 Persistent storage for common settings. closes #10 (Ilya Kitaev) 1eac46a "new wallet" and "recovery wallet" flows are implemented using libwallet api (Ilya Kitaev) b7787dc Moving wallet to the user defined location at the "donation" page (pre- final) (Ilya Kitaev) fd50e6f new wallet wizard: wallet created in temporary directory and moved to the destination at the final step (Ilya Kitaev) 5c10be3 Qt wrappers for libwallet API classes (Ilya Kitaev) da1b74a Start in normal mode if wallet exists. Resolves #9 (Ilya Kitaev) 493e290 libwallet integration (Ilya Kitaev) 238d582 build against libwallet_merged and boost libs (Ilya Kitaev) f9e0916 integrating libwallet (Ilya Kitaev) 382fa30 explicitely enabled c++11 for g++ compiler (Ilya Kitaev) 6d0179f wizard: saving locale instead of language; wallet interface continued (Ilya Kitaev) 7d9306c Qt wrapper for libwallet - in-progress (Ilya Kitaev) 625041d integrating cpp wallet mockups with QML (Ilya Kitaev) 1195a89 started integrating wallet library (Ilya Kitaev) 921d16a Forgotten file with password strength related functions (Ilya Kitaev) e555631 wallet directrory in "Documents" for Windows and in "home" for *nix (Ilya Kitaev) 16020ae Wizard: "next button" visibility in backward direction fixed (Ilya Kitaev) 8bc411c wordings and text alignment according to design (Ilya Kitaev) 1364c2b Password strength level updated (Ilya Kitaev) 1571118 Refactored wizard paths internal handling (Ilya Kitaev) 496a34c Language (qt linguist) files actually added to project. (Ilya Kitaev) e3bea0d "word mnemonic input" with clipboard button and hint is reusable component; (Ilya Kitaev) 6289e18 fix for window drag bug on ubuntu, only tested on windows (unknown) fce88a8 Selection (branching) for recovery path (Ilya Kitaev) bbc35ff Next button is in "disabled" state on password page (Ilya Kitaev) 46db771 German and English translation files (Ilya Kitaev)
Diffstat (limited to 'src')
-rw-r--r--src/libwalletqt/PendingTransaction.cpp38
-rw-r--r--src/libwalletqt/PendingTransaction.h50
-rw-r--r--src/libwalletqt/TransactionHistory.cpp50
-rw-r--r--src/libwalletqt/TransactionHistory.h42
-rw-r--r--src/libwalletqt/TransactionInfo.cpp55
-rw-r--r--src/libwalletqt/TransactionInfo.h54
-rw-r--r--src/libwalletqt/Wallet.cpp206
-rw-r--r--src/libwalletqt/Wallet.h138
-rw-r--r--src/libwalletqt/WalletManager.cpp158
-rw-r--r--src/libwalletqt/WalletManager.h107
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