UserOpts: set _default_to_none to True
This commit is contained in:
parent
b79865dba4
commit
481bc13e52
12 changed files with 22 additions and 17 deletions
|
|
@ -190,7 +190,7 @@ def KeyGenerator(proto,pubkey_type,backend=None,silent=False):
|
|||
pubkey_type_cls = getattr(keygen_backend,pubkey_type)
|
||||
|
||||
from .opts import opt
|
||||
backend = backend or getattr(opt,'keygen_backend',None)
|
||||
backend = backend or opt.keygen_backend
|
||||
|
||||
if backend:
|
||||
_check_backend(backend,pubkey_type)
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ class AddrFile(MMGenObject):
|
|||
|
||||
if p.has_keys and not p.skip_ka_check:
|
||||
from .opts import opt
|
||||
if getattr(opt,'yes',False) or keypress_confirm('Check key-to-address validity?'):
|
||||
if opt.yes or keypress_confirm('Check key-to-address validity?'):
|
||||
from .addr import KeyGenerator,AddrGenerator
|
||||
kg = KeyGenerator(p.proto,p.al_id.mmtype.pubkey_type)
|
||||
ag = AddrGenerator(p.proto,p.al_id.mmtype)
|
||||
|
|
|
|||
|
|
@ -94,9 +94,9 @@ class EthereumMMGenTX:
|
|||
|
||||
def __init__(self,*args,**kwargs):
|
||||
MMGenTX.New.__init__(self,*args,**kwargs)
|
||||
if getattr(opt,'tx_gas',None):
|
||||
if opt.tx_gas:
|
||||
self.tx_gas = self.start_gas = ETHAmt(int(opt.tx_gas),'wei')
|
||||
if getattr(opt,'contract_data',None):
|
||||
if opt.contract_data:
|
||||
m = "'--contract-data' option may not be used with token transaction"
|
||||
assert not 'Token' in type(self).__name__, m
|
||||
with open(opt.contract_data) as fp:
|
||||
|
|
|
|||
|
|
@ -250,6 +250,7 @@ class GlobalContext(Lockable):
|
|||
auto_typeset_opts = {
|
||||
'seed_len': int,
|
||||
'subseeds': int,
|
||||
'vsize_adj': float,
|
||||
}
|
||||
|
||||
min_screen_width = 80
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import mmgen.share.Opts
|
|||
|
||||
class UserOpts(Lockable):
|
||||
_autolock = False
|
||||
_default_to_none = True
|
||||
_set_ok = ('usr_randchars',)
|
||||
_reset_ok = ('quiet','verbose','yes')
|
||||
|
||||
|
|
|
|||
|
|
@ -458,7 +458,7 @@ class CoinProtocol(MMGenObject):
|
|||
def __init__(self,*args,**kwargs):
|
||||
super().__init__(*args,**kwargs)
|
||||
from .opts import opt
|
||||
self.coin_id = 'ZEC-Z' if getattr(opt,'type',None) in ('zcash_z','Z') else 'ZEC-T'
|
||||
self.coin_id = 'ZEC-Z' if opt.type in ('zcash_z','Z') else 'ZEC-T'
|
||||
|
||||
def get_addr_len(self,addr_fmt):
|
||||
return (20,64)[addr_fmt in ('zcash_z','viewkey')]
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class Seed(SeedBase):
|
|||
from .opts import opt
|
||||
self._subseeds = SubSeedList(
|
||||
self,
|
||||
length = self.nSubseeds or getattr(opt,'subseeds',None) )
|
||||
length = self.nSubseeds or opt.subseeds )
|
||||
return self._subseeds
|
||||
|
||||
def subseed(self,*args,**kwargs):
|
||||
|
|
|
|||
|
|
@ -280,7 +280,9 @@ class MMGenToolCmds(metaclass=MMGenToolCmdMeta):
|
|||
def __init__(self,proto=None,mmtype=None):
|
||||
from .protocol import init_proto_from_opts
|
||||
self.proto = proto or init_proto_from_opts()
|
||||
self.mmtype = MMGenAddrType(self.proto,(mmtype or getattr(opt,'type',None) or self.proto.dfl_mmtype))
|
||||
self.mmtype = MMGenAddrType(
|
||||
self.proto,
|
||||
mmtype or opt.type or self.proto.dfl_mmtype )
|
||||
if g.token:
|
||||
self.proto.tokensym = g.token.upper()
|
||||
|
||||
|
|
@ -1050,7 +1052,7 @@ class tool_api(
|
|||
"""
|
||||
import mmgen.opts
|
||||
opts.UserOpts._reset_ok += ('usr_randchars',)
|
||||
if not hasattr(opt,'version'):
|
||||
if not opt._lock:
|
||||
opts.init()
|
||||
super().__init__()
|
||||
|
||||
|
|
|
|||
|
|
@ -465,7 +465,7 @@ class MMGenTX:
|
|||
dmsg(f' inputs size: {isize}, outputs size: {osize}, witness size: {wsize}')
|
||||
dmsg(f' size: {new_size}, vsize: {ret}, old_size: {old_size}')
|
||||
|
||||
return int(ret * float(opt.vsize_adj)) if hasattr(opt,'vsize_adj') and opt.vsize_adj else ret
|
||||
return int(ret * (opt.vsize_adj or 1))
|
||||
|
||||
# convert absolute BTC fee to satoshis-per-byte using estimated size
|
||||
def fee_abs2rel(self,abs_fee,to_unit=None):
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@ def warn_altcoins(coinsym,trust_level):
|
|||
def get_keccak():
|
||||
|
||||
from .opts import opt
|
||||
# called in opts.init() via CoinProtocol, so must use getattr():
|
||||
if getattr(opt,'use_internal_keccak_module',False):
|
||||
from .keccak import keccak_256
|
||||
qmsg('Using internal keccak module by user request')
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class Wallet(MMGenObject,metaclass=WalletMeta):
|
|||
|
||||
in_fmt = in_fmt or opt.in_fmt
|
||||
|
||||
if hasattr(opt,'out_fmt') and opt.out_fmt:
|
||||
if opt.out_fmt:
|
||||
out_cls = cls.fmt_code_to_type(opt.out_fmt)
|
||||
if not out_cls:
|
||||
die(1,f'{opt.out_fmt!r}: unrecognized output format')
|
||||
|
|
|
|||
|
|
@ -161,12 +161,12 @@ def init_coverage():
|
|||
return coverdir,acc_file
|
||||
|
||||
def silence():
|
||||
if not (opt.verbose or getattr(opt,'exact_output',None)):
|
||||
if not (opt.verbose or opt.exact_output):
|
||||
devnull_fn = ('/dev/null','null.out')[g.platform == 'win']
|
||||
g.stdout = g.stderr = open(devnull_fn,'w')
|
||||
|
||||
def end_silence():
|
||||
if not (opt.verbose or getattr(opt,'exact_output',None)):
|
||||
if not (opt.verbose or opt.exact_output):
|
||||
g.stdout.close()
|
||||
g.stdout = sys.stdout
|
||||
g.stderr = sys.stderr
|
||||
|
|
@ -178,10 +178,10 @@ def omsg_r(s):
|
|||
sys.stderr.flush()
|
||||
|
||||
def imsg(s):
|
||||
if opt.verbose or getattr(opt,'exact_output',None):
|
||||
if opt.verbose or opt.exact_output:
|
||||
omsg(s)
|
||||
def imsg_r(s):
|
||||
if opt.verbose or getattr(opt,'exact_output',None):
|
||||
if opt.verbose or opt.exact_output:
|
||||
omsg_r(s)
|
||||
|
||||
def iqmsg(s):
|
||||
|
|
@ -192,10 +192,10 @@ def iqmsg_r(s):
|
|||
omsg_r(s)
|
||||
|
||||
def oqmsg(s):
|
||||
if not (opt.verbose or getattr(opt,'exact_output',None)):
|
||||
if not (opt.verbose or opt.exact_output):
|
||||
omsg(s)
|
||||
def oqmsg_r(s):
|
||||
if not (opt.verbose or getattr(opt,'exact_output',None)):
|
||||
if not (opt.verbose or opt.exact_output):
|
||||
omsg_r(s)
|
||||
|
||||
def end_msg(t):
|
||||
|
|
@ -220,7 +220,7 @@ def restart_test_daemons(*network_ids,remove_datadir=False):
|
|||
def test_daemons_ops(*network_ids,op,remove_datadir=False):
|
||||
if not opt.no_daemon_autostart:
|
||||
from mmgen.daemon import CoinDaemon
|
||||
silent = not opt.verbose and not getattr(opt,'exact_output',False)
|
||||
silent = not (opt.verbose or opt.exact_output)
|
||||
ret = False
|
||||
for network_id in network_ids:
|
||||
d = CoinDaemon(network_id,test_suite=True,daemon_id=g.daemon_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue