common.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  5. # Copyright (C)2013-2018 The MMGen Project <mmgen@tuta.io>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. """
  20. common.py: Common imports for all MMGen scripts
  21. """
  22. import sys,os
  23. from mmgen.globalvars import g
  24. import mmgen.opts as opts
  25. from mmgen.opts import opt
  26. from mmgen.util import *
  27. def set_debug_all():
  28. if os.getenv('MMGEN_DEBUG_ALL'):
  29. for name in g.env_opts:
  30. if name[:11] == 'MMGEN_DEBUG':
  31. os.environ[name] = '1'
  32. def help_notes(k):
  33. from mmgen.seed import SeedSource
  34. from mmgen.tx import MMGenTX
  35. def fee_spec_letters(use_quotes=False):
  36. cu = g.proto.coin_amt.units
  37. sep,conj = ((',',' or '),("','","' or '"))[use_quotes]
  38. return sep.join(u[0] for u in cu[:-1]) + ('',conj)[len(cu)>1] + cu[-1][0]
  39. def fee_spec_names():
  40. cu = g.proto.coin_amt.units
  41. return ', '.join(cu[:-1]) + ('',' and ')[len(cu)>1] + cu[-1] + ('',',\nrespectively')[len(cu)>1]
  42. return {
  43. 'rel_fee_desc': MMGenTX().rel_fee_desc,
  44. 'fee_spec_letters': fee_spec_letters(),
  45. 'passwd': """
  46. For passphrases all combinations of whitespace are equal and leading and
  47. trailing space is ignored. This permits reading passphrase or brainwallet
  48. data from a multi-line file with free spacing and indentation.
  49. """.strip(),
  50. 'brainwallet': """
  51. BRAINWALLET NOTE:
  52. To thwart dictionary attacks, it's recommended to use a strong hash preset
  53. with brainwallets. For a brainwallet passphrase to generate the correct
  54. seed, the same seed length and hash preset parameters must always be used.
  55. """.strip(),
  56. 'txcreate': """
  57. The transaction's outputs are specified on the command line, while its inputs
  58. are chosen from a list of the user's unpent outputs via an interactive menu.
  59. If the transaction fee is not specified on the command line (see FEE
  60. SPECIFICATION below), it will be calculated dynamically using network fee
  61. estimation for the default (or user-specified) number of confirmations.
  62. If network fee estimation fails, the user will be prompted for a fee.
  63. Network-estimated fees will be multiplied by the value of '--tx-fee-adj',
  64. if specified.
  65. Ages of transactions are approximate based on an average block discovery
  66. interval of one per {g.proto.secs_per_block} seconds.
  67. All addresses on the command line can be either {pnu} addresses or {pnm}
  68. addresses of the form <seed ID>:<index>.
  69. To send the value of all inputs (minus TX fee) to a single output, specify
  70. one address with no amount on the command line.
  71. """.format(g=g,pnm=g.proj_name,pnu=g.proto.name.capitalize()),
  72. 'fee': """
  73. FEE SPECIFICATION: Transaction fees, both on the command line and at the
  74. interactive prompt, may be specified as either absolute {c} amounts, using
  75. a plain decimal number, or as {r}, using an integer followed by
  76. '{l}', for {u}.
  77. """.format( c=g.coin,
  78. r=MMGenTX().rel_fee_desc,
  79. l=fee_spec_letters(use_quotes=True),
  80. u=fee_spec_names() ),
  81. 'txsign': u"""
  82. Transactions may contain both {pnm} or non-{pnm} input addresses.
  83. To sign non-{pnm} inputs, a {dn} wallet dump or flat key list is used
  84. as the key source ('--keys-from-file' option).
  85. To sign {pnm} inputs, key data is generated from a seed as with the
  86. {pnl}-addrgen and {pnl}-keygen commands. Alternatively, a key-address file
  87. may be used (--mmgen-keys-from-file option).
  88. Multiple wallets or other seed files can be listed on the command line in
  89. any order. If the seeds required to sign the transaction's inputs are not
  90. found in these files (or in the default wallet), the user will be prompted
  91. for seed data interactively.
  92. To prevent an attacker from crafting transactions with bogus {pnm}-to-{pnu}
  93. address mappings, all outputs to {pnm} addresses are verified with a seed
  94. source. Therefore, seed files or a key-address file for all {pnm} outputs
  95. must also be supplied on the command line if the data can't be found in the
  96. default wallet.
  97. Seed source files must have the canonical extensions listed in the 'FileExt'
  98. column below:
  99. {n_fmt}
  100. """.format( dn=g.proto.daemon_name,
  101. n_fmt='\n '.join(SeedSource.format_fmt_codes().splitlines()),
  102. pnm=g.proj_name,
  103. pnu=g.proto.name.capitalize(),
  104. pnl=g.proj_name.lower())
  105. }[k] + (u'-α' if g.debug_utf8 else '')