help_notes.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. help: help notes functions for MMGen suite commands
  12. """
  13. class help_notes:
  14. def __init__(self, proto, cfg):
  15. self.proto = proto
  16. self.cfg = cfg
  17. def txcreate_args(self):
  18. return (
  19. '[ADDR,AMT ... | DATA_SPEC] ADDR'
  20. if self.proto.base_proto == 'Bitcoin' else
  21. 'ADDR,AMT')
  22. def swaptxcreate_args(self):
  23. return 'COIN1 [AMT CHG_ADDR] COIN2 [ADDR]'
  24. def account_info_desc(self):
  25. return 'unspent outputs' if self.proto.base_proto == 'Bitcoin' else 'account info'
  26. def fee_spec_letters(self, *, use_quotes=False, proto=None):
  27. cu = (proto or self.proto).coin_amt.units
  28. pfx, sfx, sep, conj = (('', '', ',', ' or '), ("‘", "’", "’,‘", "’ or ‘"))[use_quotes]
  29. return pfx + sep.join(u[0] for u in cu[:-1]) + ('', conj)[len(cu)>1] + cu[-1][0] + sfx
  30. def stream_interval(self):
  31. from ..tx.new_swap import get_swap_proto_mod
  32. return get_swap_proto_mod(self.cfg.swap_proto).SwapCfg(self.cfg).si.dfl
  33. def fee_spec_names(self, *, proto=None, linebreak=' '):
  34. cu = (proto or self.proto).coin_amt.units
  35. return (
  36. ', '.join(cu[:-1])
  37. + ('', ' and ')[len(cu)>1]
  38. + cu[-1]
  39. + (f',{linebreak}respectively' if len(cu) > 1 else ''))
  40. def dfl_twname(self):
  41. from ..proto.btc.rpc.local import BitcoinRPCClient
  42. return BitcoinRPCClient.dfl_twname
  43. def MasterShareIdx(self):
  44. from ..seedsplit import MasterShareIdx
  45. return MasterShareIdx
  46. def tool_help(self):
  47. from ..tool.help import main_help
  48. return main_help()
  49. def dfl_subseeds(self):
  50. from ..subseed import SubSeedList
  51. return str(SubSeedList.dfl_len)
  52. def dfl_seed_len(self):
  53. from ..seed import Seed
  54. return str(Seed.dfl_len)
  55. def password_formats(self):
  56. from ..passwdlist import PasswordList
  57. pwi_fs = '{:8} {:1} {:26} {:<7} {:<7} {}'
  58. return '\n '.join(
  59. [pwi_fs.format('Code', '', 'Description', 'Min Len', 'Max Len', 'Default Len')] +
  60. [pwi_fs.format(k, '-', v.desc, v.min_len, v.max_len, v.dfl_len)
  61. for k, v in PasswordList.pw_info.items()]
  62. )
  63. def dfl_mmtype(self):
  64. from ..addr import MMGenAddrType
  65. return "'{}' or '{}'".format(self.proto.dfl_mmtype, MMGenAddrType.mmtypes[self.proto.dfl_mmtype].name)
  66. def address_types(self):
  67. from ..addr import MMGenAddrType
  68. return """
  69. ADDRESS TYPES:
  70. Code Type Description
  71. ---- ---- -----------
  72. """ + format('\n '.join(['‘{}’ {:<12} - {}'.format(k, v.name, v.desc)
  73. for k, v in MMGenAddrType.mmtypes.items()]))
  74. def fmt_codes(self):
  75. from ..wallet import format_fmt_codes
  76. return """
  77. FMT CODES:
  78. """ + '\n '.join(format_fmt_codes().splitlines())
  79. def coin_id(self):
  80. return self.proto.coin_id
  81. def keygen_backends(self):
  82. from ..keygen import get_backends
  83. from ..addr import MMGenAddrType
  84. backends = get_backends(
  85. MMGenAddrType(self.proto, self.cfg.type or self.proto.dfl_mmtype).pubkey_type
  86. )
  87. return ' '.join('{n}:{k}{t}'.format(n=n, k=k, t=('', ' [default]')[n == 1])
  88. for n, k in enumerate(backends, 1))
  89. def coin_daemon_network_ids(self):
  90. from ..daemon import CoinDaemon
  91. from ..util import fmt_list
  92. return fmt_list(CoinDaemon.get_network_ids(self.cfg), fmt='bare')
  93. def tx_proxies(self):
  94. from ..util import fmt_list
  95. return fmt_list(self.cfg._autoset_opts['tx_proxy'].choices, fmt='fancy')
  96. def rel_fee_desc(self):
  97. from ..tx import BaseTX
  98. return BaseTX(cfg=self.cfg, proto=self.proto).rel_fee_desc
  99. def gas_limit(self, target):
  100. return """
  101. GAS LIMIT
  102. This option specifies the maximum gas allowance for an Ethereum transaction.
  103. It’s generally of interest only for token transactions or swap transactions
  104. from token assets.
  105. Parameter must be an integer or one of the special values ‘fallback’ (for a
  106. locally computed sane default) or ‘auto’ (for gas estimate via an RPC call,
  107. in the case of a token transaction, or locally computed default, in the case
  108. of a standard transaction). The default is ‘auto’.
  109. """ if target == 'swaptx' or self.proto.base_coin == 'ETH' else ''
  110. def fee(self, all_coins=False):
  111. from ..tx import BaseTX
  112. text = """
  113. FEE SPECIFICATION
  114. Transaction fees, both on the command line and at the interactive prompt, may
  115. be specified as either absolute coin amounts, using a plain decimal number, or
  116. as {r}, using an integer followed by {l}, for{s}{u}""".format(
  117. r = BaseTX(cfg=self.cfg, proto=self.proto).rel_fee_desc,
  118. l = self.fee_spec_letters(use_quotes=True),
  119. s = '\n' if self.proto.base_coin == 'ETH' else ' ',
  120. u = self.fee_spec_names())
  121. if all_coins:
  122. from ..protocol import init_proto
  123. eth_proto = init_proto(self.cfg, 'eth', need_amt=True)
  124. return text + (
  125. ' (for\nBitcoin, Litecoin and Bitcoin Cash)'
  126. + ", or {r}, using an integer followed\nby {l}, for {u}".format(
  127. r = BaseTX(cfg=self.cfg, proto=eth_proto).rel_fee_desc,
  128. l = self.fee_spec_letters(use_quotes=True, proto=eth_proto),
  129. u = self.fee_spec_names(proto=eth_proto, linebreak='\n'))
  130. + ' (for Ethereum)')
  131. else:
  132. return text + '.'
  133. def passwd(self):
  134. return """
  135. PASSPHRASE NOTE:
  136. For passphrases all combinations of whitespace are equal, and leading and
  137. trailing space are ignored. This permits reading passphrase or brainwallet
  138. data from a multi-line file with free spacing and indentation.
  139. """.strip()
  140. def brainwallet(self):
  141. return """
  142. BRAINWALLET NOTE:
  143. To thwart dictionary attacks, it’s recommended to use a strong hash preset
  144. with brainwallets. For a brainwallet passphrase to generate the correct
  145. seed, the same seed length and hash preset parameters must always be used.
  146. """.strip()