Browse Source

Syntax change: Require --offline to run commands without a daemon.

That makes the syntax less ambiguous. It also makes it possible to
implement a CLI that does not import all the electrum modules.
dependabot/pip/contrib/deterministic-build/ecdsa-0.13.3
ThomasV 5 years ago
parent
commit
e79253b5e0
  1. 2
      electrum/commands.py
  2. 32
      electrum/tests/regtest/regtest.sh
  3. 35
      run_electrum

2
electrum/commands.py

@ -1091,6 +1091,7 @@ def add_global_options(parser):
group.add_argument("--simnet", action="store_true", dest="simnet", default=False, help="Use Simnet")
group.add_argument("--lightning", action="store_true", dest="lightning", default=False, help="Enable lightning")
group.add_argument("--reckless", action="store_true", dest="reckless", default=False, help="Allow to enable lightning on mainnet")
group.add_argument("-o", "--offline", action="store_true", dest="offline", default=False, help="Run offline")
def get_parser():
# create main parser
@ -1102,7 +1103,6 @@ def get_parser():
parser_gui = subparsers.add_parser('gui', description="Run Electrum's Graphical User Interface.", help="Run GUI (default)")
parser_gui.add_argument("url", nargs='?', default=None, help="bitcoin URI (or bip70 file)")
parser_gui.add_argument("-g", "--gui", dest="gui", help="select graphical user interface", choices=['qt', 'kivy', 'text', 'stdio'])
parser_gui.add_argument("-o", "--offline", action="store_true", dest="offline", default=False, help="Run offline")
parser_gui.add_argument("-m", action="store_true", dest="hide_gui", default=False, help="hide GUI on startup")
parser_gui.add_argument("-L", "--lang", dest="language", default=None, help="default language used in GUI")
parser_gui.add_argument("--daemon", action="store_true", dest="daemon", default=False, help="keep daemon running after GUI is closed")

32
electrum/tests/regtest/regtest.sh

@ -70,20 +70,20 @@ fi
if [[ $1 == "init" ]]; then
echo "initializing alice, bob and carol"
rm -rf /tmp/alice/ /tmp/bob/ /tmp/carol/
$alice create > /dev/null
$bob create > /dev/null
$carol create > /dev/null
$alice setconfig log_to_file True
$bob setconfig log_to_file True
$carol setconfig log_to_file True
$alice setconfig server 127.0.0.1:51001:t
$bob setconfig server 127.0.0.1:51001:t
$carol setconfig server 127.0.0.1:51001:t
$bob setconfig lightning_listen localhost:9735
$bob setconfig lightning_forward_payments true
$alice create --offline > /dev/null
$bob create --offline > /dev/null
$carol create --offline > /dev/null
$alice setconfig --offline log_to_file True
$bob setconfig --offline log_to_file True
$carol setconfig --offline log_to_file True
$alice setconfig --offline server 127.0.0.1:51001:t
$bob setconfig --offline server 127.0.0.1:51001:t
$carol setconfig --offline server 127.0.0.1:51001:t
$bob setconfig --offline lightning_listen localhost:9735
$bob setconfig --offline lightning_forward_payments true
echo "funding alice and carol"
$bitcoin_cli sendtoaddress $($alice getunusedaddress) 1
$bitcoin_cli sendtoaddress $($carol getunusedaddress) 1
$bitcoin_cli sendtoaddress $($alice getunusedaddress -o) 1
$bitcoin_cli sendtoaddress $($carol getunusedaddress -o) 1
new_blocks 1
fi
@ -296,9 +296,9 @@ if [[ $1 == "watchtower" ]]; then
# carol is a watchtower of alice
$alice stop
$carol stop
$alice setconfig watchtower_url http://127.0.0.1:12345
$carol setconfig watchtower_host 127.0.0.1
$carol setconfig watchtower_port 12345
$alice setconfig --offline watchtower_url http://127.0.0.1:12345
$carol setconfig --offline watchtower_host 127.0.0.1
$carol setconfig --offline watchtower_port 12345
$carol daemon start
$alice daemon start
sleep 1

35
run_electrum

@ -398,25 +398,34 @@ if __name__ == '__main__':
sys_exit(1)
else:
# command line
try:
cmd = known_commands[cmdname]
if not config.get('offline'):
init_cmdline(config_options, True)
timeout = config_options.get('timeout', 60)
if timeout: timeout = int(timeout)
result = daemon.request(config, 'run_cmdline', (config_options,), timeout)
except daemon.DaemonNotRunning:
cmd = known_commands[cmdname]
if cmd.requires_network:
try:
result = daemon.request(config, 'run_cmdline', (config_options,), timeout)
except daemon.DaemonNotRunning:
print_msg("Daemon not running; try 'electrum daemon start'")
if not cmd.requires_network:
print_msg("To run this command without a daemon, use --offline")
sys_exit(1)
else:
init_cmdline(config_options, False)
plugins = init_plugins(config, 'cmdline')
coro = run_offline_command(config, config_options, plugins)
fut = asyncio.run_coroutine_threadsafe(coro, loop)
except Exception as e:
print_stderr(e)
sys_exit(1)
else:
if cmd.requires_network:
print_msg("This command cannot be run offline")
sys_exit(1)
init_cmdline(config_options, False)
plugins = init_plugins(config, 'cmdline')
coro = run_offline_command(config, config_options, plugins)
fut = asyncio.run_coroutine_threadsafe(coro, loop)
try:
result = fut.result(10)
except Exception as e:
print_stderr(e)
sys_exit(1)
except Exception as e:
print_stderr(e)
sys_exit(1)
if isinstance(result, str):
print_msg(result)
elif type(result) is dict and result.get('error'):

Loading…
Cancel
Save