1
0

cmdline: use 'wallet_path' argument to pass wallet_path

This commit is contained in:
ThomasV
2025-06-04 14:23:25 +02:00
parent 5efeaf13c5
commit 37914d5af0
3 changed files with 8 additions and 16 deletions

View File

@@ -166,11 +166,12 @@ def command(s):
if 'wallet_path' in cmd.options and kwargs.get('wallet_path') is None: if 'wallet_path' in cmd.options and kwargs.get('wallet_path') is None:
kwargs['wallet_path'] = daemon.config.get_wallet_path() kwargs['wallet_path'] = daemon.config.get_wallet_path()
if cmd.requires_wallet and kwargs.get('wallet') is None: if cmd.requires_wallet and kwargs.get('wallet') is None:
kwargs['wallet'] = daemon.config.get_wallet_path() kwargs['wallet_path'] = daemon.config.get_wallet_path()
if 'wallet' in cmd.options: if 'wallet' in cmd.options:
wallet = kwargs.get('wallet', None) wallet_path = kwargs.pop('wallet_path', None) # unit tests may set wallet and not wallet_path
if isinstance(wallet, str): wallet = kwargs.get('wallet', None) # run_offline_command sets both
wallet = daemon.get_wallet(wallet) if wallet is None:
wallet = daemon.get_wallet(wallet_path)
if wallet is None: if wallet is None:
raise UserFacingException('wallet not loaded') raise UserFacingException('wallet not loaded')
kwargs['wallet'] = wallet kwargs['wallet'] = wallet

View File

@@ -367,10 +367,7 @@ class CommandsServer(AuthenticatedServer):
wallet_path = config_options.get('wallet_path') wallet_path = config_options.get('wallet_path')
if len(self.daemon._wallets) > 1 and wallet_path is None: if len(self.daemon._wallets) > 1 and wallet_path is None:
raise UserFacingException("error: wallet not specified") raise UserFacingException("error: wallet not specified")
if 'wallet_path' in cmd.options: kwargs['wallet_path'] = wallet_path
kwargs['wallet_path'] = wallet_path
else:
kwargs['wallet'] = wallet_path
func = getattr(self.cmd_runner, cmd.name) func = getattr(self.cmd_runner, cmd.name)
# execute requested command now. note: cmd can raise, the caller (self.handle) will wrap it. # execute requested command now. note: cmd can raise, the caller (self.handle) will wrap it.
result = await func(*args, **kwargs) result = await func(*args, **kwargs)

View File

@@ -215,11 +215,8 @@ class TestCommandsWithDaemon(DaemonTestCase):
await cmds.load_wallet(wallet_path=wpath, password="123456") await cmds.load_wallet(wallet_path=wpath, password="123456")
wallet = self.daemon.get_wallet(wpath) wallet = self.daemon.get_wallet(wpath)
self.assertIsInstance(wallet, Abstract_Wallet) self.assertIsInstance(wallet, Abstract_Wallet)
# when using the CLI/RPC to run commands, the "wallet" param is a path:
self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver", self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver",
await cmds.getseed(wallet=wpath, password="123456")) await cmds.getseed(wallet_path=wpath, password="123456"))
# in unit tests or custom code, the "wallet" param is often an Abstract_Wallet:
self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver", self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver",
await cmds.getseed(wallet=wallet, password="123456")) await cmds.getseed(wallet=wallet, password="123456"))
@@ -229,10 +226,7 @@ class TestCommandsWithDaemon(DaemonTestCase):
await cmds.load_wallet(wallet_path=wpath, password=None) await cmds.load_wallet(wallet_path=wpath, password=None)
wallet = self.daemon.get_wallet(wpath) wallet = self.daemon.get_wallet(wpath)
self.assertIsInstance(wallet, Abstract_Wallet) self.assertIsInstance(wallet, Abstract_Wallet)
# when using the CLI/RPC to run commands, the "wallet" param is a path:
self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver", self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver",
await cmds.getseed(wallet=wpath)) await cmds.getseed(wallet_path=wpath))
# in unit tests or custom code, the "wallet" param is often an Abstract_Wallet:
self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver", self.assertEqual("bitter grass shiver impose acquire brush forget axis eager alone wine silver",
await cmds.getseed(wallet=wallet)) await cmds.getseed(wallet=wallet))