diff --git a/electrum/daemon.py b/electrum/daemon.py index 40fb1ac9c..46fe96a84 100644 --- a/electrum/daemon.py +++ b/electrum/daemon.py @@ -495,6 +495,8 @@ class Daemon(Logger): if wallet := self._wallets.get(wallet_key): return wallet wallet = self._load_wallet(path, password, upgrade=upgrade, config=self.config) + if wallet.requires_unlock(): + wallet.unlock(password) wallet.start_network(self.network) self.add_wallet(wallet) self.update_recently_opened_wallets(path) diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index a2aaff7c1..4ff0a8c6c 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -251,7 +251,8 @@ class QEDaemon(AuthMixin, QObject): assert wallet is not None self._current_wallet = QEWallet.getInstanceFor(wallet) self.availableWallets.updateWallet(self._path) - self._current_wallet.password = password if password else None + if wallet.requires_unlock(): + wallet.unlock(password) self._loading = False self.loadingChanged.emit() self.walletLoaded.emit(self._name, self._path) diff --git a/electrum/gui/qml/qewallet.py b/electrum/gui/qml/qewallet.py index 6386eaf20..6990e05ed 100644 --- a/electrum/gui/qml/qewallet.py +++ b/electrum/gui/qml/qewallet.py @@ -731,12 +731,16 @@ class QEWallet(AuthMixin, QObject, QtEventListener): try: self._logger.info('setting new password') self.wallet.update_password(current_password, password, encrypt_storage=True) - self.password = password + self.wallet.unlock(password) return True except InvalidPassword as e: self._logger.exception(repr(e)) return False + @property + def password(self): + return self.wallet.get_unlocked_password() + @pyqtSlot(str) def importAddresses(self, addresslist): self.wallet.import_addresses(addresslist.split()) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 935370ea8..6b67ff867 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -1291,6 +1291,8 @@ class LNWallet(LNWorker): zeroconf: bool = False, opening_fee: int = None, password=None): + if self.config.ENABLE_ANCHOR_CHANNELS: + self.wallet.unlock(password) coins = self.wallet.get_spendable_coins(None) node_id = peer.pubkey funding_tx = self.mktx_for_open_channel( diff --git a/electrum/wallet.py b/electrum/wallet.py index 88e532e30..3439f34c4 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -502,6 +502,12 @@ class Abstract_Wallet(ABC, Logger, EventListener): def has_lightning(self) -> bool: return bool(self.lnworker) + def has_channels(self): + return self.lnworker is not None and len(self.lnworker._channels) > 0 + + def requires_unlock(self): + return self.config.ENABLE_ANCHOR_CHANNELS and self.has_channels() + def can_have_lightning(self) -> bool: # we want static_remotekey to be a wallet address return self.txin_type == 'p2wpkh' @@ -2977,8 +2983,8 @@ class Abstract_Wallet(ABC, Logger, EventListener): if self.storage and self.storage.file_exists(): self.db.write_and_force_consolidation() # if wallet was previously unlocked, update password in memory - if self._password_in_memory is not None: - self._password_in_memory = new_pw + if self.requires_unlock(): + self.unlock(new_pw) @abstractmethod def _update_password_for_keystore(self, old_pw: Optional[str], new_pw: Optional[str]) -> None: