opts.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. #!/usr/bin/env python3
  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. opts.py: MMGen-specific options processing after generic processing by share.Opts
  21. """
  22. import sys,os,stat
  23. class opt(object): pass
  24. from mmgen.globalvars import g
  25. import mmgen.share.Opts
  26. from mmgen.util import *
  27. def usage(): Die(2,'USAGE: {} {}'.format(g.prog_name,usage_txt))
  28. def die_on_incompatible_opts(incompat_list):
  29. for group in incompat_list:
  30. bad = [k for k in opt.__dict__ if opt.__dict__[k] and k in group]
  31. if len(bad) > 1:
  32. die(1,'Conflicting options: {}'.format(', '.join(map(fmt_opt,bad))))
  33. def fmt_opt(o): return '--' + o.replace('_','-')
  34. def _show_hash_presets():
  35. fs = ' {:<7} {:<6} {:<3} {}'
  36. msg('Available parameters for scrypt.hash():')
  37. msg(fs.format('Preset','N','r','p'))
  38. for i in sorted(g.hash_presets.keys()):
  39. msg(fs.format("'{}'".format(i,*g.hash_presets[i])))
  40. msg('N = memory usage (power of two), p = iterations (rounds)')
  41. def opt_preproc_debug(short_opts,long_opts,skipped_opts,uopts,args):
  42. d = (
  43. ('Cmdline', ' '.join(sys.argv)),
  44. ('Short opts', short_opts),
  45. ('Long opts', long_opts),
  46. ('Skipped opts', skipped_opts),
  47. ('User-selected opts', uopts),
  48. ('Cmd args', args),
  49. )
  50. Msg('\n=== opts.py debug ===')
  51. for e in d: Msg(' {:<20}: {}'.format(*e))
  52. def opt_postproc_debug():
  53. a = [k for k in dir(opt) if k[:2] != '__' and getattr(opt,k) != None]
  54. b = [k for k in dir(opt) if k[:2] != '__' and getattr(opt,k) == None]
  55. Msg(' Opts after processing:')
  56. for k in a:
  57. v = getattr(opt,k)
  58. Msg(' {:18}: {:<6} [{}]'.format(k,v,type(v).__name__))
  59. Msg(" Opts set to 'None':")
  60. Msg(' {}\n'.format('\n '.join(b)))
  61. Msg(' Global vars:')
  62. for e in [d for d in dir(g) if d[:2] != '__']:
  63. Msg(' {:<20}: {}'.format(e, getattr(g,e)))
  64. Msg('\n=== end opts.py debug ===\n')
  65. def opt_postproc_initializations():
  66. from mmgen.term import set_terminal_vars
  67. set_terminal_vars()
  68. # testnet data_dir differs from data_dir_root, so check or create
  69. from mmgen.util import msg,die,check_or_create_dir
  70. check_or_create_dir(g.data_dir) # dies on error
  71. from mmgen.color import init_color
  72. init_color(enable_color=g.color,num_colors=('auto',256)[bool(g.force_256_color)])
  73. if g.platform == 'win': start_mscolor()
  74. g.coin = g.coin.upper() # allow user to use lowercase
  75. g.dcoin = g.coin
  76. def set_data_dir_root():
  77. g.data_dir_root = os.path.normpath(os.path.expanduser(opt.data_dir)) if opt.data_dir else \
  78. os.path.join(g.home_dir,'.'+g.proj_name.lower())
  79. # mainnet and testnet share cfg file, as with Core
  80. g.cfg_file = os.path.join(g.data_dir_root,'{}.cfg'.format(g.proj_name.lower()))
  81. def get_cfg_template_data():
  82. # https://wiki.debian.org/Python:
  83. # Debian (Ubuntu) sys.prefix is '/usr' rather than '/usr/local, so add 'local'
  84. # TODO - test for Windows
  85. # This must match the configuration in setup.py
  86. cfg_template = os.path.join(*([sys.prefix]
  87. + (['share'],['local','share'])[g.platform=='linux']
  88. + [g.proj_name.lower(),os.path.basename(g.cfg_file)]))
  89. try:
  90. with open(cfg_template,'r') as f:
  91. return f.read()
  92. except:
  93. msg("WARNING: configuration template not found at '{}'".format(cfg_template))
  94. return ''
  95. def get_data_from_cfg_file():
  96. from mmgen.util import msg,die,check_or_create_dir
  97. check_or_create_dir(g.data_dir_root) # dies on error
  98. template_data = get_cfg_template_data()
  99. data = {}
  100. def copy_template_data(fn):
  101. try:
  102. with open(fn,'wb') as f: f.write(template_data.encode())
  103. os.chmod(fn,0o600)
  104. except:
  105. die(2,"ERROR: unable to write to datadir '{}'".format(g.data_dir))
  106. for k,suf in (('cfg',''),('sample','.sample')):
  107. try:
  108. with open(g.cfg_file+suf,'rb') as f:
  109. data[k] = f.read().decode('utf8')
  110. except:
  111. if template_data:
  112. copy_template_data(g.cfg_file+suf)
  113. data[k] = template_data
  114. else:
  115. data[k] = ''
  116. if template_data and data['sample'] != template_data:
  117. g.cfg_options_changed = True
  118. copy_template_data(g.cfg_file+'.sample')
  119. return data['cfg']
  120. def override_from_cfg_file(cfg_data):
  121. from mmgen.util import die,strip_comments,set_for_type
  122. import re
  123. from mmgen.protocol import CoinProtocol
  124. for n,l in enumerate(cfg_data.splitlines(),1): # DOS-safe
  125. l = strip_comments(l)
  126. if l == '': continue
  127. m = re.match(r'(\w+)\s+(\S+)$',l)
  128. if not m: die(2,"Parse error in file '{}', line {}".format(g.cfg_file,n))
  129. name,val = m.groups()
  130. if name in g.cfg_file_opts:
  131. pfx,cfg_var = name.split('_',1)
  132. if pfx in CoinProtocol.coins:
  133. tn = False
  134. cv1,cv2 = cfg_var.split('_',1)
  135. if cv1 in ('mainnet','testnet'):
  136. tn,cfg_var = (cv1 == 'testnet'),cv2
  137. cls,attr = CoinProtocol(pfx,tn),cfg_var
  138. else:
  139. cls,attr = g,name
  140. setattr(cls,attr,set_for_type(val,getattr(cls,attr),attr,src=g.cfg_file))
  141. else:
  142. die(2,"'{}': unrecognized option in '{}'".format(name,g.cfg_file))
  143. def override_from_env():
  144. from mmgen.util import set_for_type
  145. for name in g.env_opts:
  146. if name == 'MMGEN_DEBUG_ALL': continue
  147. idx,invert_bool = ((6,False),(14,True))[name[:14]=='MMGEN_DISABLE_']
  148. val = os.getenv(name) # os.getenv() returns None if env var is unset
  149. if val: # exclude empty string values too
  150. gname = name[idx:].lower()
  151. setattr(g,gname,set_for_type(val,getattr(g,gname),name,invert_bool))
  152. def warn_altcoins(trust_level):
  153. if trust_level == None: return
  154. tl = (red('COMPLETELY UNTESTED'),red('LOW'),yellow('MEDIUM'),green('HIGH'))
  155. m = """
  156. Support for coin '{}' is EXPERIMENTAL. The {pn} project assumes no
  157. responsibility for any loss of funds you may incur.
  158. This coin's {pn} testing status: {}
  159. Are you sure you want to continue?
  160. """.strip().format(g.coin,tl[trust_level],pn=g.proj_name)
  161. if os.getenv('MMGEN_TEST_SUITE'):
  162. msg(m); return
  163. if not keypress_confirm(m,default_yes=True):
  164. sys.exit(0)
  165. def init(opts_f,add_opts=[],opt_filter=None):
  166. from mmgen.protocol import CoinProtocol,BitcoinProtocol,init_genonly_altcoins
  167. g.proto = BitcoinProtocol # this must be initialized to something before opts_f is called
  168. # most, but not all, of these set the corresponding global var
  169. common_opts_data = """
  170. --, --accept-defaults Accept defaults at all prompts
  171. --, --coin=c Choose coin unit. Default: {cu_dfl}. Options: {cu_all}
  172. --, --token=t Specify an ERC20 token by address or symbol
  173. --, --color=0|1 Disable or enable color output
  174. --, --force-256-color Force 256-color output when color is enabled
  175. --, --daemon-data-dir=d Specify coin daemon data directory location 'd'
  176. --, --data-dir=d Specify {pnm} data directory location 'd'
  177. --, --no-license Suppress the GPL license prompt
  178. --, --rpc-host=h Communicate with {dn} running on host 'h'
  179. --, --rpc-port=p Communicate with {dn} listening on port 'p'
  180. --, --rpc-user=user Override 'rpcuser' in {pn}.conf
  181. --, --rpc-password=pass Override 'rpcpassword' in {pn}.conf
  182. --, --regtest=0|1 Disable or enable regtest mode
  183. --, --testnet=0|1 Disable or enable testnet
  184. --, --skip-cfg-file Skip reading the configuration file
  185. --, --version Print version information and exit
  186. --, --bob Switch to user "Bob" in MMGen regtest setup
  187. --, --alice Switch to user "Alice" in MMGen regtest setup
  188. """.format( pnm=g.proj_name,pn=g.proto.name,dn=g.proto.daemon_name,
  189. cu_dfl=g.coin,
  190. cu_all=' '.join(CoinProtocol.coins))
  191. opts_data = opts_f()
  192. opts_data['long_options'] = common_opts_data
  193. version_info = """
  194. {pgnm_uc} version {g.version}
  195. Part of the {pnm} suite, an online/offline cryptocoin wallet for the command line.
  196. Copyright (C) {g.Cdates} {g.author} {g.email}
  197. """.format(pnm=g.proj_name, g=g, pgnm_uc=g.prog_name.upper()).strip()
  198. uopts,args,short_opts,long_opts,skipped_opts,do_help = \
  199. mmgen.share.Opts.parse_opts(sys.argv,opts_data,opt_filter=opt_filter,skip_help=True)
  200. if g.debug_opts: opt_preproc_debug(short_opts,long_opts,skipped_opts,uopts,args)
  201. # Save this for usage()
  202. global usage_txt
  203. usage_txt = opts_data['usage']
  204. # Transfer uopts into opt, setting program's opts + required opts to None if not set by user
  205. for o in tuple([s.rstrip('=') for s in long_opts] + add_opts + skipped_opts) + \
  206. g.required_opts + g.common_opts:
  207. setattr(opt,o,uopts[o] if o in uopts else None)
  208. if opt.version: Die(0,version_info)
  209. from mmgen.common import set_debug_all
  210. set_debug_all()
  211. # === Interaction with global vars begins here ===
  212. # NB: user opt --data-dir is actually g.data_dir_root
  213. # cfg file is in g.data_dir_root, wallet and other data are in g.data_dir
  214. # We must set g.data_dir_root and g.cfg_file from cmdline before processing cfg file
  215. set_data_dir_root()
  216. if not opt.skip_cfg_file:
  217. override_from_cfg_file(get_data_from_cfg_file())
  218. override_from_env()
  219. # User opt sets global var - do these here, before opt is set from g.global_sets_opt
  220. for k in g.common_opts:
  221. val = getattr(opt,k)
  222. if val != None: setattr(g,k,set_for_type(val,getattr(g,k),'--'+k))
  223. if g.regtest: g.testnet = True # These are equivalent for now
  224. altcoin_trust_level = init_genonly_altcoins(opt.coin)
  225. # g.testnet is set, so we can set g.proto
  226. g.proto = CoinProtocol(g.coin,g.testnet)
  227. # global sets proto
  228. if g.daemon_data_dir: g.proto.daemon_data_dir = g.daemon_data_dir
  229. # g.proto is set, so we can set g.data_dir
  230. g.data_dir = os.path.normpath(os.path.join(g.data_dir_root,g.proto.data_subdir))
  231. # If user opt is set, convert its type based on value in mmgen.globalvars (g)
  232. # If unset, set it to default value in mmgen.globalvars (g)
  233. setattr(opt,'set_by_user',[])
  234. for k in g.global_sets_opt:
  235. if k in opt.__dict__ and getattr(opt,k) != None:
  236. setattr(opt,k,set_for_type(getattr(opt,k),getattr(g,k),'--'+k))
  237. opt.set_by_user.append(k)
  238. else:
  239. setattr(opt,k,g.__dict__[k])
  240. if opt.show_hash_presets:
  241. _show_hash_presets()
  242. sys.exit(0)
  243. if opt.verbose: opt.quiet = None
  244. die_on_incompatible_opts(g.incompatible_opts)
  245. opt_postproc_initializations()
  246. if do_help: # print help screen only after global vars are initialized
  247. opts_data = opts_f()
  248. opts_data['long_options'] = common_opts_data
  249. if g.debug_utf8:
  250. for k in opts_data:
  251. if type(opts_data[k]) == str:
  252. opts_data[k] += '-α'
  253. mmgen.share.Opts.parse_opts(sys.argv,opts_data,opt_filter=opt_filter)
  254. if g.bob or g.alice:
  255. g.testnet = True
  256. g.regtest = True
  257. g.proto = CoinProtocol(g.coin,g.testnet)
  258. g.data_dir = os.path.join(g.data_dir_root,'regtest',g.coin.lower(),('alice','bob')[g.bob])
  259. check_or_create_dir(g.data_dir)
  260. from . import regtest as rt
  261. g.rpc_host = 'localhost'
  262. g.rpc_port = rt.rpc_port
  263. g.rpc_user = rt.rpc_user
  264. g.rpc_password = rt.rpc_password
  265. if g.regtest and hasattr(g.proto,'bech32_hrp_rt'):
  266. g.proto.bech32_hrp = g.proto.bech32_hrp_rt
  267. # Check user-set opts without modifying them
  268. if not check_opts(uopts):
  269. sys.exit(1)
  270. if hasattr(g,'cfg_options_changed'):
  271. ymsg("Warning: config file options have changed! See '{}' for details".format(g.cfg_file+'.sample'))
  272. my_raw_input('Hit ENTER to continue: ')
  273. if g.debug and g.prog_name != 'test.py':
  274. opt.verbose,opt.quiet = True,None
  275. if g.debug_opts: opt_postproc_debug()
  276. # We don't need this data anymore
  277. del mmgen.share.Opts
  278. del opts_f
  279. for k in ('prog_name','desc','usage','options','notes'):
  280. if k in opts_data: del opts_data[k]
  281. g.altcoin_data_dir = os.path.join(g.data_dir_root,'altcoins')
  282. warn_altcoins(altcoin_trust_level)
  283. return args
  284. def opt_is_tx_fee(val,desc):
  285. from mmgen.tx import MMGenTX
  286. ret = MMGenTX().process_fee_spec(val,224,on_fail='return')
  287. # Non-standard startgas: disable fee checking
  288. if hasattr(opt,'contract_data') and opt.contract_data: ret = None
  289. if hasattr(opt,'tx_gas') and opt.tx_gas: ret = None
  290. if ret == False:
  291. msg("'{}': invalid {}\n(not a {} amount or {} specification)".format(
  292. val,desc,g.coin.upper(),MMGenTX().rel_fee_desc))
  293. elif ret != None and ret > g.proto.max_tx_fee:
  294. msg("'{}': invalid {}\n({} > max_tx_fee ({} {}))".format(
  295. val,desc,ret.fmt(fs='1.1'),g.proto.max_tx_fee,g.coin.upper()))
  296. else:
  297. return True
  298. return False
  299. def check_opts(usr_opts): # Returns false if any check fails
  300. def opt_splits(val,sep,n,desc):
  301. sepword = 'comma' if sep == ',' else 'colon' if sep == ':' else "'{}'".format(sep)
  302. try: l = val.split(sep)
  303. except:
  304. msg("'{}': invalid {} (not {}-separated list)".format(val,desc,sepword))
  305. return False
  306. if len(l) == n: return True
  307. else:
  308. msg("'{}': invalid {} ({} {}-separated items required)".format(val,desc,n,sepword))
  309. return False
  310. def opt_compares(val,op_str,target,desc,what=''):
  311. import operator as o
  312. op_f = { '<':o.lt, '<=':o.le, '>':o.gt, '>=':o.ge, '=':o.eq }[op_str]
  313. if what: what += ' '
  314. if not op_f(val,target):
  315. msg('{}: invalid {} ({}not {} {})'.format(val,desc,what,op_str,target))
  316. return False
  317. return True
  318. def opt_is_int(val,desc):
  319. try: int(val)
  320. except:
  321. msg("'{}': invalid {} (not an integer)".format(val,desc))
  322. return False
  323. return True
  324. def opt_is_float(val,desc):
  325. try: float(val)
  326. except:
  327. msg("'{}': invalid {} (not a floating-point number)".format(val,desc))
  328. return False
  329. return True
  330. def opt_is_in_list(val,lst,desc):
  331. if val not in lst:
  332. q,sep = (('',','),("'","','"))[type(lst[0]) == str]
  333. fs = '{q}{v}{q}: invalid {w}\nValid choices: {q}{o}{q}'
  334. msg(fs.format(v=val,w=desc,q=q,o=sep.join(map(str,sorted(lst)))))
  335. return False
  336. return True
  337. def opt_unrecognized(key,val,desc):
  338. msg("'{}': unrecognized {} for option '{}'".format(val,desc,fmt_opt(key)))
  339. return False
  340. def opt_display(key,val='',beg='For selected',end=':\n'):
  341. s = '{}={}'.format(fmt_opt(key),val) if val else fmt_opt(key)
  342. msg_r("{} option '{}'{}".format(beg,s,end))
  343. global opt
  344. for key,val in [(k,getattr(opt,k)) for k in usr_opts]:
  345. desc = "parameter for '{}' option".format(fmt_opt(key))
  346. from mmgen.util import check_infile,check_outfile,check_outdir
  347. # Check for file existence and readability
  348. if key in ('keys_from_file','mmgen_keys_from_file',
  349. 'passwd_file','keysforaddrs','comment_file'):
  350. check_infile(val) # exits on error
  351. continue
  352. if key == 'outdir':
  353. check_outdir(val) # exits on error
  354. # # NEW
  355. elif key in ('in_fmt','out_fmt'):
  356. from mmgen.seed import SeedSource,IncogWallet,Brainwallet,IncogWalletHidden
  357. sstype = SeedSource.fmt_code_to_type(val)
  358. if not sstype:
  359. return opt_unrecognized(key,val,'format code')
  360. if key == 'out_fmt':
  361. p = 'hidden_incog_output_params'
  362. if sstype == IncogWalletHidden and not getattr(opt,p):
  363. m1 = 'Hidden incog format output requested. '
  364. m2 = "You must supply a file and offset with the '{}' option"
  365. die(1,m1+m2.format(fmt_opt(p)))
  366. if issubclass(sstype,IncogWallet) and opt.old_incog_fmt:
  367. opt_display(key,val,beg='Selected',end=' ')
  368. opt_display('old_incog_fmt',beg='conflicts with',end=':\n')
  369. die(1,'Export to old incog wallet format unsupported')
  370. elif issubclass(sstype,Brainwallet):
  371. die(1,'Output to brainwallet format unsupported')
  372. elif key in ('hidden_incog_input_params','hidden_incog_output_params'):
  373. a = val.split(',')
  374. if len(a) < 2:
  375. opt_display(key,val)
  376. msg('Option requires two comma-separated arguments')
  377. return False
  378. fn,ofs = ','.join(a[:-1]),a[-1] # permit comma in filename
  379. if not opt_is_int(ofs,desc): return False
  380. if key == 'hidden_incog_input_params':
  381. check_infile(fn,blkdev_ok=True)
  382. key2 = 'in_fmt'
  383. else:
  384. try: os.stat(fn)
  385. except:
  386. b = os.path.dirname(fn)
  387. if b: check_outdir(b)
  388. else: check_outfile(fn,blkdev_ok=True)
  389. key2 = 'out_fmt'
  390. if hasattr(opt,key2):
  391. val2 = getattr(opt,key2)
  392. from mmgen.seed import IncogWalletHidden
  393. if val2 and val2 not in IncogWalletHidden.fmt_codes:
  394. fs = 'Option conflict:\n {}, with\n {}={}'
  395. die(1,fs.format(fmt_opt(key),fmt_opt(key2),val2))
  396. elif key == 'seed_len':
  397. if not opt_is_int(val,desc): return False
  398. if not opt_is_in_list(int(val),g.seed_lens,desc): return False
  399. elif key == 'hash_preset':
  400. if not opt_is_in_list(val,list(g.hash_presets.keys()),desc): return False
  401. elif key == 'brain_params':
  402. a = val.split(',')
  403. if len(a) != 2:
  404. opt_display(key,val)
  405. msg('Option requires two comma-separated arguments')
  406. return False
  407. d = 'seed length ' + desc
  408. if not opt_is_int(a[0],d): return False
  409. if not opt_is_in_list(int(a[0]),g.seed_lens,d): return False
  410. d = 'hash preset ' + desc
  411. if not opt_is_in_list(a[1],list(g.hash_presets.keys()),d): return False
  412. elif key == 'usr_randchars':
  413. if val == 0: continue
  414. if not opt_is_int(val,desc): return False
  415. if not opt_compares(val,'>=',g.min_urandchars,desc): return False
  416. if not opt_compares(val,'<=',g.max_urandchars,desc): return False
  417. elif key == 'tx_fee':
  418. if not opt_is_tx_fee(val,desc): return False
  419. elif key == 'tx_confs':
  420. if not opt_is_int(val,desc): return False
  421. if not opt_compares(val,'>=',1,desc): return False
  422. elif key == 'vsize_adj':
  423. if not opt_is_float(val,desc): return False
  424. ymsg('Adjusting transaction vsize by a factor of {:1.2f}'.format(float(val)))
  425. elif key == 'key_generator':
  426. if not opt_compares(val,'<=',len(g.key_generators),desc): return False
  427. if not opt_compares(val,'>',0,desc): return False
  428. elif key == 'coin':
  429. from mmgen.protocol import CoinProtocol
  430. if not opt_is_in_list(val.lower(),list(CoinProtocol.coins.keys()),'coin'): return False
  431. elif key == 'rbf':
  432. if not g.proto.cap('rbf'):
  433. msg('--rbf requested, but {} does not support replace-by-fee transactions'.format(g.coin))
  434. return False
  435. elif key in ('bob','alice'):
  436. from mmgen.regtest import daemon_dir
  437. m = "Regtest (Bob and Alice) mode not set up yet. Run '{}-regtest setup' to initialize."
  438. try: os.stat(daemon_dir)
  439. except: die(1,m.format(g.proj_name.lower()))
  440. elif key == 'locktime':
  441. if not opt_is_int(val,desc): return False
  442. if not opt_compares(val,'>',0,desc): return False
  443. elif key == 'token':
  444. if not 'token' in g.proto.caps:
  445. msg("Coin '{}' does not support the --token option".format(g.coin))
  446. return False
  447. elif len(val) == 40 and is_hex_str(val):
  448. pass
  449. elif len(val) > 20 or not all(s.isalnum() for s in val):
  450. msg("u'{}: invalid parameter for --token option".format(val))
  451. return False
  452. elif key == 'contract_data':
  453. check_infile(val)
  454. else:
  455. if g.debug: Msg("check_opts(): No test for opt '{}'".format(key))
  456. return True