mmgen-autosign: improve execution flow

This commit is contained in:
The MMGen Project 2023-04-28 11:23:23 +00:00
commit 8dd218790b
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2

View file

@ -143,6 +143,21 @@ is over.
}
}
def main(do_loop):
asi.init_led()
asi.init_exit_handler()
async def do():
await asi.check_daemons_running()
if do_loop:
await asi.do_loop()
else:
ret = await asi.do_sign()
asi.at_exit(not ret)
async_run(do())
from .autosign import Autosign,AutosignConfig
cfg = AutosignConfig(
@ -165,33 +180,19 @@ cfg._post_init()
if len(cmd_args) not in (0,1):
cfg._opts.usage()
if len(cmd_args) == 1:
if cmd_args:
cmd = cmd_args[0]
if cmd == 'gen_key':
asi.gen_key()
sys.exit(0)
elif cmd == 'setup':
asi.setup()
from .ui import keypress_confirm
if cfg.xmrwallets and keypress_confirm( cfg, '\nContinue with Monero setup?', default_yes=True ):
msg('')
asi.xmr_setup()
sys.exit(0)
elif cmd != 'wait':
elif cmd == 'wait':
main(do_loop=True)
else:
die(1,f'{cmd!r}: unrecognized command')
asi.init_led()
asi.init_exit_handler()
async def main():
await asi.check_daemons_running()
if not cmd_args:
ret = await asi.do_sign()
asi.at_exit(not ret)
elif cmd_args[0] == 'wait':
await asi.do_loop()
async_run(main())
else:
main(do_loop=False)