electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit e79253b5e067ef513f4dbd9f8750497a04897927
parent c67fb88e5862a97c9b1841f9c449bb0724defcbf
Author: ThomasV <thomasv@electrum.org>
Date:   Sat, 31 Aug 2019 09:19:46 +0200

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.

Diffstat:
Melectrum/commands.py | 2+-
Melectrum/tests/regtest/regtest.sh | 32++++++++++++++++----------------
Mrun_electrum | 35++++++++++++++++++++++-------------
3 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/electrum/commands.py b/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") diff --git a/electrum/tests/regtest/regtest.sh b/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 diff --git a/run_electrum b/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'):