daemon: load_wallet: add force_check_password arg, and use it in qml
- fix: qml gui errors when trying to open a wallets with only keystore-encryption - fixes https://github.com/spesmilo/electrum/issues/10171 - qml gui to prompt for password on wallet open even if wallet is not storage-encrypted
This commit is contained in:
@@ -476,14 +476,28 @@ class Daemon(Logger):
|
||||
return func_wrapper
|
||||
|
||||
@with_wallet_lock
|
||||
def load_wallet(self, path, password, *, upgrade=False) -> Optional[Abstract_Wallet]:
|
||||
def load_wallet(
|
||||
self,
|
||||
path,
|
||||
password: Optional[str],
|
||||
*,
|
||||
upgrade: bool = False,
|
||||
force_check_password: bool = False,
|
||||
) -> Optional[Abstract_Wallet]:
|
||||
"""
|
||||
force_check_password: if False, the password arg is only used if it needed to decrypt the storage.
|
||||
if True, the password arg is always validated.
|
||||
"""
|
||||
assert password != ''
|
||||
path = standardize_path(path)
|
||||
wallet_key = self._wallet_key_from_path(path)
|
||||
# wizard will be launched if we return
|
||||
if wallet := self._wallets.get(wallet_key):
|
||||
if force_check_password:
|
||||
wallet.check_password(password)
|
||||
return wallet
|
||||
wallet = self._load_wallet(path, password, upgrade=upgrade, config=self.config)
|
||||
wallet = self._load_wallet(
|
||||
path, password, upgrade=upgrade, config=self.config, force_check_password=force_check_password)
|
||||
if self.network:
|
||||
wallet.start_network(self.network)
|
||||
elif wallet.lnworker:
|
||||
@@ -501,10 +515,11 @@ class Daemon(Logger):
|
||||
@profiler
|
||||
def _load_wallet(
|
||||
path,
|
||||
password,
|
||||
password: Optional[str],
|
||||
*,
|
||||
upgrade: bool = False,
|
||||
config: SimpleConfig,
|
||||
force_check_password: bool = False, # if set, always validate password
|
||||
) -> Optional[Abstract_Wallet]:
|
||||
path = standardize_path(path)
|
||||
storage = WalletStorage(path, allow_partial_writes=config.WALLET_PARTIAL_WRITES)
|
||||
@@ -519,6 +534,8 @@ class Daemon(Logger):
|
||||
if db.get_action():
|
||||
raise WalletUnfinished(db)
|
||||
wallet = Wallet(db, config=config)
|
||||
if force_check_password:
|
||||
wallet.check_password(password)
|
||||
return wallet
|
||||
|
||||
@with_wallet_lock
|
||||
@@ -546,7 +563,7 @@ class Daemon(Logger):
|
||||
|
||||
def stop_wallet(self, path: str) -> bool:
|
||||
"""Returns True iff a wallet was found."""
|
||||
# note: this must not be called from the event loop. # TODO raise if so
|
||||
assert util.get_running_loop() != util.get_asyncio_loop(), 'must not be called from asyncio thread'
|
||||
fut = asyncio.run_coroutine_threadsafe(self._stop_wallet(path), self.asyncio_loop)
|
||||
return fut.result()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user