From cfbe51a2c4529100a28d18c6329b871cb507a013 Mon Sep 17 00:00:00 2001 From: levonpetrosyan93 Date: Sun, 8 Oct 2023 13:17:09 +0400 Subject: [PATCH] Unlock screen for spark first run --- src/qt/bitcoin.cpp | 37 ++++++++++++++++++++++++++++++++++++- src/wallet/wallet.cpp | 2 ++ src/wallet/wallet.h | 5 +++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index cbea7f2b5b..7db0654d5f 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -21,7 +21,7 @@ #include "splashscreen.h" #include "utilitydialog.h" #include "winshutdownmonitor.h" - +#include "askpassphrasedialog.h" #ifdef ENABLE_WALLET #include "paymentserver.h" #include "walletmodel.h" @@ -237,6 +237,9 @@ class BitcoinApplication: public QApplication WId getMainWinId() const; public Q_SLOTS: +#ifdef ENABLE_WALLET + void unlockWallet_(void * wallet); +#endif void initializeResult(int retval); void shutdownResult(int retval); /// Handle runaway exceptions. Shows a message box with the problem and quits the program. @@ -322,6 +325,15 @@ void BitcoinCore::shutdown() } } +#ifdef ENABLE_WALLET +static void unlockWallet(BitcoinApplication* application, CWallet* wallet) +{ + Q_UNUSED(wallet); + QMetaObject::invokeMethod(application, "unlockWallet_", Qt::QueuedConnection, + Q_ARG(void *, wallet)); +} +#endif + BitcoinApplication::BitcoinApplication(int &argc, char **argv): QApplication(argc, argv), coreThread(0), @@ -346,6 +358,10 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv): if (!platformStyle) // Fall back to "other" if specified name not found platformStyle = PlatformStyle::instantiate("other"); assert(platformStyle); + +#ifdef ENABLE_WALLET + UnlockWallet.connect(boost::bind(unlockWallet, this, _1)); +#endif } BitcoinApplication::~BitcoinApplication() @@ -368,6 +384,8 @@ BitcoinApplication::~BitcoinApplication() optionsModel = 0; delete platformStyle; platformStyle = 0; + UnlockWallet.disconnect(boost::bind(unlockWallet, this, _1)); + } #ifdef ENABLE_WALLET @@ -375,6 +393,23 @@ void BitcoinApplication::createPaymentServer() { paymentServer = new PaymentServer(this); } + +void BitcoinApplication::unlockWallet_(void * wallet) +{ + CWallet * wallet_ = reinterpret_cast(wallet); + + QString info = tr("You need to unlock to allow spark wallet be created."); + + walletModel = new WalletModel(platformStyle, wallet_, optionsModel); + + // Unlock wallet when requested by wallet model + if (walletModel->getEncryptionStatus() == WalletModel::Locked) + { + AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this->window, info); + dlg.setModel(walletModel); + dlg.exec(); + } +} #endif void BitcoinApplication::createOptionsModel(bool resetSettings) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 769c9e7b49..7e086b3336 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -70,6 +70,7 @@ bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS; bool fWalletRbf = DEFAULT_WALLET_RBF; const char * DEFAULT_WALLET_DAT = "wallet.dat"; +boost::signals2::signal UnlockWallet; /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) @@ -510,6 +511,7 @@ void CWallet::RequestUnlock() { return; LogPrintf("Requesting wallet unlock\n"); + UnlockWallet(this); fUnlockRequested.store(true); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 1c91fb3909..6ea15a2ef8 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -642,6 +642,11 @@ class CAccountingEntry class LelantusJoinSplitBuilder; + +/**Open unlock wallet window**/ +//static boost::signals2::signal UnlockWallet; +extern boost::signals2::signal UnlockWallet; + /** * A CWallet is an extension of a keystore, which also maintains a set of transactions and balances, * and provides the ability to create new transactions.