1
0

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
    7113cec4c7,
    it is more robust for the function itself to do it
- get_unlocked_password() should never return an invalid password
- add is_unlocked()
This commit is contained in:
SomberNight
2026-01-16 17:28:41 +00:00
parent d5ca2e89d5
commit 91f286b422

View File

@@ -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,