aboutsummaryrefslogtreecommitdiff
path: root/src/libwalletqt
diff options
context:
space:
mode:
authorxiphon <xiphon@protonmail.com>2020-04-26 02:23:51 +0000
committerxiphon <xiphon@protonmail.com>2020-04-28 20:36:22 +0000
commitcfdba59584d434e38407569441f4f518dd9507fa (patch)
tree5e971ed434929a8ede78877fa8cfcbc23f7a97cb /src/libwalletqt
parent4141832a4d948d7a85cf53c35c167b88a2441219 (diff)
downloadmonzero-gui-cfdba59584d434e38407569441f4f518dd9507fa.tar.gz
monzero-gui-cfdba59584d434e38407569441f4f518dd9507fa.tar.xz
monzero-gui-cfdba59584d434e38407569441f4f518dd9507fa.zip
Wallet: implement async wallet storing
Diffstat (limited to 'src/libwalletqt')
-rw-r--r--src/libwalletqt/Wallet.cpp15
-rw-r--r--src/libwalletqt/Wallet.h3
2 files changed, 14 insertions, 4 deletions
diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp
index 8eacb113..355ce6a9 100644
--- a/src/libwalletqt/Wallet.cpp
+++ b/src/libwalletqt/Wallet.cpp
@@ -48,7 +48,6 @@
#include <QtConcurrent/QtConcurrent>
#include <QList>
#include <QVector>
-#include <QMutex>
#include <QMutexLocker>
namespace {
@@ -230,9 +229,19 @@ QString Wallet::path() const
return QDir::toNativeSeparators(QString::fromStdString(m_walletImpl->path()));
}
-bool Wallet::store(const QString &path)
+void Wallet::storeAsync(const QJSValue &callback, const QString &path /* = "" */)
{
- return m_walletImpl->store(path.toStdString());
+ const auto future = m_scheduler.run(
+ [this, path] {
+ QMutexLocker locker(&m_storeMutex);
+
+ return QJSValueList({m_walletImpl->store(path.toStdString())});
+ },
+ callback);
+ if (!future.first)
+ {
+ QJSValue(callback).call(QJSValueList({false}));
+ }
}
bool Wallet::init(const QString &daemonAddress, bool trustedDaemon, quint64 upperTransactionLimit, bool isRecovering, bool isRecoveringFromDevice, quint64 restoreHeight)
diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h
index 5a408049..3450b1ce 100644
--- a/src/libwalletqt/Wallet.h
+++ b/src/libwalletqt/Wallet.h
@@ -144,7 +144,7 @@ public:
//! saves wallet to the file by given path
//! empty path stores in current location
- Q_INVOKABLE bool store(const QString &path = "");
+ Q_INVOKABLE void storeAsync(const QJSValue &callback, const QString &path = "");
//! initializes wallet asynchronously
Q_INVOKABLE void initAsync(const QString &daemonAddress, bool trustedDaemon = false, quint64 upperTransactionLimit = 0, bool isRecovering = false, bool isRecoveringFromDevice = false, quint64 restoreHeight = 0);
@@ -434,6 +434,7 @@ private:
QString m_daemonPassword;
Monero::WalletListener *m_walletListener;
FutureScheduler m_scheduler;
+ QMutex m_storeMutex;
};