diff --git a/electrum/commands.py b/electrum/commands.py index 111d0cf0c..7e5a68709 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -246,7 +246,6 @@ class Commands(Logger): 'connected': self.network.is_connected(), 'auto_connect': net_params.auto_connect, 'version': ELECTRUM_VERSION, - 'current_wallet': self.config.get_wallet_path(use_fallback=False), 'fee_estimates': self.network.fee_estimates.get_data() } return response diff --git a/electrum/daemon.py b/electrum/daemon.py index 253756879..1b3bcb7ad 100644 --- a/electrum/daemon.py +++ b/electrum/daemon.py @@ -363,10 +363,14 @@ class CommandsServer(AuthenticatedServer): kwargs = {} for x in cmd.options: kwargs[x] = config_options.get(x) - if 'wallet_path' in cmd.options: - kwargs['wallet_path'] = config_options.get('wallet_path') - elif 'wallet' in cmd.options: - kwargs['wallet'] = config_options.get('wallet_path') + if 'wallet_path' in cmd.options or 'wallet' in cmd.options: + wallet_path = config_options.get('wallet_path') + if len(self.daemon._wallets) > 1 and wallet_path is None: + raise UserFacingException("error: wallet not specified") + if 'wallet_path' in cmd.options: + kwargs['wallet_path'] = wallet_path + else: + kwargs['wallet'] = wallet_path func = getattr(self.cmd_runner, cmd.name) # execute requested command now. note: cmd can raise, the caller (self.handle) will wrap it. result = await func(*args, **kwargs) @@ -477,14 +481,10 @@ class Daemon(Logger): coro = wallet.lnworker.lnwatcher.trigger_callbacks(requires_synchronizer=False) asyncio.run_coroutine_threadsafe(coro, self.asyncio_loop) self.add_wallet(wallet) - self.update_current_wallet() + self.config.CURRENT_WALLET = wallet_key self.update_recently_opened_wallets(path) return wallet - def update_current_wallet(self): - if not self._wallets: - return - self.config.CURRENT_WALLET = list(self._wallets.keys())[0] if len(self._wallets) == 1 else None @staticmethod @profiler @@ -546,8 +546,9 @@ class Daemon(Logger): wallet = self._wallets.pop(wallet_key, None) if not wallet: return False - self.update_current_wallet() await wallet.stop() + if self.config.CURRENT_WALLET == wallet_key and self._wallets: + self.config.CURRENT_WALLET = list(self._wallets.keys())[0] return True def run_daemon(self): diff --git a/electrum/simple_config.py b/electrum/simple_config.py index 5b7d975b5..a48e29521 100644 --- a/electrum/simple_config.py +++ b/electrum/simple_config.py @@ -458,7 +458,7 @@ class SimpleConfig(Logger): else: return self.WALLET_BACKUP_DIRECTORY - def get_wallet_path(self, *, use_fallback=True) -> Optional[str]: + def get_wallet_path(self) -> str: """Returns the wallet path.""" # command line -w option if self.get('wallet_path'): @@ -467,9 +467,7 @@ class SimpleConfig(Logger): path = self.CURRENT_WALLET if path and os.path.exists(path): return path - if use_fallback: - return self.get_fallback_wallet_path() - return + return self.get_fallback_wallet_path() def get_datadir_wallet_path(self): util.assert_datadir_available(self.path) diff --git a/run_electrum b/run_electrum index b04fc0d8a..6808c092d 100755 --- a/run_electrum +++ b/run_electrum @@ -531,8 +531,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict): # command line configure_logging(config, log_to_file=False) # don't spam logfiles for each client-side RPC, but support "-v" cmd = known_commands[cmdname] - use_fallback = (cmdname in ['create', 'restore', 'load_wallet']) - wallet_path = config.get_wallet_path(use_fallback=use_fallback) + wallet_path = config.get_wallet_path() if cmd.requires_wallet and not wallet_path: print_stderr('wallet path not provided') sys_exit(1)