aboutsummaryrefslogtreecommitdiff
path: root/src/libwalletqt/WalletManager.cpp
diff options
context:
space:
mode:
authorDusan Klinec <dusan.klinec@gmail.com>2020-04-11 12:43:21 +0200
committerDusan Klinec <dusan.klinec@gmail.com>2020-05-08 18:40:17 +0200
commit86d21a34baacb7d317b8774b3409781bb3dde037 (patch)
tree2bb83dcc37e8fe0a77e8311824db75afd973d037 /src/libwalletqt/WalletManager.cpp
parent38612c1285889f59a8c94bb412354bb7bed4108a (diff)
downloadmonzero-gui-86d21a34baacb7d317b8774b3409781bb3dde037.tar.gz
monzero-gui-86d21a34baacb7d317b8774b3409781bb3dde037.tar.xz
monzero-gui-86d21a34baacb7d317b8774b3409781bb3dde037.zip
trezor: support new passphrase entry mechanism
- passphrase can be prompted also when wallet is running (thus added to the wallet listener) - device/host decision is now made on the host
Diffstat (limited to 'src/libwalletqt/WalletManager.cpp')
-rw-r--r--src/libwalletqt/WalletManager.cpp74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp
index a5c9e0ff..62836149 100644
--- a/src/libwalletqt/WalletManager.cpp
+++ b/src/libwalletqt/WalletManager.cpp
@@ -42,11 +42,12 @@
#include <QString>
#include "qt/updater.h"
+#include "qt/ScopeGuard.h"
-class WalletPassphraseListenerImpl : public Monero::WalletListener
+class WalletPassphraseListenerImpl : public Monero::WalletListener, public PassphraseReceiver
{
public:
- WalletPassphraseListenerImpl(WalletManager * mgr): m_mgr(mgr), m_wallet(nullptr) {}
+ WalletPassphraseListenerImpl(WalletManager * mgr): m_mgr(mgr), m_phelper(mgr) {}
virtual void moneySpent(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
virtual void moneyReceived(const std::string &txId, uint64_t amount) override { (void)txId; (void)amount; };
@@ -55,43 +56,33 @@ public:
virtual void updated() override {};
virtual void refreshed() override {};
- virtual Monero::optional<std::string> onDevicePassphraseRequest(bool on_device) override
+ virtual void onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort) override
{
qDebug() << __FUNCTION__;
- if (on_device) return Monero::optional<std::string>();
-
- m_mgr->onWalletPassphraseNeeded(m_wallet);
-
- if (m_mgr->m_passphrase_abort)
- {
- throw std::runtime_error("Passphrase entry abort");
- }
-
- auto tmpPass = m_mgr->m_passphrase.toStdString();
- m_mgr->m_passphrase = QString();
-
- return Monero::optional<std::string>(tmpPass);
+ m_phelper.onPassphraseEntered(passphrase, enter_on_device, entry_abort);
}
- virtual void onDeviceButtonRequest(uint64_t code) override
+ virtual Monero::optional<std::string> onDevicePassphraseRequest(bool & on_device) override
{
- emit m_mgr->deviceButtonRequest(code);
+ qDebug() << __FUNCTION__;
+ return m_phelper.onDevicePassphraseRequest(on_device);
}
- virtual void onDeviceButtonPressed() override
+ virtual void onDeviceButtonRequest(uint64_t code) override
{
- emit m_mgr->deviceButtonPressed();
+ qDebug() << __FUNCTION__;
+ emit m_mgr->deviceButtonRequest(code);
}
- virtual void onSetWallet(Monero::Wallet * wallet) override
+ virtual void onDeviceButtonPressed() override
{
qDebug() << __FUNCTION__;
- m_wallet = wallet;
+ emit m_mgr->deviceButtonPressed();
}
private:
WalletManager * m_mgr;
- Monero::Wallet * m_wallet;
+ PassphraseHelper m_phelper;
};
WalletManager * WalletManager::m_instance = nullptr;
@@ -123,6 +114,13 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password,
{
QMutexLocker locker(&m_mutex);
WalletPassphraseListenerImpl tmpListener(this);
+ m_mutex_passphraseReceiver.lock();
+ m_passphraseReceiver = &tmpListener;
+ m_mutex_passphraseReceiver.unlock();
+ const auto cleanup = sg::make_scope_guard([this]() noexcept {
+ QMutexLocker passphrase_locker(&m_mutex_passphraseReceiver);
+ this->m_passphraseReceiver = nullptr;
+ });
if (m_currentWallet) {
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
@@ -186,6 +184,13 @@ Wallet *WalletManager::createWalletFromDevice(const QString &path, const QString
{
QMutexLocker locker(&m_mutex);
WalletPassphraseListenerImpl tmpListener(this);
+ m_mutex_passphraseReceiver.lock();
+ m_passphraseReceiver = &tmpListener;
+ m_mutex_passphraseReceiver.unlock();
+ const auto cleanup = sg::make_scope_guard([this]() noexcept {
+ QMutexLocker passphrase_locker(&m_mutex_passphraseReceiver);
+ this->m_passphraseReceiver = nullptr;
+ });
if (m_currentWallet) {
qDebug() << "Closing open m_currentWallet" << m_currentWallet;
@@ -529,6 +534,7 @@ bool WalletManager::clearWalletCache(const QString &wallet_path) const
WalletManager::WalletManager(QObject *parent)
: QObject(parent)
+ , m_passphraseReceiver(nullptr)
, m_scheduler(this)
{
m_pimpl = Monero::WalletManagerFactory::getWalletManager();
@@ -539,22 +545,16 @@ WalletManager::~WalletManager()
m_scheduler.shutdownWaitForFinished();
}
-void WalletManager::onWalletPassphraseNeeded(Monero::Wallet *)
+void WalletManager::onWalletPassphraseNeeded(bool on_device)
{
- m_mutex_pass.lock();
- m_passphrase_abort = false;
- emit this->walletPassphraseNeeded();
-
- m_cond_pass.wait(&m_mutex_pass);
- m_mutex_pass.unlock();
+ emit this->walletPassphraseNeeded(on_device);
}
-void WalletManager::onPassphraseEntered(const QString &passphrase, bool entry_abort)
+void WalletManager::onPassphraseEntered(const QString &passphrase, bool enter_on_device, bool entry_abort)
{
- m_mutex_pass.lock();
- m_passphrase = passphrase;
- m_passphrase_abort = entry_abort;
-
- m_cond_pass.wakeAll();
- m_mutex_pass.unlock();
+ QMutexLocker locker(&m_mutex_passphraseReceiver);
+ if (m_passphraseReceiver != nullptr)
+ {
+ m_passphraseReceiver->onPassphraseEntered(passphrase, enter_on_device, entry_abort);
+ }
}