From 2d88491d48fbba64daae81f1084e9b199c0adc09 Mon Sep 17 00:00:00 2001 From: nahuhh <50635951+nahuhh@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:58:00 +0100 Subject: [PATCH] xmr: detect corrupt wallets --- basicswap/basicswap.py | 4 +++- basicswap/interface/wow.py | 24 ++++++++++++++++++++++++ basicswap/interface/xmr.py | 9 +++++---- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 7fd46de..66de309 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -1054,7 +1054,9 @@ class BasicSwap(BaseApp): elif c in (Coins.XMR, Coins.WOW): try: ci.ensureWalletExists() - except Exception as e: # noqa: F841 + except Exception as e: + if "invalid signature" in str(e): # wallet is corrupt + raise self.log.warning( f"Can't open {ci.coin_name()} wallet, could be locked." ) diff --git a/basicswap/interface/wow.py b/basicswap/interface/wow.py index d615b01..87dbc75 100644 --- a/basicswap/interface/wow.py +++ b/basicswap/interface/wow.py @@ -30,3 +30,27 @@ class WOWInterface(XMRInterface): @staticmethod def depth_spendable() -> int: return 3 + + # below only needed until wow is rebased to monero v0.18.4.0+ + def openWallet(self, filename): + params = {"filename": filename} + if self._wallet_password is not None: + params["password"] = self._wallet_password + + try: + self.rpc_wallet("open_wallet", params) + except Exception as e: + if "no connection to daemon" in str(e): + self._log.debug(f"{self.coin_name()} {e}") + return # bypass refresh error to allow startup with a busy daemon + + try: + # TODO Remove `store` after upstream fix to autosave on close_wallet + self.rpc_wallet("store") + self.rpc_wallet("close_wallet") + self._log.debug(f"Attempt to save and close {self.coin_name()} wallet") + except Exception as e: # noqa: F841 + pass + + self.rpc_wallet("open_wallet", params) + self._log.debug(f"Reattempt to open {self.coin_name()} wallet") diff --git a/basicswap/interface/xmr.py b/basicswap/interface/xmr.py index 32bb01b..f6bd3c4 100644 --- a/basicswap/interface/xmr.py +++ b/basicswap/interface/xmr.py @@ -205,17 +205,18 @@ class XMRInterface(CoinInterface): if "no connection to daemon" in str(e): self._log.debug(f"{self.coin_name()} {e}") return # bypass refresh error to allow startup with a busy daemon + if "invalid signature" in str(e): + self._log.debug(f"{self.coin_name()} wallet is corrupt") + raise try: - # TODO Remove `store` after upstream fix to autosave on close_wallet - self.rpc_wallet("store") self.rpc_wallet("close_wallet") - self._log.debug(f"Attempt to save and close {self.coin_name()} wallet") + self._log.debug(f"Closing {self.coin_name()} wallet") except Exception as e: # noqa: F841 pass self.rpc_wallet("open_wallet", params) - self._log.debug(f"Reattempt to open {self.coin_name()} wallet") + self._log.debug(f"Attempting to open {self.coin_name()} wallet") def initialiseWallet( self, key_view: bytes, key_spend: bytes, restore_height=None