CLI: make sure we do not load WalletDB while another process is accessing it
- do not load WalletDB in order to check keystore password - do not allow --offline commands while a daemon is running
This commit is contained in:
24
run_electrum
24
run_electrum
@@ -152,27 +152,19 @@ def init_cmdline(config_options, wallet_path, server, *, config: 'SimpleConfig')
|
|||||||
print_stderr("Exposing a single private key can compromise your entire wallet!")
|
print_stderr("Exposing a single private key can compromise your entire wallet!")
|
||||||
print_stderr("In particular, DO NOT use 'redeem private key' services proposed by third parties.")
|
print_stderr("In particular, DO NOT use 'redeem private key' services proposed by third parties.")
|
||||||
|
|
||||||
# will we need a password
|
|
||||||
if not storage.is_encrypted():
|
|
||||||
db = WalletDB(storage.read(), manual_upgrades=False)
|
|
||||||
use_encryption = db.get('use_encryption')
|
|
||||||
else:
|
|
||||||
use_encryption = True
|
|
||||||
|
|
||||||
# commands needing password
|
# commands needing password
|
||||||
if ((cmd.requires_wallet and storage.is_encrypted() and server is False)\
|
if ((cmd.requires_wallet and storage.is_encrypted() and server is False)\
|
||||||
or (cmdname == 'load_wallet' and storage.is_encrypted())\
|
or (cmdname == 'load_wallet' and storage.is_encrypted())\
|
||||||
or (cmd.requires_password and use_encryption)):
|
or cmd.requires_password):
|
||||||
if storage.is_encrypted_with_hw_device():
|
if storage.is_encrypted_with_hw_device():
|
||||||
# this case is handled later in the control flow
|
# this case is handled later in the control flow
|
||||||
password = None
|
password = None
|
||||||
elif config.get('password'):
|
elif config.get('password') is not None:
|
||||||
password = config.get('password')
|
password = config.get('password')
|
||||||
|
if password == '':
|
||||||
|
password = None
|
||||||
else:
|
else:
|
||||||
password = prompt_password('Password:', False)
|
password = prompt_password('Password:', None)
|
||||||
if not password:
|
|
||||||
print_msg("Error: Password required")
|
|
||||||
sys_exit(1)
|
|
||||||
else:
|
else:
|
||||||
password = None
|
password = None
|
||||||
|
|
||||||
@@ -512,6 +504,12 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict):
|
|||||||
if cmd.requires_network:
|
if cmd.requires_network:
|
||||||
print_msg("This command cannot be run offline")
|
print_msg("This command cannot be run offline")
|
||||||
sys_exit(1)
|
sys_exit(1)
|
||||||
|
lockfile = daemon.get_lockfile(config)
|
||||||
|
if os.path.exists(lockfile):
|
||||||
|
print_stderr("Daemon already running (lockfile detected)")
|
||||||
|
print_stderr("Run 'electrum stop' to stop the daemon.")
|
||||||
|
print_stderr("Run this command without --offline to interact with the daemon")
|
||||||
|
sys_exit(1)
|
||||||
init_cmdline(config_options, wallet_path, False, config=config)
|
init_cmdline(config_options, wallet_path, False, config=config)
|
||||||
plugins = init_plugins(config, 'cmdline')
|
plugins = init_plugins(config, 'cmdline')
|
||||||
coro = run_offline_command(config, config_options, plugins)
|
coro = run_offline_command(config, config_options, plugins)
|
||||||
|
|||||||
Reference in New Issue
Block a user