main_xmrwallet.py 6.3 KB

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