__init__.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. xmrwallet.__init__: Monero wallet ops for the MMGen Suite
  12. """
  13. import re, importlib
  14. from collections import namedtuple
  15. from ..proto.btc.common import b58a
  16. from ..util import capfirst
  17. tx_priorities = {
  18. 1: 'low',
  19. 2: 'normal',
  20. 3: 'high',
  21. 4: 'highest'
  22. }
  23. uargs = namedtuple('xmrwallet_uargs', [
  24. 'infile',
  25. 'wallets',
  26. 'spec',
  27. ])
  28. uarg_info = (
  29. lambda e, hp: {
  30. 'daemon': e('HOST:PORT', hp),
  31. 'tx_relay_daemon': e('HOST:PORT[:PROXY_IP:PROXY_PORT]', rf'({hp})(?::({hp}))?'),
  32. 'newaddr_spec': e('WALLET[:ACCOUNT][,"label text"]', r'(\d+)(?::(\d+))?(?:,(.*))?'),
  33. 'transfer_spec': e('SOURCE:ACCOUNT:ADDRESS,AMOUNT', rf'(\d+):(\d+):([{b58a}]+),([0-9.]+)'),
  34. 'sweep_spec': e('SOURCE:ACCOUNT[,DEST[:ACCOUNT]]', r'(\d+):(\d+)(?:,(\d+)(?::(\d+))?)?'),
  35. 'label_spec': e('WALLET:ACCOUNT:ADDRESS,"label text"', r'(\d+):(\d+):(\d+),(.*)'),
  36. })(
  37. namedtuple('uarg_info_entry', ['annot','pat']),
  38. r'(?:[^:]+):(?:\d+)')
  39. # canonical op names mapped to their respective modules:
  40. op_names = {
  41. 'create': 'create',
  42. 'create_offline': 'create',
  43. 'sync': 'sync',
  44. 'list': 'view',
  45. 'view': 'view',
  46. 'listview': 'view',
  47. 'new': 'new',
  48. 'transfer': 'sweep',
  49. 'sweep': 'sweep',
  50. 'sweep_all': 'sweep',
  51. 'relay': 'relay',
  52. 'txview': 'txview',
  53. 'txlist': 'txview',
  54. 'label': 'label',
  55. 'sign': 'sign',
  56. 'submit': 'submit',
  57. 'resubmit': 'submit',
  58. 'abort': 'submit',
  59. 'dump': 'dump',
  60. 'restore': 'restore',
  61. 'export_outputs': 'export',
  62. 'export_outputs_sign': 'export',
  63. 'import_outputs': 'import',
  64. 'import_key_images': 'import',
  65. 'wallet': 'wallet', # virtual class
  66. }
  67. kafile_arg_ops = (
  68. 'create',
  69. 'sync',
  70. 'list',
  71. 'view',
  72. 'listview',
  73. 'label',
  74. 'new',
  75. 'transfer',
  76. 'sweep',
  77. 'sweep_all',
  78. 'dump',
  79. 'restore')
  80. opts = (
  81. 'wallet_dir',
  82. 'daemon',
  83. 'tx_relay_daemon',
  84. 'use_internal_keccak_module',
  85. 'hash_preset',
  86. 'restore_height',
  87. 'no_start_wallet_daemon',
  88. 'no_stop_wallet_daemon',
  89. 'no_relay',
  90. 'watch_only',
  91. 'autosign',
  92. 'skip_empty_accounts',
  93. 'skip_empty_addresses')
  94. pat_opts = ('daemon', 'tx_relay_daemon')
  95. def op_cls(op_name):
  96. def upper(m):
  97. return m[1].upper()
  98. clsname = 'Op' + capfirst(re.sub(r'_(.)', upper, op_name))
  99. cls = getattr(importlib.import_module(f'.ops.{op_names[op_name]}', 'mmgen.xmrwallet'), clsname)
  100. cls.name = op_name
  101. return cls
  102. def op(op, cfg, infile, wallets, *, spec=None):
  103. return op_cls(op.replace('-', '_'))(cfg, uargs(infile, wallets, spec))