aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-04-28 21:40:17 -0500
committerluigi1111 <luigi1111w@gmail.com>2020-04-28 21:40:17 -0500
commit135c970ad94ca214b21440c849ba2f092925c7f1 (patch)
tree90f7aaa2f124c0f8e9dbf912a0a6aebdaf6e2520
parentfd5d1f584eb28f710c83a2b674485fd7ad565c09 (diff)
parentcfdba59584d434e38407569441f4f518dd9507fa (diff)
downloadmonzero-gui-135c970ad94ca214b21440c849ba2f092925c7f1.tar.gz
monzero-gui-135c970ad94ca214b21440c849ba2f092925c7f1.tar.xz
monzero-gui-135c970ad94ca214b21440c849ba2f092925c7f1.zip
Merge pull request #2865
cfdba59 Wallet: implement async wallet storing (xiphon)
-rw-r--r--main.qml6
-rw-r--r--src/libwalletqt/Wallet.cpp15
-rw-r--r--src/libwalletqt/Wallet.h3
-rw-r--r--wizard/WizardController.qml53
-rw-r--r--wizard/WizardCreateWallet4.qml7
-rw-r--r--wizard/WizardRestoreWallet4.qml5
6 files changed, 56 insertions, 33 deletions
diff --git a/main.qml b/main.qml
index 3c046e64..449a1e7f 100644
--- a/main.qml
+++ b/main.qml
@@ -972,7 +972,11 @@ ApplicationWindow {
informationPopup.open()
currentWallet.refresh()
currentWallet.disposeTransaction(transaction)
- currentWallet.store();
+ currentWallet.storeAsync(function(success) {
+ if (!success) {
+ appWindow.showStatusMessage(qsTr("Failed to store the wallet"), 3);
+ }
+ });
}
// called on "getProof"
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;
};
diff --git a/wizard/WizardController.qml b/wizard/WizardController.qml
index 3ec9dc79..a1628b4f 100644
--- a/wizard/WizardController.qml
+++ b/wizard/WizardController.qml
@@ -344,41 +344,48 @@ Rectangle {
wizardController.tmpWalletFilename = tmp_wallet_filename
}
- function writeWallet() {
+ function writeWallet(onSuccess) {
// Save wallet files in user specified location
var new_wallet_filename = Wizard.createWalletPath(
isIOS,
wizardController.walletOptionsLocation,
wizardController.walletOptionsName);
- if(isIOS) {
- console.log("saving in ios: " + moneroAccountsDir + new_wallet_filename)
- wizardController.m_wallet.store(moneroAccountsDir + new_wallet_filename);
- } else {
- console.log("saving in wizard: " + new_wallet_filename)
- wizardController.m_wallet.store(new_wallet_filename);
- }
+ const handler = function(success) {
+ if (!success) {
+ appWindow.showStatusMessage(qsTr("Failed to store the wallet"), 3);
+ return;
+ }
- // make sure temporary wallet files are deleted
- console.log("Removing temporary wallet: " + wizardController.tmpWalletFilename)
- oshelper.removeTemporaryWallet(wizardController.tmpWalletFilename)
+ // make sure temporary wallet files are deleted
+ console.log("Removing temporary wallet: " + wizardController.tmpWalletFilename)
+ oshelper.removeTemporaryWallet(wizardController.tmpWalletFilename)
- // protecting wallet with password
- wizardController.m_wallet.setPassword(wizardController.walletOptionsPassword);
+ // protecting wallet with password
+ wizardController.m_wallet.setPassword(wizardController.walletOptionsPassword);
- // save to persistent settings
- persistentSettings.language = wizardController.language_language
- persistentSettings.locale = wizardController.language_locale
+ // save to persistent settings
+ persistentSettings.language = wizardController.language_language
+ persistentSettings.locale = wizardController.language_locale
- persistentSettings.account_name = wizardController.walletOptionsName
- persistentSettings.wallet_path = wizardController.m_wallet.path;
- persistentSettings.restore_height = (isNaN(walletOptionsRestoreHeight))? 0 : walletOptionsRestoreHeight
+ persistentSettings.account_name = wizardController.walletOptionsName
+ persistentSettings.wallet_path = wizardController.m_wallet.path;
+ persistentSettings.restore_height = (isNaN(walletOptionsRestoreHeight))? 0 : walletOptionsRestoreHeight
- persistentSettings.allow_background_mining = false
- persistentSettings.is_recovering = (wizardController.walletOptionsIsRecovering === undefined) ? false : wizardController.walletOptionsIsRecovering
- persistentSettings.is_recovering_from_device = (wizardController.walletOptionsIsRecoveringFromDevice === undefined) ? false : wizardController.walletOptionsIsRecoveringFromDevice
+ persistentSettings.allow_background_mining = false
+ persistentSettings.is_recovering = (wizardController.walletOptionsIsRecovering === undefined) ? false : wizardController.walletOptionsIsRecovering
+ persistentSettings.is_recovering_from_device = (wizardController.walletOptionsIsRecoveringFromDevice === undefined) ? false : wizardController.walletOptionsIsRecoveringFromDevice
- restart();
+ restart();
+
+ onSuccess();
+ };
+
+ if (isIOS) {
+ new_wallet_filename = moneroAccountsDir + new_wallet_filename;
+ }
+ console.log("saving new wallet to", new_wallet_filename);
+ wizardController.m_wallet.storeAsync(handler, new_wallet_filename);
}
function recoveryWallet() {
diff --git a/wizard/WizardCreateWallet4.qml b/wizard/WizardCreateWallet4.qml
index f28a0f4a..2fa410fe 100644
--- a/wizard/WizardCreateWallet4.qml
+++ b/wizard/WizardCreateWallet4.qml
@@ -77,9 +77,10 @@ Rectangle {
}
}
onNextClicked: {
- wizardController.writeWallet();
- wizardController.useMoneroClicked();
- wizardController.walletOptionsIsRecoveringFromDevice = false;
+ wizardController.writeWallet(function() {
+ wizardController.useMoneroClicked();
+ wizardController.walletOptionsIsRecoveringFromDevice = false;
+ });
}
}
}
diff --git a/wizard/WizardRestoreWallet4.qml b/wizard/WizardRestoreWallet4.qml
index ac552b37..f4a0456c 100644
--- a/wizard/WizardRestoreWallet4.qml
+++ b/wizard/WizardRestoreWallet4.qml
@@ -78,8 +78,9 @@ Rectangle {
}
onNextClicked: {
wizardController.recoveryWallet();
- wizardController.writeWallet();
- wizardController.useMoneroClicked();
+ wizardController.writeWallet(function() {
+ wizardController.useMoneroClicked();
+ });
}
}
}