globalvars.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 The MMGen Project <mmgen@tuta.io>
  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. # Global vars are set to dfl values in class g.
  23. # They're overridden in this order:
  24. # 1 - config file
  25. # 2 - environmental vars
  26. # 3 - command line
  27. class g(object):
  28. def die(ev=0,s=''):
  29. if s: sys.stderr.write(s+'\n')
  30. sys.exit(ev)
  31. # Constants:
  32. version = '0.10.099'
  33. release_date = 'February 2019'
  34. proj_name = 'MMGen'
  35. proj_url = 'https://github.com/mmgen/mmgen'
  36. prog_name = os.path.basename(sys.argv[0])
  37. author = 'The MMGen Project'
  38. email = '<mmgen@tuta.io>'
  39. Cdates = '2013-2019'
  40. keywords = 'Bitcoin, BTC, 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, BCash, BCH, Litecoin, LTC, altcoin, ZEC, Zcash, DASH, Dashpay, ETH, Ethereum, Classic, SHA256Compress, XMR, Monero, monerod, EMC, Emercoin, ERC20, token, deploy, contract, gas, fee, smart contract, solidity, Parity, testnet, devmode, Kovan'
  41. max_int = 0xffffffff
  42. stdin_tty = bool(sys.stdin.isatty() or os.getenv('MMGEN_TEST_SUITE_POPEN_SPAWN'))
  43. stdout_fileno = sys.stdout.fileno()
  44. stderr_fileno = sys.stderr.fileno()
  45. http_timeout = 60
  46. # Variables - these might be altered at runtime:
  47. user_entropy = ''
  48. hash_preset = '3'
  49. usr_randchars = 30
  50. tx_fee_adj = 1.0
  51. tx_confs = 3
  52. seed_len = 256
  53. # Constant vars - some of these might be overriden in opts.py, but they don't change thereafter
  54. coin = 'BTC'
  55. dcoin = None # the display coin unit
  56. token = ''
  57. debug = False
  58. debug_opts = False
  59. debug_rpc = False
  60. debug_addrlist = False
  61. quiet = False
  62. no_license = False
  63. color = (False,True)[sys.stdout.isatty()]
  64. force_256_color = False
  65. testnet = False
  66. regtest = False
  67. accept_defaults = False
  68. chain = None # set by first call to rpc_init()
  69. chains = 'mainnet','testnet','regtest'
  70. rpc_host = ''
  71. rpc_port = 0
  72. rpc_user = ''
  73. rpc_password = ''
  74. rpc_fail_on_command = ''
  75. rpch = None # global RPC handle
  76. bob = False
  77. alice = False
  78. # test suite:
  79. bogus_wallet_data = ''
  80. bogus_send = False
  81. debug_utf8 = False
  82. traceback = False
  83. test_suite = False
  84. for k in ('win','linux'):
  85. if sys.platform[:len(k)] == k:
  86. platform = k; break
  87. else:
  88. die(1,"'{}': platform not supported by {}\n".format(sys.platform,proj_name))
  89. if os.getenv('HOME'): # Linux or MSYS
  90. home_dir = os.getenv('HOME')
  91. elif platform == 'win': # Windows native:
  92. die(1,'$HOME not set! {} for Windows must be run in MSYS environment'.format(proj_name))
  93. else:
  94. die(2,'$HOME is not set! Unable to determine home directory')
  95. data_dir_root,data_dir,cfg_file = None,None,None
  96. daemon_data_dir = '' # set by user or protocol
  97. # User opt sets global var:
  98. common_opts = (
  99. 'color','no_license','rpc_host','rpc_port','testnet','rpc_user','rpc_password',
  100. 'daemon_data_dir','force_256_color','regtest','coin','bob','alice',
  101. 'accept_defaults','token'
  102. )
  103. required_opts = (
  104. 'quiet','verbose','debug','outdir','echo_passphrase','passwd_file','stdout',
  105. 'show_hash_presets','label','keep_passphrase','keep_hash_preset','yes',
  106. 'brain_params','b16','usr_randchars','coin','bob','alice','key_generator',
  107. 'hidden_incog_input_params','in_fmt'
  108. )
  109. incompatible_opts = (
  110. ('base32','hex'), # mmgen-passgen
  111. ('bob','alice'),
  112. ('quiet','verbose'),
  113. ('label','keep_label'),
  114. ('tx_id','info'),
  115. ('tx_id','terse_info'),
  116. ('batch','rescan') # still incompatible as of Core 0.15.0
  117. )
  118. cfg_file_opts = (
  119. 'color','debug','hash_preset','http_timeout','no_license','rpc_host','rpc_port',
  120. 'quiet','tx_fee_adj','usr_randchars','testnet','rpc_user','rpc_password',
  121. 'daemon_data_dir','force_256_color','regtest',
  122. 'btc_max_tx_fee','ltc_max_tx_fee','bch_max_tx_fee','eth_max_tx_fee',
  123. 'eth_mainnet_chain_name','eth_testnet_chain_name',
  124. 'max_tx_file_size','max_input_size'
  125. )
  126. # Supported environmental vars
  127. # The corresponding vars (lowercase, minus 'mmgen_') must be initialized in g
  128. # 'DISABLE_' env vars disable the corresponding var in g
  129. env_opts = (
  130. 'MMGEN_DEBUG_ALL', # special: there is no g.debug_all var
  131. 'MMGEN_TEST_SUITE',
  132. 'MMGEN_BOGUS_WALLET_DATA',
  133. 'MMGEN_BOGUS_SEND',
  134. 'MMGEN_DEBUG',
  135. 'MMGEN_DEBUG_OPTS',
  136. 'MMGEN_DEBUG_RPC',
  137. 'MMGEN_DEBUG_ADDRLIST',
  138. 'MMGEN_DEBUG_UTF8',
  139. 'MMGEN_QUIET',
  140. 'MMGEN_FORCE_256_COLOR',
  141. 'MMGEN_MIN_URANDCHARS',
  142. 'MMGEN_NO_LICENSE',
  143. 'MMGEN_RPC_HOST',
  144. 'MMGEN_RPC_FAIL_ON_COMMAND',
  145. 'MMGEN_TESTNET',
  146. 'MMGEN_REGTEST',
  147. 'MMGEN_TRACEBACK',
  148. 'MMGEN_DISABLE_COLOR',
  149. )
  150. min_screen_width = 80
  151. minconf = 1
  152. max_tx_file_size = 100000
  153. max_input_size = 1024 * 1024
  154. # Global var sets user opt:
  155. global_sets_opt = ['minconf','seed_len','hash_preset','usr_randchars','debug',
  156. 'quiet','tx_confs','tx_fee_adj','key_generator']
  157. passwd_max_tries = 5
  158. max_urandchars = 80
  159. min_urandchars = 10
  160. seed_lens = 128,192,256
  161. mmenc_ext = 'mmenc'
  162. salt_len = 16
  163. aesctr_iv_len = 16
  164. hincog_chk_len = 8
  165. key_generators = 'python-ecdsa','secp256k1' # '1','2'
  166. key_generator = 2 # secp256k1 is default
  167. hash_presets = {
  168. # Scrypt params:
  169. # ID N p r (N is an exponent of two)
  170. '1': [12, 8, 1],
  171. '2': [13, 8, 4],
  172. '3': [14, 8, 8],
  173. '4': [15, 8, 12],
  174. '5': [16, 8, 16],
  175. '6': [17, 8, 20],
  176. '7': [18, 8, 24],
  177. }