main_regtest.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2021 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. mmgen-regtest: Coin daemon regression test mode setup and operations for the MMGen
  20. suite
  21. """
  22. from .common import *
  23. opts_data = {
  24. 'sets': [('yes', True, 'quiet', True)],
  25. 'text': {
  26. 'desc': f'Coin daemon regression test mode setup and operations for the {g.proj_name} suite',
  27. 'usage': '[opts] <command>',
  28. 'options': """
  29. -h, --help Print this help message
  30. --, --longhelp Print help message for long options (common options)
  31. -e, --empty Don't fund Bob and Alice's wallets on setup
  32. -n, --setup-no-stop-daemon Don't stop daemon after setup is finished
  33. -q, --quiet Produce quieter output
  34. -v, --verbose Produce more verbose output
  35. """,
  36. 'notes': """
  37. AVAILABLE COMMANDS
  38. setup - set up Bob and Alice regtest mode
  39. start - start the regtest coin daemon
  40. stop - stop the regtest coin daemon
  41. generate N - mine N blocks (defaults to 1)
  42. send ADDR AMT - send amount AMT of miner funds to address ADDR
  43. state - show current state of daemon (ready, busy, or stopped)
  44. balances - get Bob and Alice's balances
  45. mempool - show transaction IDs in mempool
  46. cli - execute an RPC call with supplied arguments
  47. wallet_cli - execute a wallet RPC call with supplied arguments (wallet
  48. is first argument)
  49. """
  50. }
  51. }
  52. cmd_args = opts.init(opts_data)
  53. from .regtest import MMGenRegtest
  54. def check_num_args():
  55. m = getattr(MMGenRegtest,cmd_args[0])
  56. margs = m.__code__.co_varnames[1:m.__code__.co_argcount]
  57. mdfls = m.__defaults__ or ()
  58. amin = len(margs) - len(mdfls)
  59. amax = len(margs)
  60. args = cmd_args[1:]
  61. m = "{}: too {} arguments for command '%s' (must have no {} than {})" % cmd_args[0]
  62. if len(args) < amin:
  63. die(1,m.format(args,'few','less',amin))
  64. elif len(cmd_args[1:]) > amax:
  65. die(1,m.format(args,'many','more',amax))
  66. if not cmd_args:
  67. opts.usage()
  68. elif cmd_args[0] not in MMGenRegtest.usr_cmds:
  69. die(1,f'{cmd_args[0]!r}: invalid command')
  70. elif cmd_args[0] not in ('cli','wallet_cli','balances'):
  71. check_num_args()
  72. async def main():
  73. await MMGenRegtest(g.coin).cmd(cmd_args)
  74. run_session(main())