main_regtest.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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': 'Coin daemon regression test mode setup and operations for the {} suite'.format(g.proj_name),
  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. stop - stop the regtest coin daemon
  40. bob - switch to Bob's wallet, starting daemon if necessary
  41. alice - switch to Alice's wallet, starting daemon if necessary
  42. miner - switch to Miner's wallet, starting daemon if necessary
  43. user - show current user
  44. generate N - mine N blocks (defaults to 1)
  45. send ADDR AMT - send amount AMT of miner funds to address ADDR
  46. state - show current state of daemon (ready, busy, or stopped)
  47. balances - get Bob and Alice's balances
  48. mempool - show transaction IDs in mempool
  49. cli - execute an RPC call with supplied arguments
  50. """
  51. }
  52. }
  53. cmd_args = opts.init(opts_data)
  54. from .regtest import MMGenRegtest
  55. def check_num_args():
  56. m = getattr(MMGenRegtest,cmd_args[0])
  57. margs = m.__code__.co_varnames[1:m.__code__.co_argcount]
  58. mdfls = m.__defaults__ or ()
  59. amin = len(margs) - len(mdfls)
  60. amax = len(margs)
  61. args = cmd_args[1:]
  62. m = "{}: too {} arguments for command '%s' (must have no {} than {})" % cmd_args[0]
  63. if len(args) < amin:
  64. die(1,m.format(args,'few','less',amin))
  65. elif len(cmd_args[1:]) > amax:
  66. die(1,m.format(args,'many','more',amax))
  67. if not cmd_args:
  68. opts.usage()
  69. elif cmd_args[0] not in MMGenRegtest.usr_cmds:
  70. die(1,'{!r}: invalid command'.format(cmd_args[0]))
  71. elif cmd_args[0] not in ('cli','balances'):
  72. check_num_args()
  73. MMGenRegtest(g.coin).cmd(cmd_args)