]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
Warn if wallet file was not created with Feather
authortobtoht <thotbot@protonmail.com>
Fri, 4 Mar 2022 12:30:26 +0000 (13:30 +0100)
committertobtoht <thotbot@protonmail.com>
Fri, 4 Mar 2022 12:30:26 +0000 (13:30 +0100)
src/WindowManager.cpp
src/libwalletqt/Wallet.cpp
src/libwalletqt/Wallet.h
src/libwalletqt/WalletManager.cpp

index d0eb903e24f727ab5bb4e863e630ebbd61e576ea..a1e87a785ee8fe261f204bc4ee19682332fce792 100644 (file)
@@ -158,17 +158,21 @@ void WindowManager::tryOpenWallet(const QString &path, const QString &password)
 }
 
 void WindowManager::onWalletOpened(Wallet *wallet) {
-    if (wallet->status() != Wallet::Status_Ok) {
+    auto status = wallet->status();
+    if (status != Wallet::Status_Ok) {
         QString errMsg = wallet->errorString();
-        if (wallet->status() == Wallet::Status_BadPassword) {
+        QString keysPath = wallet->keysPath();
+        QString cachePath = wallet->cachePath();
+        wallet->deleteLater();
+        if (status == Wallet::Status_BadPassword) {
             // Don't show incorrect password when we try with empty password for the first time
             bool showIncorrectPassword = m_openWalletTriedOnce;
             m_openWalletTriedOnce = true;
-            this->onWalletOpenPasswordRequired(showIncorrectPassword, wallet->keysPath());
+            this->onWalletOpenPasswordRequired(showIncorrectPassword, keysPath);
         }
         else if (errMsg == QString("basic_string::_M_replace_aux") || errMsg == QString("std::bad_alloc")) {
             qCritical() << errMsg;
-            WalletManager::clearWalletCache(wallet->cachePath()); // TODO: check this
+            WalletManager::clearWalletCache(cachePath);
             errMsg = QString("%1\n\nAttempted to clean wallet cache. Please restart Feather.").arg(errMsg);
             this->handleWalletError(errMsg);
         } else {
@@ -179,6 +183,16 @@ void WindowManager::onWalletOpened(Wallet *wallet) {
 
     this->onInitialNetworkConfigured();
 
+    if (!wallet->cacheAttributeExists("feather.xmrig_password") && !wallet->cacheAttributeExists("feather.created")) {
+        auto result = QMessageBox::question(nullptr, "Foreign wallet",
+                                            "This wallet file was not created with Feather. This may cause unexpected behavior. Please restore your wallet from seed.\n\nOpen this wallet anyway?");
+        if (result == QMessageBox::No) {
+            wallet->deleteLater();
+            this->initWizard();
+            return;
+        }
+    }
+
     // Create new mainwindow with wallet
 
     m_splashDialog->hide();
index 0b0708d44453b138665036674b271802f1b161e9..0a125b0494b6e23abadf63e2a994a863f1b1ba87 100644 (file)
@@ -958,6 +958,10 @@ QString Wallet::integratedAddress(const QString &paymentId) const
     return QString::fromStdString(m_walletImpl->integratedAddress(paymentId.toStdString()));
 }
 
+bool Wallet::cacheAttributeExists(const QString &key) {
+    return m_walletImpl->cacheAttributeExists(key.toStdString());
+}
+
 QString Wallet::getCacheAttribute(const QString &key) const {
     return QString::fromStdString(m_walletImpl->getCacheAttribute(key.toStdString()));
 }
index ff14309ec2d6d65609d60e0fcb92722c826c4d30..19ec6855ffe07263de5b65ad92862397b7a8b58a 100644 (file)
@@ -394,6 +394,7 @@ public:
     QString make_uri(const QString &address, quint64 &amount, const QString &description, const QString &recipient) const;
 
     //! Namespace your cacheAttribute keys to avoid collisions
+    bool cacheAttributeExists(const QString &key);
     bool setCacheAttribute(const QString &key, const QString &val);
     QString getCacheAttribute(const QString &key) const;
 
index 6b3adb705f7cabfb115400e851a4560e96aa82a8..8141c737b83bc0e500df2c16c1802b9c6a107dac 100644 (file)
@@ -290,7 +290,7 @@ bool WalletManager::clearWalletCache(const QString &wallet_path)
 
     // create unique file name
     for (int i = 1; QFile::exists(newFileName); i++) {
-       newFileName = QString("%1%2.%3").arg(fileName).arg(suffix).arg(i);
+       newFileName = QString("%1%2.%3").arg(fileName, suffix, QString::number(i));
     }
 
     return walletCache.rename(newFileName);