start-coin-daemons.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. action = g.prog_name.split('-')[0]
  7. opts_data = {
  8. 'sets': [('debug',True,'verbose',True)],
  9. 'text': {
  10. 'desc': '{} coin daemons for the MMGen test suite'.format(action.capitalize()),
  11. 'usage':'[opts] <network IDs>',
  12. 'options': """
  13. -h, --help Print this help message
  14. --, --longhelp Print help message for long options (common options)
  15. -D, --debug Produce debugging output (implies --verbose)
  16. -d, --datadir= Override the default datadir
  17. -n, --no-daemonize Don't fork daemon to background
  18. -p, --port-shift= Shift the RPC port by this number
  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. """
  27. },
  28. 'code': {
  29. 'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name),
  30. 'notes': lambda s: s.format(nid=', '.join(CoinDaemon.network_ids))
  31. }
  32. }
  33. cmd_args = opts.init(opts_data)
  34. if 'all' in cmd_args or 'no_xmr' in cmd_args:
  35. if len(cmd_args) != 1:
  36. die(1,"'all' or 'no_xmr' must be the sole argument")
  37. else:
  38. ids = list(CoinDaemon.network_ids)
  39. if cmd_args[0] == 'no_xmr':
  40. ids.remove('xmr')
  41. else:
  42. ids = cmd_args
  43. if not ids:
  44. opts.usage()
  45. for i in ids:
  46. if i not in CoinDaemon.network_ids:
  47. die(1,f'{i!r}: invalid network ID')
  48. if 'eth' in ids and 'etc' in ids:
  49. msg('Cannot run ETH and ETC simultaneously, so skipping ETC')
  50. ids.remove('etc')
  51. for network_id in ids:
  52. network_id = network_id.lower()
  53. d = CoinDaemon(
  54. network_id,
  55. test_suite = True,
  56. opts = ['no_daemonize'] if opt.no_daemonize else None,
  57. port_shift = int(opt.port_shift or 0),
  58. datadir = opt.datadir )
  59. d.debug = opt.debug
  60. d.wait = not opt.no_wait
  61. if opt.get_state:
  62. print('{} {} (port {}) is {}'.format(d.net_desc,d.desc,d.rpc_port,d.state))
  63. elif opt.testing:
  64. print(' '.join(getattr(d,action+'_cmd')))
  65. else:
  66. d.cmd(action)