globalvars.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2017 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. skip_segwit_active_check = bool(os.getenv('MMGEN_TEST_SUITE'))
  30. def die(ev=0,s=''):
  31. if s: sys.stderr.write(s+'\n')
  32. sys.exit(ev)
  33. # Variables - these might be altered at runtime:
  34. version = '0.9.399'
  35. release_date = 'October 2017'
  36. proj_name = 'MMGen'
  37. proj_url = 'https://github.com/mmgen/mmgen'
  38. prog_name = os.path.basename(sys.argv[0])
  39. author = 'Philemon'
  40. email = '<mmgen@tuta.io>'
  41. Cdates = '2013-2017'
  42. keywords = 'Bitcoin, cryptocurrency, wallet, cold storage, offline, online, spending, open-source, command-line, Python, Linux, Bitcoin Core, bitcoind, hd, deterministic, hierarchical, secure, anonymous, Electrum, seed, mnemonic, brainwallet, Scrypt, utility, script, scriptable, blockchain, raw, transaction, permissionless, console, terminal, curses, ansi, color, tmux, remote, client, daemon, RPC, json, entropy, xterm, rxvt, PowerShell, MSYS, MinGW, mswin, Armbian, Raspbian, Raspberry Pi, Orange Pi'
  43. coin = 'BTC'
  44. coins = 'BTC','BCH'
  45. user_entropy = ''
  46. hash_preset = '3'
  47. usr_randchars = 30
  48. stdin_tty = bool(sys.stdin.isatty() or os.getenv('MMGEN_TEST_SUITE'))
  49. max_tx_fee = BTCAmt('0.01')
  50. tx_fee_adj = 1.0
  51. tx_confs = 3
  52. satoshi = BTCAmt('0.00000001') # One bitcoin equals 100,000,000 satoshis
  53. seed_len = 256
  54. http_timeout = 60
  55. max_int = 0xffffffff
  56. # Constants - some of these might be overriden in opts.py, but they don't change thereafter
  57. debug = False
  58. quiet = False
  59. no_license = False
  60. hold_protect = True
  61. color = (False,True)[sys.stdout.isatty()]
  62. force_256_color = False
  63. testnet = False
  64. regtest = False
  65. chain = None # set by first call to rpc_connection()
  66. chains = 'mainnet','testnet','regtest'
  67. bitcoind_version = None # set by first call to rpc_connection()
  68. rpc_host = ''
  69. rpc_port = 0
  70. rpc_user = ''
  71. rpc_password = ''
  72. bob = False
  73. alice = False
  74. # test suite:
  75. bogus_wallet_data = ''
  76. traceback_cmd = 'scripts/traceback.py'
  77. for k in ('win','linux'):
  78. if sys.platform[:len(k)] == k:
  79. platform = k; break
  80. else:
  81. die(1,"'%s': platform not supported by %s\n" % (sys.platform,proj_name))
  82. if os.getenv('HOME'): # Linux or MSYS
  83. home_dir = os.getenv('HOME')
  84. elif platform == 'win': # Windows native:
  85. die(1,'$HOME not set! {} for Windows must be run in MSYS environment'.format(proj_name))
  86. else:
  87. die(2,'$HOME is not set! Unable to determine home directory')
  88. data_dir_root,data_dir,cfg_file = None,None,None
  89. daemon_data_dir = '' # set by user or protocol
  90. # User opt sets global var:
  91. common_opts = (
  92. 'color','no_license','rpc_host','rpc_port','testnet','rpc_user','rpc_password',
  93. 'daemon_data_dir','force_256_color','regtest','coin','bob','alice'
  94. )
  95. required_opts = (
  96. 'quiet','verbose','debug','outdir','echo_passphrase','passwd_file','stdout',
  97. 'show_hash_presets','label','keep_passphrase','keep_hash_preset','yes',
  98. 'brain_params','b16','usr_randchars','coin','bob','alice','key_generator'
  99. )
  100. incompatible_opts = (
  101. ('bob','alice'),
  102. ('quiet','verbose'),
  103. ('label','keep_label'),
  104. ('tx_id','info'),
  105. ('tx_id','terse_info'),
  106. ('batch','rescan') # still incompatible as of Core 0.15.0
  107. )
  108. cfg_file_opts = (
  109. 'color','debug','hash_preset','http_timeout','no_license','rpc_host','rpc_port',
  110. 'quiet','tx_fee_adj','usr_randchars','testnet','rpc_user','rpc_password',
  111. 'daemon_data_dir','force_256_color','max_tx_fee','regtest'
  112. )
  113. env_opts = (
  114. 'MMGEN_BOGUS_WALLET_DATA',
  115. 'MMGEN_DEBUG',
  116. 'MMGEN_QUIET',
  117. 'MMGEN_DISABLE_COLOR',
  118. 'MMGEN_FORCE_256_COLOR',
  119. 'MMGEN_DISABLE_HOLD_PROTECT',
  120. 'MMGEN_MIN_URANDCHARS',
  121. 'MMGEN_NO_LICENSE',
  122. 'MMGEN_RPC_HOST',
  123. 'MMGEN_TESTNET'
  124. 'MMGEN_REGTEST'
  125. )
  126. min_screen_width = 80
  127. minconf = 1
  128. # Global var sets user opt:
  129. global_sets_opt = ['minconf','seed_len','hash_preset','usr_randchars','debug',
  130. 'quiet','tx_confs','tx_fee_adj','key_generator']
  131. mins_per_block = 9
  132. passwd_max_tries = 5
  133. max_urandchars = 80
  134. min_urandchars = 10
  135. seed_lens = 128,192,256
  136. mmenc_ext = 'mmenc'
  137. salt_len = 16
  138. aesctr_iv_len = 16
  139. hincog_chk_len = 8
  140. key_generators = 'python-ecdsa','secp256k1' # '1','2'
  141. key_generator = 2 # secp256k1 is default
  142. hash_presets = {
  143. # Scrypt params:
  144. # ID N p r
  145. # N is a power of two
  146. '1': [12, 8, 1],
  147. '2': [13, 8, 4],
  148. '3': [14, 8, 8],
  149. '4': [15, 8, 12],
  150. '5': [16, 8, 16],
  151. '6': [17, 8, 20],
  152. '7': [18, 8, 24],
  153. }