1
0

password unification refactor: move methods from wallet to daemon

Note in particular that check_password_for_directory was not safe to use while the daemon had wallets loaded,
as the same file would have two corresponding Wallet() instances in memory. This was specifically handled in
the kivy GUI, on the caller side, by stopping-before and reloading-after the wallets; but it was dirty to
have the caller handle this.
This commit is contained in:
SomberNight
2022-07-06 18:33:08 +02:00
parent c71f00cc8e
commit c463f5e23d
4 changed files with 97 additions and 86 deletions

View File

@@ -12,7 +12,6 @@ from typing import TYPE_CHECKING, Optional, Union, Callable, Sequence
from electrum.storage import WalletStorage, StorageReadWriteError
from electrum.wallet_db import WalletDB
from electrum.wallet import Wallet, InternalAddressCorruption, Abstract_Wallet
from electrum.wallet import update_password_for_directory
from electrum.plugin import run_hook
from electrum import util
@@ -679,7 +678,8 @@ class ElectrumWindow(App, Logger, EventListener):
def on_wizard_success(self, storage, db, password):
self.password = password
if self.electrum_config.get('single_password'):
self._use_single_password = update_password_for_directory(self.electrum_config, password, password)
self._use_single_password = self.daemon.update_password_for_directory(
old_password=password, new_password=password)
self.logger.info(f'use single password: {self._use_single_password}')
wallet = Wallet(db, storage, config=self.electrum_config)
wallet.start_network(self.daemon.network)
@@ -1346,10 +1346,7 @@ class ElectrumWindow(App, Logger, EventListener):
# called if old_password works on self.wallet
self.password = new_password
if self._use_single_password:
path = self.wallet.storage.path
self.stop_wallet()
update_password_for_directory(self.electrum_config, old_password, new_password)
self.load_wallet_by_name(path)
self.daemon.update_password_for_directory(old_password=old_password, new_password=new_password)
msg = _("Password updated successfully")
else:
self.wallet.update_password(old_password, new_password)