From 91f286b422ace9d928dcd736394c5c9e9cfeb521 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 16 Jan 2026 17:28:41 +0000 Subject: [PATCH] wallet: minor clean-up and sanity checks for unlock/lock - unlock() did not handle password=="" well instead of the caller converting the arg, as in https://github.com/spesmilo/electrum/commit/7113cec4c724c2a443031c71cc8d08fee5e2f385, it is more robust for the function itself to do it - get_unlocked_password() should never return an invalid password - add is_unlocked() --- electrum/wallet.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/electrum/wallet.py b/electrum/wallet.py index cf7874ff0..c852603af 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -3532,16 +3532,27 @@ class Abstract_Wallet(ABC, Logger, EventListener): """Returns the number of new addresses we generated.""" return 0 - def unlock(self, password): + def unlock(self, password: Optional[str]) -> None: self.logger.info(f'unlocking wallet') + password = password or None self.check_password(password) self._password_in_memory = password def lock_wallet(self): self._password_in_memory = None - def get_unlocked_password(self): - return self._password_in_memory + def get_unlocked_password(self) -> Optional[str]: + pw = self._password_in_memory + if not self.is_unlocked(): + return None + try: + self.check_password(pw) + except InvalidPassword as e: + raise Exception("inconsistent _password_in_memory") from e + return pw + + def is_unlocked(self) -> bool: + return self._password_in_memory is not None or not self.has_password() def get_text_not_enough_funds_mentioning_frozen( self,