main_xmrwallet.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2024 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-xmrwallet: Perform various Monero wallet and transacting operations for
  20. addresses in an MMGen XMR key-address file
  21. """
  22. import asyncio
  23. from .cfg import gc,Config
  24. from .util import die
  25. from .xmrwallet import (
  26. MoneroWalletOps,
  27. xmrwallet_uarg_info,
  28. xmrwallet_uargs,
  29. )
  30. opts_data = {
  31. 'sets': [
  32. ('autosign',True,'watch_only',True),
  33. ('autosign_mountpoint',bool,'autosign',True),
  34. ('autosign_mountpoint',bool,'watch_only',True),
  35. ],
  36. 'text': {
  37. 'desc': """Perform various Monero wallet and transacting operations for
  38. addresses in an MMGen XMR key-address file""",
  39. 'usage2': [
  40. '[opts] create | sync | list | view | listview | dump | restore [xmr_keyaddrfile] [wallets]',
  41. '[opts] label [xmr_keyaddrfile] LABEL_SPEC',
  42. '[opts] new [xmr_keyaddrfile] NEW_ADDRESS_SPEC',
  43. '[opts] transfer [xmr_keyaddrfile] TRANSFER_SPEC',
  44. '[opts] sweep [xmr_keyaddrfile] SWEEP_SPEC',
  45. '[opts] submit [TX_file]',
  46. '[opts] relay <TX_file>',
  47. '[opts] resubmit | abort (for use with --autosign only)',
  48. '[opts] txview | txlist [TX_file] ...',
  49. '[opts] export-outputs | export-outputs-sign | import-key-images [wallets]',
  50. ],
  51. 'options': """
  52. -h, --help Print this help message
  53. --, --longhelp Print help message for long options (common
  54. options)
  55. -a, --autosign Use appropriate outdir and other params for
  56. autosigning operations (implies --watch-only).
  57. When this option is in effect, filename argu-
  58. ments must be omitted, as files are located
  59. automatically.
  60. -m, --autosign-mountpoint=P Specify the autosign mountpoint (defaults to
  61. ‘/mnt/mmgen_autosign’, implies --autosign)
  62. -b, --rescan-blockchain Rescan the blockchain if wallet fails to sync
  63. -d, --outdir=D Save transaction files to directory 'D'
  64. instead of the working directory
  65. -D, --daemon=H:P Connect to the monerod at {D}
  66. -k, --use-internal-keccak-module Force use of the internal keccak module
  67. -p, --hash-preset=P Use scrypt hash preset 'P' for password
  68. hashing (default: '{gc.dfl_hash_preset}')
  69. -R, --tx-relay-daemon=H:P[:H:P] Relay transactions via a monerod specified by
  70. {R}
  71. -r, --restore-height=H Scan from height 'H' when creating wallets.
  72. Use special value ‘current’ to create empty
  73. wallet at current blockchain height.
  74. -R, --no-relay Save transaction to file instead of relaying
  75. -s, --no-start-wallet-daemon Don’t start the wallet daemon at startup
  76. -S, --no-stop-wallet-daemon Don’t stop the wallet daemon at exit
  77. -W, --watch-only Create or operate on watch-only wallets
  78. -w, --wallet-dir=D Output or operate on wallets in directory 'D'
  79. instead of the working directory
  80. -U, --wallet-rpc-user=user Wallet RPC username (currently: {cfg.monero_wallet_rpc_user!r})
  81. -P, --wallet-rpc-password=pass Wallet RPC password (currently: [scrubbed])
  82. """,
  83. 'notes': """
  84. {xmrwallet_help}
  85. """
  86. },
  87. 'code': {
  88. 'options': lambda cfg,s: s.format(
  89. D=xmrwallet_uarg_info['daemon'].annot,
  90. R=xmrwallet_uarg_info['tx_relay_daemon'].annot,
  91. cfg=cfg,
  92. gc=gc,
  93. ),
  94. 'notes': lambda help_mod,s: s.format(
  95. xmrwallet_help = help_mod('xmrwallet')
  96. )
  97. }
  98. }
  99. cfg = Config(opts_data=opts_data)
  100. cmd_args = cfg._args
  101. if cmd_args and cfg.autosign and (
  102. cmd_args[0] in (
  103. MoneroWalletOps.kafile_arg_ops
  104. + ('export-outputs', 'export-outputs-sign', 'import-key-images', 'txview', 'txlist')
  105. )
  106. or len(cmd_args) == 1 and cmd_args[0] in ('submit', 'resubmit', 'abort')
  107. ):
  108. cmd_args.insert(1,None)
  109. if len(cmd_args) < 2:
  110. cfg._opts.usage()
  111. op = cmd_args.pop(0)
  112. infile = cmd_args.pop(0)
  113. wallets = spec = None
  114. if op in ('relay', 'submit', 'resubmit', 'abort'):
  115. if len(cmd_args) != 0:
  116. cfg._opts.usage()
  117. elif op in ('txview','txlist'):
  118. infile = [infile] + cmd_args
  119. elif op in ('create','sync','list','view','listview','dump','restore'): # kafile_arg_ops
  120. if len(cmd_args) > 1:
  121. cfg._opts.usage()
  122. wallets = cmd_args.pop(0) if cmd_args else None
  123. elif op in ('new','transfer','sweep','label'):
  124. if len(cmd_args) != 1:
  125. cfg._opts.usage()
  126. spec = cmd_args[0]
  127. elif op in ('export-outputs', 'export-outputs-sign', 'import-key-images'):
  128. if not cfg.autosign: # --autosign only for now - TODO
  129. die(f'--autosign must be used with command {op!r}')
  130. if len(cmd_args) > 1:
  131. cfg._opts.usage()
  132. wallets = cmd_args.pop(0) if cmd_args else None
  133. else:
  134. die(1,f'{op!r}: unrecognized operation')
  135. op_cls = getattr(MoneroWalletOps,op.replace('-','_'))
  136. m = op_cls(cfg, xmrwallet_uargs(infile, wallets, spec))
  137. if asyncio.run(m.main()):
  138. m.post_main_success()
  139. else:
  140. m.post_main_failure()