globalvars.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2016 Philemon <mmgen-py@yandex.com>
  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. globalvars.py: Constants and configuration options for the MMGen suite
  20. """
  21. import sys,os
  22. from mmgen.obj import BTCAmt
  23. # Global vars are set to dfl values in class g.
  24. # They're overridden in this order:
  25. # 1 - config file
  26. # 2 - environmental vars
  27. # 3 - command line
  28. class g(object):
  29. def die(ev=0,s=''):
  30. if s: sys.stderr.write(s+'\n')
  31. sys.exit(ev)
  32. # Variables - these might be altered at runtime:
  33. version = '0.9.0'
  34. release_date = 'December 2016'
  35. proj_name = 'MMGen'
  36. proj_url = 'https://github.com/mmgen/mmgen'
  37. prog_name = os.path.basename(sys.argv[0])
  38. author = 'Philemon'
  39. email = '<mmgen@tuta.io>'
  40. Cdates = '2013-2016'
  41. user_entropy = ''
  42. hash_preset = '3'
  43. usr_randchars = 30
  44. tx_fee = BTCAmt('0.0003')
  45. tx_fee_adj = 1.0
  46. tx_confs = 3
  47. seed_len = 256
  48. http_timeout = 60
  49. # Constants - some of these might be overriden, but they don't change thereafter
  50. debug = False
  51. quiet = False
  52. no_license = False
  53. hold_protect = True
  54. color = (False,True)[sys.stdout.isatty()]
  55. force_256_color = False
  56. testnet = False
  57. rpc_host = ''
  58. rpc_port = 0
  59. rpc_user = ''
  60. rpc_password = ''
  61. testnet_name = 'testnet3'
  62. bogus_wallet_data = '' # for debugging, used by test suite
  63. for k in ('win','linux'):
  64. if sys.platform[:len(k)] == k:
  65. platform = k; break
  66. else:
  67. die(1,"'%s': platform not supported by %s\n" % (sys.platform,proj_name))
  68. if os.getenv('HOME'): # Linux or MSYS
  69. home_dir = os.getenv('HOME')
  70. elif platform == 'win': # Windows native:
  71. die(1,'$HOME not set! {} for Windows must be run in MSYS environment'.format(proj_name))
  72. else:
  73. die(2,'$HOME is not set! Unable to determine home directory')
  74. data_dir_root,data_dir,cfg_file = None,None,None
  75. bitcoin_data_dir = os.path.join(os.getenv('APPDATA'),'Bitcoin') if platform == 'win' \
  76. else os.path.join(home_dir,'.bitcoin')
  77. # User opt sets global var:
  78. common_opts = (
  79. 'color','no_license','rpc_host','rpc_port','testnet','rpc_user','rpc_password',
  80. 'bitcoin_data_dir','force_256_color'
  81. )
  82. required_opts = (
  83. 'quiet','verbose','debug','outdir','echo_passphrase','passwd_file','stdout',
  84. 'show_hash_presets','label','keep_passphrase','keep_hash_preset',
  85. 'brain_params','b16','usr_randchars'
  86. )
  87. incompatible_opts = (
  88. ('quiet','verbose'),
  89. ('label','keep_label'),
  90. ('tx_id','info'),
  91. ('tx_id','terse_info'),
  92. ('batch','rescan')
  93. )
  94. cfg_file_opts = (
  95. 'color','debug','hash_preset','http_timeout','no_license','rpc_host','rpc_port',
  96. 'quiet','tx_fee','tx_fee_adj','usr_randchars','testnet','rpc_user','rpc_password',
  97. 'bitcoin_data_dir','force_256_color'
  98. )
  99. env_opts = (
  100. 'MMGEN_BOGUS_WALLET_DATA',
  101. 'MMGEN_DEBUG',
  102. 'MMGEN_QUIET',
  103. 'MMGEN_DISABLE_COLOR',
  104. 'MMGEN_FORCE_256_COLOR',
  105. 'MMGEN_DISABLE_HOLD_PROTECT',
  106. 'MMGEN_MIN_URANDCHARS',
  107. 'MMGEN_NO_LICENSE',
  108. 'MMGEN_RPC_HOST',
  109. 'MMGEN_TESTNET'
  110. )
  111. min_screen_width = 80
  112. minconf = 1
  113. # Global var sets user opt:
  114. global_sets_opt = ['minconf','seed_len','hash_preset','usr_randchars','debug',
  115. 'quiet','tx_confs','tx_fee_adj','tx_fee','key_generator']
  116. keyconv_exec = 'keyconv'
  117. mins_per_block = 9
  118. passwd_max_tries = 5
  119. max_urandchars = 80
  120. min_urandchars = 10
  121. seed_lens = 128,192,256
  122. mn_lens = [i / 32 * 3 for i in seed_lens]
  123. mmenc_ext = 'mmenc'
  124. salt_len = 16
  125. aesctr_iv_len = 16
  126. hincog_chk_len = 8
  127. key_generators = 'python-ecdsa','keyconv','secp256k1' # 1,2,3
  128. key_generator = 3 # secp256k1 is default
  129. hash_presets = {
  130. # Scrypt params:
  131. # ID N p r
  132. # N is a power of two
  133. '1': [12, 8, 1],
  134. '2': [13, 8, 4],
  135. '3': [14, 8, 8],
  136. '4': [15, 8, 12],
  137. '5': [16, 8, 16],
  138. '6': [17, 8, 20],
  139. '7': [18, 8, 24],
  140. }