start-coin-daemons.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python3
  2. import sys
  3. from include.tests_header import repo_root
  4. from mmgen.common import *
  5. from mmgen.daemon import CoinDaemon
  6. from mmgen.regtest import MMGenRegtest
  7. action = g.prog_name.split('-')[0]
  8. opts_data = {
  9. 'sets': [('debug',True,'verbose',True)],
  10. 'text': {
  11. 'desc': '{} coin daemons for the MMGen test suite'.format(action.capitalize()),
  12. 'usage':'[opts] <network IDs>',
  13. 'options': """
  14. -h, --help Print this help message
  15. --, --longhelp Print help message for long options (common options)
  16. -d, --debug Produce debugging output (implies --verbose)
  17. -D, --no-daemonize Don't fork daemon to background
  18. -r, --regtest-user=U {a} a regtest daemon for user 'U'
  19. -s, --get-state Get the state of the daemon(s) and exit
  20. -t, --testing Testing mode. Print commands but don't execute them
  21. -v, --verbose Produce more verbose output
  22. -W, --no-wait Don't wait for daemons to change state before exiting
  23. """,
  24. 'notes': """
  25. Valid network IDs: {nid}, all, or no_xmr
  26. Valid Regtest network IDs: {rid}, or all
  27. Valid Regtest users: {ru}
  28. """
  29. },
  30. 'code': {
  31. 'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name),
  32. 'notes': lambda s: s.format(
  33. nid=', '.join(CoinDaemon.network_ids),
  34. rid=', '.join(MMGenRegtest.coins),
  35. ru=', '.join(MMGenRegtest.users),
  36. )
  37. }
  38. }
  39. cmd_args = opts.init(opts_data)
  40. if 'all' in cmd_args or 'no_xmr' in cmd_args:
  41. if len(cmd_args) != 1:
  42. die(1,"'all' or 'no_xmr' must be the sole argument")
  43. if opt.regtest_user:
  44. ids = MMGenRegtest.coins
  45. else:
  46. ids = list(CoinDaemon.network_ids)
  47. if cmd_args[0] == 'no_xmr':
  48. ids.remove('xmr')
  49. else:
  50. ids = cmd_args
  51. if not ids:
  52. opts.usage()
  53. for i in ids:
  54. if i not in CoinDaemon.network_ids:
  55. die(1,f'{i!r}: invalid network ID')
  56. if i.endswith('_rt'):
  57. die(1,'For regtest, use the plain coin symbol and the --regtest-user option')
  58. if opt.regtest_user and i not in MMGenRegtest.coins:
  59. die(1,f'For regtest, coin symbol must be one of {MMGenRegtest.coins}')
  60. if 'eth' in ids and 'etc' in ids:
  61. msg('Cannot run ETH and ETC simultaneously, so skipping ETC')
  62. ids.remove('etc')
  63. for network_id in ids:
  64. network_id = network_id.lower()
  65. if opt.regtest_user:
  66. rt = MMGenRegtest(network_id)
  67. rt.init_daemon(opt.regtest_user)
  68. d = rt.d
  69. else:
  70. d = CoinDaemon(network_id,test_suite=True,flags=['no_daemonize'] if opt.no_daemonize else None)
  71. d.debug = opt.debug
  72. d.wait = not opt.no_wait
  73. if opt.get_state:
  74. print('{} {} (port {}) is {}'.format(d.net_desc,d.desc,d.rpc_port,d.state))
  75. elif opt.testing:
  76. print(' '.join(getattr(d,action+'_cmd')))
  77. else:
  78. d.cmd(action)