Use new-style string formatting
This commit is contained in:
parent
b80b059815
commit
351f5f9118
24 changed files with 319 additions and 360 deletions
|
|
@ -328,7 +328,7 @@ Record this checksum: it will be used to verify the address file in the future
|
|||
""".strip(),
|
||||
'check_chksum': 'Check this value against your records',
|
||||
'removed_dup_keys': """
|
||||
Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
||||
Removed {{}} duplicate WIF key{{}} from keylist (also in {pnm} key-address file
|
||||
""".strip().format(pnm=pnm)
|
||||
}
|
||||
entry_type = AddrListEntry
|
||||
|
|
@ -371,7 +371,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
elif al_id or adata:
|
||||
die(3,'Must specify both al_id and adata')
|
||||
else:
|
||||
die(3,'Incorrect arguments for %s' % type(self).__name__)
|
||||
die(3,'Incorrect arguments for {}'.format(type(self).__name__))
|
||||
|
||||
# al_id,adata now set
|
||||
self.data = adata
|
||||
|
|
@ -389,8 +389,8 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
if chksum_only:
|
||||
Msg(self.chksum)
|
||||
else:
|
||||
qmsg('Checksum for %s data %s: %s' %
|
||||
(self.data_desc,self.id_str.hl(),self.chksum.hl()))
|
||||
qmsg('Checksum for {} data {}: {}'.format(
|
||||
self.data_desc,self.id_str.hl(),self.chksum.hl()))
|
||||
qmsg(self.msgs[('check_chksum','record_chksum')[src=='gen']])
|
||||
|
||||
def update_msgs(self):
|
||||
|
|
@ -426,7 +426,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
pos += 1
|
||||
|
||||
if not g.debug:
|
||||
qmsg_r('\rGenerating %s #%s (%s of %s)' % (self.gen_desc,num,pos,t_addrs))
|
||||
qmsg_r('\rGenerating {} #{} ({} of {})'.format(self.gen_desc,num,pos,t_addrs))
|
||||
|
||||
e = le(idx=num)
|
||||
|
||||
|
|
@ -448,7 +448,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
out.append(e)
|
||||
if g.debug: Msg('generate():\n{}'.format(e.pformat()))
|
||||
|
||||
qmsg('\r%s: %s %s%s generated%s' % (
|
||||
qmsg('\r{}: {} {}{} generated{}'.format(
|
||||
self.al_id.hl(),t_addrs,self.gen_desc,suf(t_addrs,self.gen_desc_pl),' '*15))
|
||||
return out
|
||||
|
||||
|
|
@ -481,7 +481,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
return [e.idx for e in self.data]
|
||||
|
||||
def addrs(self):
|
||||
return ['%s:%s'%(self.al_id.sid,e.idx) for e in self.data]
|
||||
return ['{}:{}'.format(self.al_id.sid,e.idx) for e in self.data]
|
||||
|
||||
def addrpairs(self):
|
||||
return [(e.idx,e.addr) for e in self.data]
|
||||
|
|
@ -526,7 +526,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
pop_list.append(n)
|
||||
for n in reversed(pop_list): self.data.pop(n)
|
||||
if pop_list:
|
||||
vmsg(self.msgs['removed_dup_keys'] % (len(pop_list),suf(removed,'s')))
|
||||
vmsg(self.msgs['removed_dup_keys'].format(len(pop_list),suf(removed,'s')))
|
||||
|
||||
def add_wifs(self,key_list):
|
||||
if not key_list: return
|
||||
|
|
@ -543,9 +543,9 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
ag = AddrGenerator('p2pkh')
|
||||
d = self.data
|
||||
for n,e in enumerate(d,1):
|
||||
qmsg_r('\rGenerating addresses from keylist: %s/%s' % (n,len(d)))
|
||||
qmsg_r('\rGenerating addresses from keylist: {}/{}'.format(n,len(d)))
|
||||
e.addr = ag.to_addr(kg.to_pubhex(e.sec))
|
||||
qmsg('\rGenerated addresses from keylist: %s/%s ' % (n,len(d)))
|
||||
qmsg('\rGenerated addresses from keylist: {}/{} '.format(n,len(d)))
|
||||
|
||||
def format(self,enable_comments=False):
|
||||
|
||||
|
|
@ -600,7 +600,7 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
while lines:
|
||||
d = get_line()
|
||||
|
||||
assert is_mmgen_idx(d[0]),"'%s': invalid address num. in line: '%s'" % (d[0],' '.join(d))
|
||||
assert is_mmgen_idx(d[0]),"'{}': invalid address num. in line: '{}'".format(d[0],' '.join(d))
|
||||
assert self.check_format(d[1]),"'{}': invalid {}".format(d[1],self.data_desc)
|
||||
|
||||
if len(d) != 3: d.append('')
|
||||
|
|
@ -623,9 +623,9 @@ Removed %s duplicate WIF key%s from keylist (also in {pnm} key-address file
|
|||
ag = AddrGenerator(self.al_id.mmtype)
|
||||
llen = len(ret)
|
||||
for n,e in enumerate(ret):
|
||||
msg_r('\rVerifying keys %s/%s' % (n+1,llen))
|
||||
msg_r('\rVerifying keys {}/{}'.format(n+1,llen))
|
||||
assert e.addr == ag.to_addr(kg.to_pubhex(e.sec)),(
|
||||
"Key doesn't match address!\n %s\n %s" % (e.sec.wif,e.addr))
|
||||
"Key doesn't match address!\n {}\n {}".format(e.sec.wif,e.addr))
|
||||
msg(' - done')
|
||||
|
||||
return ret
|
||||
|
|
@ -849,7 +849,7 @@ Record this checksum: it will be used to verify the password file in the future
|
|||
class AddrData(MMGenObject):
|
||||
msgs = {
|
||||
'too_many_acct_addresses': """
|
||||
ERROR: More than one address found for account: '%s'.
|
||||
ERROR: More than one address found for account: '{{}}'.
|
||||
Your 'wallet.dat' file appears to have been altered by a non-{pnm} program.
|
||||
Please restore your tracking wallet from a backup or create a new one and
|
||||
re-import your addresses.
|
||||
|
|
@ -890,7 +890,7 @@ re-import your addresses.
|
|||
obj = l.mmid.obj
|
||||
i += 1
|
||||
if len(addrlist) != 1:
|
||||
die(2,self.msgs['too_many_acct_addresses'] % acct)
|
||||
die(2,self.msgs['too_many_acct_addresses'].format(acct))
|
||||
al_id = AddrListID(SeedID(sid=obj.sid),MMGenAddrType(obj.mmtype))
|
||||
if al_id not in data:
|
||||
data[al_id] = []
|
||||
|
|
@ -904,7 +904,7 @@ re-import your addresses.
|
|||
self.al_ids[addrlist.al_id] = addrlist
|
||||
return True
|
||||
else:
|
||||
raise TypeError, 'Error: object %s is not of type AddrList' % repr(addrlist)
|
||||
raise TypeError, 'Error: object {!r} is not of type AddrList'.format(addrlist)
|
||||
|
||||
def make_reverse_dict(self,coinaddrs):
|
||||
d = MMGenDict()
|
||||
|
|
|
|||
|
|
@ -44,14 +44,14 @@ class Filename(MMGenObject):
|
|||
self.ftype = ftype
|
||||
# elif: # other MMGen file types
|
||||
else:
|
||||
die(3,"'%s': not a recognized file type for SeedSource" % ftype)
|
||||
die(3,"'{}': not a recognized file type for SeedSource".format(ftype))
|
||||
else:
|
||||
die(3,"'%s': not a class" % ftype)
|
||||
die(3,"'{}': not a class".format(ftype))
|
||||
else:
|
||||
# TODO: other file types
|
||||
self.ftype = SeedSource.ext_to_type(self.ext)
|
||||
if not self.ftype:
|
||||
die(3,"'%s': not a recognized extension for SeedSource" % self.ext)
|
||||
die(3,"'{}': not a recognized extension for SeedSource".format(self.ext))
|
||||
|
||||
|
||||
import stat
|
||||
|
|
@ -62,7 +62,7 @@ class Filename(MMGenObject):
|
|||
fd = os.open(fn, mode)
|
||||
except OSError as e:
|
||||
if e.errno == 13:
|
||||
die(2,"'%s': permission denied" % fn)
|
||||
die(2,"'{}': permission denied".format(fn))
|
||||
# if e.errno != 17: raise
|
||||
else:
|
||||
self.size = os.lseek(fd, 0, os.SEEK_END)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ class g(object):
|
|||
if sys.platform[:len(k)] == k:
|
||||
platform = k; break
|
||||
else:
|
||||
die(1,"'%s': platform not supported by %s\n" % (sys.platform,proj_name))
|
||||
die(1,"'{}': platform not supported by {}\n".format(sys.platform,proj_name))
|
||||
|
||||
if os.getenv('HOME'): # Linux or MSYS
|
||||
home_dir = os.getenv('HOME')
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ import mmgen.tool as tool
|
|||
if Command == 'Help' and not cmd_args: tool.usage(None)
|
||||
|
||||
if Command not in tool.cmd_data:
|
||||
die(1,"'%s': no such command" % Command.lower())
|
||||
die(1,"'{}': no such command".format(Command.lower()))
|
||||
|
||||
args,kwargs = tool.process_args(Command,cmd_args)
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ if not opt.status: do_license_msg()
|
|||
from mmgen.tx import *
|
||||
|
||||
tx = MMGenTX(infile,silent_open=True) # sig check performed here
|
||||
vmsg("Signed transaction file '%s' is valid" % infile)
|
||||
vmsg("Signed transaction file '{}' is valid".format(infile))
|
||||
|
||||
if not tx.marked_signed():
|
||||
die(1,'Transaction is not signed!')
|
||||
|
|
|
|||
|
|
@ -92,13 +92,13 @@ if kl and kal: kl.remove_dup_keys(kal)
|
|||
tx_num_str = ''
|
||||
for tx_num,tx_file in enumerate(tx_files,1):
|
||||
if len(tx_files) > 1:
|
||||
msg('\nTransaction #%s of %s:' % (tx_num,len(tx_files)))
|
||||
tx_num_str = ' #%s' % tx_num
|
||||
msg('\nTransaction #{} of {}:'.format(tx_num,len(tx_files)))
|
||||
tx_num_str = ' #{}'.format(tx_num)
|
||||
tx = MMGenTX(tx_file)
|
||||
|
||||
if tx.marked_signed():
|
||||
die(1,'Transaction is already signed!')
|
||||
vmsg("Successfully opened transaction file '%s'" % tx_file)
|
||||
vmsg("Successfully opened transaction file '{}'".format(tx_file))
|
||||
|
||||
if opt.tx_id:
|
||||
msg(tx.txid); continue
|
||||
|
|
@ -107,7 +107,7 @@ for tx_num,tx_file in enumerate(tx_files,1):
|
|||
tx.view(pause=False,terse=opt.terse_info); continue
|
||||
|
||||
if not opt.yes:
|
||||
tx.view_with_prompt('View data for transaction%s?' % tx_num_str)
|
||||
tx.view_with_prompt('View data for transaction{}?'.format(tx_num_str))
|
||||
|
||||
txsign(tx,seed_files,kl,kal,tx_num_str)
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ elif invoked_as == 'passchg':
|
|||
iaction = 'input'
|
||||
bw_note = False
|
||||
else:
|
||||
die(1,"'%s': unrecognized invocation" % g.prog_name)
|
||||
die(1,"'{}': unrecognized invocation".format(g.prog_name))
|
||||
|
||||
opts_data = lambda: {
|
||||
# Can't use: share/Opts doesn't know anything about fmt codes
|
||||
|
|
@ -117,10 +117,10 @@ sf = get_seed_file(cmd_args,nargs,invoked_as=invoked_as)
|
|||
|
||||
if not invoked_as == 'chk': do_license_msg()
|
||||
|
||||
dw_msg = ('',yellow(' (default wallet)'))[bool(sf and os.path.dirname(sf)==g.data_dir)]
|
||||
|
||||
if invoked_as in ('conv','passchg'):
|
||||
msg(green('Processing input wallet')+dw_msg)
|
||||
m1 = green('Processing input wallet')
|
||||
m2 = yellow(' (default wallet)') if sf and os.path.dirname(sf) == g.data_dir else ''
|
||||
msg(m1+m2)
|
||||
|
||||
ss_in = None if invoked_as == 'gen' else SeedSource(sf,passchg=(invoked_as=='passchg'))
|
||||
if invoked_as == 'chk':
|
||||
|
|
@ -130,12 +130,12 @@ if invoked_as == 'chk':
|
|||
sys.exit(0)
|
||||
|
||||
if invoked_as in ('conv','passchg'):
|
||||
msg(green('Processing output wallet'))
|
||||
gmsg('Processing output wallet')
|
||||
|
||||
ss_out = SeedSource(ss=ss_in,passchg=invoked_as=='passchg')
|
||||
|
||||
if invoked_as == 'gen':
|
||||
qmsg("This wallet's Seed ID: %s" % ss_out.seed.sid.hl())
|
||||
qmsg("This wallet's Seed ID: {}".format(ss_out.seed.sid.hl()))
|
||||
|
||||
if invoked_as == 'passchg':
|
||||
if not (opt.force_update or [k for k in ('passwd','hash_preset','label')
|
||||
|
|
@ -155,7 +155,7 @@ if invoked_as == 'passchg' and ss_in.infile.dirname == g.data_dir:
|
|||
try:
|
||||
check_output(sd_cmd + [ss_in.infile.name])
|
||||
except:
|
||||
msg(yellow("WARNING: '%s' command failed, using regular file delete instead" % sd_cmd[0]))
|
||||
ymsg("WARNING: '{}' command failed, using regular file delete instead".format(sd_cmd[0]))
|
||||
# msg('Command output: {}\nReturn value {}'.format(e.output,e.returncode))
|
||||
os.unlink(ss_in.infile.name)
|
||||
elif invoked_as == 'gen' and not find_file_in_dir(Wallet,g.data_dir) \
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ from mmgen.globalvars import g
|
|||
import mmgen.share.Opts
|
||||
from mmgen.util import *
|
||||
|
||||
def usage(): Die(2,'USAGE: %s %s' % (g.prog_name, usage_txt))
|
||||
def usage(): Die(2,'USAGE: {} {}'.format((g.prog_name,usage_txt)))
|
||||
|
||||
def die_on_incompatible_opts(incompat_list):
|
||||
for group in incompat_list:
|
||||
bad = [k for k in opt.__dict__ if opt.__dict__[k] and k in group]
|
||||
if len(bad) > 1:
|
||||
die(1,'Conflicting options: %s' % ', '.join([fmt_opt(b) for b in bad]))
|
||||
die(1,'Conflicting options: {}'.format(', '.join(map(fmt_opt,bad))))
|
||||
|
||||
def fmt_opt(o): return '--' + o.replace('_','-')
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ def _show_hash_presets():
|
|||
msg('Available parameters for scrypt.hash():')
|
||||
msg(fs.format('Preset','N','r','p'))
|
||||
for i in sorted(g.hash_presets.keys()):
|
||||
msg(fs.format("'%s'" % i, *g.hash_presets[i]))
|
||||
msg(fs.format("'{}'".format(i,*g.hash_presets[i])))
|
||||
msg('N = memory usage (power of two), p = iterations (rounds)')
|
||||
|
||||
def opt_preproc_debug(short_opts,long_opts,skipped_opts,uopts,args):
|
||||
|
|
@ -64,9 +64,9 @@ def opt_postproc_debug():
|
|||
Msg(' Opts after processing:')
|
||||
for k in a:
|
||||
v = getattr(opt,k)
|
||||
Msg(' %-18s: %-6s [%s]' % (k,v,type(v).__name__))
|
||||
Msg(' {:18}: {:<6} [{}]'.format(k,v,type(v).__name__))
|
||||
Msg(" Opts set to 'None':")
|
||||
Msg(' %s\n' % '\n '.join(b))
|
||||
Msg(' {}\n'.format('\n '.join(b)))
|
||||
Msg(' Global vars:')
|
||||
for e in [d for d in dir(g) if d[:2] != '__']:
|
||||
Msg(' {:<20}: {}'.format(e, getattr(g,e)))
|
||||
|
|
@ -341,16 +341,15 @@ def opt_is_tx_fee(val,desc):
|
|||
def check_opts(usr_opts): # Returns false if any check fails
|
||||
|
||||
def opt_splits(val,sep,n,desc):
|
||||
sepword = 'comma' if sep == ',' else 'colon' if sep == ':' else "'%s'" % sep
|
||||
sepword = 'comma' if sep == ',' else 'colon' if sep == ':' else "'{}'".format(sep)
|
||||
try: l = val.split(sep)
|
||||
except:
|
||||
msg("'%s': invalid %s (not %s-separated list)" % (val,desc,sepword))
|
||||
msg("'{}': invalid {} (not {}-separated list)".format(val,desc,sepword))
|
||||
return False
|
||||
|
||||
if len(l) == n: return True
|
||||
else:
|
||||
msg("'%s': invalid %s (%s %s-separated items required)" %
|
||||
(val,desc,n,sepword))
|
||||
msg("'{}': invalid {} ({} {}-separated items required)".format(val,desc,n,sepword))
|
||||
return False
|
||||
|
||||
def opt_compares(val,op_str,target,desc,what=''):
|
||||
|
|
@ -385,18 +384,17 @@ def check_opts(usr_opts): # Returns false if any check fails
|
|||
return True
|
||||
|
||||
def opt_unrecognized(key,val,desc):
|
||||
msg("'%s': unrecognized %s for option '%s'"
|
||||
% (val,desc,fmt_opt(key)))
|
||||
msg("'{}': unrecognized {} for option '{}'".format(val,desc,fmt_opt(key)))
|
||||
return False
|
||||
|
||||
def opt_display(key,val='',beg='For selected',end=':\n'):
|
||||
s = '%s=%s' % (fmt_opt(key),val) if val else fmt_opt(key)
|
||||
msg_r("%s option '%s'%s" % (beg,s,end))
|
||||
s = '{}={}'.format(fmt_opt(key),val) if val else fmt_opt(key)
|
||||
msg_r("{} option '{}'{}".format(beg,s,end))
|
||||
|
||||
global opt
|
||||
for key,val in [(k,getattr(opt,k)) for k in usr_opts]:
|
||||
|
||||
desc = "parameter for '%s' option" % fmt_opt(key)
|
||||
desc = "parameter for '{}' option".format(fmt_opt(key))
|
||||
|
||||
from mmgen.util import check_infile,check_outfile,check_outdir
|
||||
# Check for file existence and readability
|
||||
|
|
@ -416,8 +414,9 @@ def check_opts(usr_opts): # Returns false if any check fails
|
|||
if key == 'out_fmt':
|
||||
p = 'hidden_incog_output_params'
|
||||
if sstype == IncogWalletHidden and not getattr(opt,p):
|
||||
die(1,'Hidden incog format output requested. You must supply'
|
||||
+ " a file and offset with the '%s' option" % fmt_opt(p))
|
||||
m1 = 'Hidden incog format output requested. '
|
||||
m2 = "You must supply a file and offset with the '{}' option"
|
||||
die(1,m1+m2.format(fmt_opt(p)))
|
||||
if issubclass(sstype,IncogWallet) and opt.old_incog_fmt:
|
||||
opt_display(key,val,beg='Selected',end=' ')
|
||||
opt_display('old_incog_fmt',beg='conflicts with',end=':\n')
|
||||
|
|
@ -446,10 +445,8 @@ def check_opts(usr_opts): # Returns false if any check fails
|
|||
val2 = getattr(opt,key2)
|
||||
from mmgen.seed import IncogWalletHidden
|
||||
if val2 and val2 not in IncogWalletHidden.fmt_codes:
|
||||
die(1,
|
||||
'Option conflict:\n %s, with\n %s=%s' % (
|
||||
fmt_opt(key),fmt_opt(key2),val2
|
||||
))
|
||||
fs = 'Option conflict:\n {}, with\n {}={}'
|
||||
die(1,fs.format(fmt_opt(key),fmt_opt(key2),val2))
|
||||
elif key == 'seed_len':
|
||||
if not opt_is_int(val,desc): return False
|
||||
if not opt_is_in_list(int(val),g.seed_lens,desc): return False
|
||||
|
|
@ -497,6 +494,6 @@ def check_opts(usr_opts): # Returns false if any check fails
|
|||
if not opt_is_int(val,desc): return False
|
||||
if not opt_compares(val,'>',0,desc): return False
|
||||
else:
|
||||
if g.debug: Msg("check_opts(): No test for opt '%s'" % key)
|
||||
if g.debug: Msg("check_opts(): No test for opt '{}'".format(key))
|
||||
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class CoinDaemonRPCConnection(object):
|
|||
die(args[1],yellow(s))
|
||||
|
||||
dmsg_rpc('=== request() debug ===')
|
||||
dmsg_rpc(' RPC POST data ==> %s\n' % p)
|
||||
dmsg_rpc(' RPC POST data ==> {}\n'.format(p))
|
||||
caller = self
|
||||
class MyJSONEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
|
|
@ -132,7 +132,7 @@ class CoinDaemonRPCConnection(object):
|
|||
m = 'Unable to connect to {} at {}:{} (but port is bound?)'
|
||||
return do_fail(None,2,m.format(g.proto.daemon_name,self.host,self.port))
|
||||
|
||||
dmsg_rpc(' RPC GETRESPONSE data ==> %s\n' % r.__dict__)
|
||||
dmsg_rpc(' RPC GETRESPONSE data ==> {}\n'.format(r.__dict__))
|
||||
|
||||
if r.status != 200:
|
||||
if cf['on_fail'] not in ('silent','raise'):
|
||||
|
|
@ -148,7 +148,7 @@ class CoinDaemonRPCConnection(object):
|
|||
|
||||
r2 = r.read()
|
||||
|
||||
dmsg_rpc(' RPC REPLY data ==> %s\n' % r2)
|
||||
dmsg_rpc(' RPC REPLY data ==> {}\n'.format(r2))
|
||||
|
||||
if not r2:
|
||||
return do_fail(r,2,'Error: empty reply')
|
||||
|
|
|
|||
176
mmgen/seed.py
176
mmgen/seed.py
|
|
@ -32,9 +32,8 @@ pnm = g.proj_name
|
|||
|
||||
def check_usr_seed_len(seed_len):
|
||||
if opt.seed_len != seed_len and 'seed_len' in opt.set_by_user:
|
||||
m = 'ERROR: requested seed length (%s) ' + \
|
||||
"doesn't match seed length of source (%s)"
|
||||
die(1, m % (opt.seed_len,seed_len))
|
||||
m = "ERROR: requested seed length ({}) doesn't match seed length of source ({})"
|
||||
die(1,m.format((opt.seed_len,seed_len)))
|
||||
|
||||
class Seed(MMGenObject):
|
||||
def __init__(self,seed_bin=None):
|
||||
|
|
@ -42,7 +41,7 @@ class Seed(MMGenObject):
|
|||
# Truncate random data for smaller seed lengths
|
||||
seed_bin = sha256(get_random(1033)).digest()[:opt.seed_len/8]
|
||||
elif len(seed_bin)*8 not in g.seed_lens:
|
||||
die(3,'%s: invalid seed length' % len(seed_bin))
|
||||
die(3,'{}: invalid seed length'.format(len(seed_bin)))
|
||||
|
||||
self.data = seed_bin
|
||||
self.hexdata = hexlify(seed_bin)
|
||||
|
|
@ -121,13 +120,12 @@ class SeedSource(MMGenObject):
|
|||
self._decrypt_retry()
|
||||
else:
|
||||
if not self.stdin_ok:
|
||||
die(1,'Reading from standard input not supported for %s format'
|
||||
% self.desc)
|
||||
die(1,'Reading from standard input not supported for {} format'.format(self.desc))
|
||||
self._deformat_retry()
|
||||
self._decrypt_retry()
|
||||
|
||||
m = ('',', seed length %s' % self.seed.length)[self.seed.length!=256]
|
||||
qmsg('Valid %s for Seed ID %s%s' % (self.desc,self.seed.sid.hl(),m))
|
||||
m = ('',', seed length {}'.format(self.seed.length))[self.seed.length!=256]
|
||||
qmsg('Valid {} for Seed ID {}{}'.format(self.desc,self.seed.sid.hl(),m))
|
||||
|
||||
def _get_data(self):
|
||||
if hasattr(self,'infile'):
|
||||
|
|
@ -229,14 +227,14 @@ class SeedSourceUnenc(SeedSource):
|
|||
def _encrypt(self): pass
|
||||
|
||||
def _filename(self):
|
||||
return '%s[%s].%s' % (self.seed.sid,self.seed.length,self.ext)
|
||||
return '{}[{}].{}'.format(self.seed.sid,self.seed.length,self.ext)
|
||||
|
||||
class SeedSourceEnc(SeedSource):
|
||||
|
||||
_msg = {
|
||||
'choose_passphrase': """
|
||||
You must choose a passphrase to encrypt your new %s with.
|
||||
A key will be generated from your passphrase using a hash preset of '%s'.
|
||||
You must choose a passphrase to encrypt your new {} with.
|
||||
A key will be generated from your passphrase using a hash preset of '{}'.
|
||||
Please note that no strength checking of passphrases is performed. For
|
||||
an empty passphrase, just hit ENTER twice.
|
||||
""".strip()
|
||||
|
|
@ -263,8 +261,7 @@ an empty passphrase, just hit ENTER twice.
|
|||
self.ssdata.hash_preset = ret
|
||||
return ret
|
||||
else:
|
||||
msg('Invalid input. Valid choices are %s' %
|
||||
', '.join(sorted(g.hash_presets.keys())))
|
||||
msg('Invalid input. Valid choices are {}'.format(', '.join(sorted(g.hash_presets.keys()))))
|
||||
else:
|
||||
self.ssdata.hash_preset = hp
|
||||
return hp
|
||||
|
|
@ -273,21 +270,20 @@ an empty passphrase, just hit ENTER twice.
|
|||
if hasattr(self,'ss_in') and hasattr(self.ss_in.ssdata,'hash_preset'):
|
||||
old_hp = self.ss_in.ssdata.hash_preset
|
||||
if opt.keep_hash_preset:
|
||||
qmsg("Reusing hash preset '%s' at user request" % old_hp)
|
||||
qmsg("Reusing hash preset '{}' at user request".format(old_hp))
|
||||
self.ssdata.hash_preset = old_hp
|
||||
elif 'hash_preset' in opt.set_by_user:
|
||||
hp = self.ssdata.hash_preset = opt.hash_preset
|
||||
qmsg("Using hash preset '%s' requested on command line"
|
||||
% opt.hash_preset)
|
||||
qmsg("Using hash preset '{}' requested on command line".format(opt.hash_preset))
|
||||
else: # Prompt, using old value as default
|
||||
hp = self._get_hash_preset_from_user(old_hp,desc_suf)
|
||||
|
||||
if (not opt.keep_hash_preset) and self.op == 'pwchg_new':
|
||||
m = ("changed to '%s'" % hp,'unchanged')[hp==old_hp]
|
||||
qmsg('Hash preset %s' % m)
|
||||
m = ("changed to '{}'".format(hp),'unchanged')[hp==old_hp]
|
||||
qmsg('Hash preset {}'.format(m))
|
||||
elif 'hash_preset' in opt.set_by_user:
|
||||
self.ssdata.hash_preset = opt.hash_preset
|
||||
qmsg("Using hash preset '%s' requested on command line"%opt.hash_preset)
|
||||
qmsg("Using hash preset '{}' requested on command line".format(opt.hash_preset))
|
||||
else:
|
||||
self._get_hash_preset_from_user(opt.hash_preset,desc_suf)
|
||||
|
||||
|
|
@ -301,18 +297,17 @@ an empty passphrase, just hit ENTER twice.
|
|||
w = pwfile_reuse_warning()
|
||||
pw = ' '.join(get_words_from_file(opt.passwd_file,desc,silent=w))
|
||||
elif opt.echo_passphrase:
|
||||
pw = ' '.join(get_words_from_user('Enter %s: ' % desc))
|
||||
pw = ' '.join(get_words_from_user('Enter {}: '.format(desc)))
|
||||
else:
|
||||
for i in range(g.passwd_max_tries):
|
||||
pw = ' '.join(get_words_from_user('Enter %s: ' % desc))
|
||||
pw = ' '.join(get_words_from_user('Enter {}: '.format(desc)))
|
||||
pw2 = ' '.join(get_words_from_user('Repeat passphrase: '))
|
||||
dmsg('Passphrases: [%s] [%s]' % (pw,pw2))
|
||||
dmsg('Passphrases: [{}] [{}]'.format(pw,pw2))
|
||||
if pw == pw2:
|
||||
vmsg('Passphrases match'); break
|
||||
else: msg('Passphrases do not match. Try again.')
|
||||
else:
|
||||
die(2,'User failed to duplicate passphrase in %s attempts' %
|
||||
g.passwd_max_tries)
|
||||
die(2,'User failed to duplicate passphrase in {} attempts'.format(g.passwd_max_tries))
|
||||
|
||||
if pw == '': qmsg('WARNING: Empty passphrase')
|
||||
self.ssdata.passwd = pw
|
||||
|
|
@ -328,7 +323,7 @@ an empty passphrase, just hit ENTER twice.
|
|||
w = pwfile_reuse_warning()
|
||||
ret = ' '.join(get_words_from_file(opt.passwd_file,desc,silent=w))
|
||||
else:
|
||||
ret = ' '.join(get_words_from_user('Enter %s: ' % desc))
|
||||
ret = ' '.join(get_words_from_user('Enter {}: '.format(desc)))
|
||||
self.ssdata.passwd = ret
|
||||
|
||||
def _get_first_pw_and_hp_and_encrypt_seed(self):
|
||||
|
|
@ -344,9 +339,9 @@ an empty passphrase, just hit ENTER twice.
|
|||
pw = self._get_new_passphrase()
|
||||
if self.op == 'pwchg_new':
|
||||
m = ('changed','unchanged')[pw==old_pw]
|
||||
qmsg('Passphrase %s' % m)
|
||||
qmsg('Passphrase {}'.format(m))
|
||||
else:
|
||||
qmsg(self.msg['choose_passphrase'] % (self.desc,d.hash_preset))
|
||||
qmsg(self.msg['choose_passphrase'].format(self.desc,d.hash_preset))
|
||||
self._get_new_passphrase()
|
||||
|
||||
d.salt = sha256(get_random(128)).digest()[:g.salt_len]
|
||||
|
|
@ -449,7 +444,7 @@ class Mnemonic (SeedSourceUnenc):
|
|||
|
||||
for n,w in enumerate(mn,1):
|
||||
if w not in baseconv.digits[self.wl_id]:
|
||||
msg('Invalid mnemonic: word #%s is not in the wordlist' % n)
|
||||
msg('Invalid mnemonic: word #{} is not in the wordlist'.format(n))
|
||||
return False
|
||||
|
||||
hexseed = baseconv.tohex(mn,self.wl_id,self._mn2hex_pad(mn))
|
||||
|
|
@ -480,30 +475,27 @@ class SeedFile (SeedSourceUnenc):
|
|||
b58seed = baseconv.b58encode(self.seed.data,pad=True)
|
||||
self.ssdata.chksum = make_chksum_6(b58seed)
|
||||
self.ssdata.b58seed = b58seed
|
||||
self.fmt_data = '%s %s\n' % (
|
||||
self.ssdata.chksum,
|
||||
split_into_cols(4,b58seed)
|
||||
)
|
||||
self.fmt_data = '{} {}\n'.format(self.ssdata.chksum,split_into_cols(4,b58seed))
|
||||
|
||||
def _deformat(self):
|
||||
desc = self.desc
|
||||
ld = self.fmt_data.split()
|
||||
|
||||
if not (7 <= len(ld) <= 12): # 6 <= padded b58 data (ld[1:]) <= 11
|
||||
msg('Invalid data length (%s) in %s' % (len(ld),desc))
|
||||
msg('Invalid data length ({}) in {}'.format(len(ld),desc))
|
||||
return False
|
||||
|
||||
a,b = ld[0],''.join(ld[1:])
|
||||
|
||||
if not is_chksum_6(a):
|
||||
msg("'%s': invalid checksum format in %s" % (a, desc))
|
||||
msg("'{}': invalid checksum format in {}".format(a, desc))
|
||||
return False
|
||||
|
||||
if not is_b58_str(b):
|
||||
msg("'%s': not a base 58 string, in %s" % (b, desc))
|
||||
msg("'{}': not a base 58 string, in {}".format(b, desc))
|
||||
return False
|
||||
|
||||
vmsg_r('Validating %s checksum...' % desc)
|
||||
vmsg_r('Validating {} checksum...'.format(desc))
|
||||
|
||||
if not compare_chksums(a,'file',make_chksum_6(b),'computed',verbose=True):
|
||||
return False
|
||||
|
|
@ -511,7 +503,7 @@ class SeedFile (SeedSourceUnenc):
|
|||
ret = baseconv.b58decode(b,pad=True)
|
||||
|
||||
if ret == False:
|
||||
msg('Invalid base-58 encoded seed: %s' % val)
|
||||
msg('Invalid base-58 encoded seed: {}'.format(val))
|
||||
return False
|
||||
|
||||
self.seed = Seed(ret)
|
||||
|
|
@ -533,7 +525,7 @@ class HexSeedFile (SeedSourceUnenc):
|
|||
h = self.seed.hexdata
|
||||
self.ssdata.chksum = make_chksum_6(h)
|
||||
self.ssdata.hexseed = h
|
||||
self.fmt_data = '%s %s\n' % (self.ssdata.chksum, split_into_cols(4,h))
|
||||
self.fmt_data = '{} {}\n'.format(self.ssdata.chksum, split_into_cols(4,h))
|
||||
|
||||
def _deformat(self):
|
||||
desc = self.desc
|
||||
|
|
@ -542,22 +534,22 @@ class HexSeedFile (SeedSourceUnenc):
|
|||
d[1]
|
||||
chk,hstr = d[0],''.join(d[1:])
|
||||
except:
|
||||
msg("'%s': invalid %s" % (self.fmt_data.strip(),desc))
|
||||
msg("'{}': invalid {}".format(self.fmt_data.strip(),desc))
|
||||
return False
|
||||
|
||||
if not len(hstr)*4 in g.seed_lens:
|
||||
msg('Invalid data length (%s) in %s' % (len(hstr),desc))
|
||||
msg('Invalid data length ({}) in {}'.format(len(hstr),desc))
|
||||
return False
|
||||
|
||||
if not is_chksum_6(chk):
|
||||
msg("'%s': invalid checksum format in %s" % (chk, desc))
|
||||
msg("'{}': invalid checksum format in {}".format(chk, desc))
|
||||
return False
|
||||
|
||||
if not is_hex_str(hstr):
|
||||
msg("'%s': not a hexadecimal string, in %s" % (hstr, desc))
|
||||
msg("'{}': not a hexadecimal string, in {}".format(hstr, desc))
|
||||
return False
|
||||
|
||||
vmsg_r('Validating %s checksum...' % desc)
|
||||
vmsg_r('Validating {} checksum...'.format(desc))
|
||||
|
||||
if not compare_chksums(chk,'file',make_chksum_6(hstr),'computed',verbose=True):
|
||||
return False
|
||||
|
|
@ -577,8 +569,8 @@ class Wallet (SeedSourceEnc):
|
|||
ext = 'mmdat'
|
||||
|
||||
def _get_label_from_user(self,old_lbl=''):
|
||||
d = ("to reuse the label '%s'" % old_lbl.hl()) if old_lbl else 'for no label'
|
||||
p = 'Enter a wallet label, or hit ENTER %s: ' % d
|
||||
d = "to reuse the label '{}'".format(old_lbl.hl()) if old_lbl else 'for no label'
|
||||
p = 'Enter a wallet label, or hit ENTER {}: '.format(d)
|
||||
while True:
|
||||
msg_r(p)
|
||||
ret = my_raw_input('')
|
||||
|
|
@ -598,19 +590,19 @@ class Wallet (SeedSourceEnc):
|
|||
if hasattr(self,'ss_in') and hasattr(self.ss_in.ssdata,'label'):
|
||||
old_lbl = self.ss_in.ssdata.label
|
||||
if opt.keep_label:
|
||||
qmsg("Reusing label '%s' at user request" % old_lbl.hl())
|
||||
qmsg("Reusing label '{}' at user request".format(old_lbl.hl()))
|
||||
self.ssdata.label = old_lbl
|
||||
elif opt.label:
|
||||
qmsg("Using label '%s' requested on command line" % opt.label.hl())
|
||||
qmsg("Using label '{}' requested on command line".format(opt.label.hl()))
|
||||
lbl = self.ssdata.label = opt.label
|
||||
else: # Prompt, using old value as default
|
||||
lbl = self._get_label_from_user(old_lbl)
|
||||
|
||||
if (not opt.keep_label) and self.op == 'pwchg_new':
|
||||
m = ("changed to '%s'" % lbl,'unchanged')[lbl==old_lbl]
|
||||
qmsg('Label %s' % m)
|
||||
m = ("changed to '{}'".format(lbl),'unchanged')[lbl==old_lbl]
|
||||
qmsg('Label {}'.format(m))
|
||||
elif opt.label:
|
||||
qmsg("Using label '%s' requested on command line" % opt.label.hl())
|
||||
qmsg("Using label '{}' requested on command line".format(opt.label.hl()))
|
||||
self.ssdata.label = opt.label
|
||||
else:
|
||||
self._get_label_from_user()
|
||||
|
|
@ -636,20 +628,18 @@ class Wallet (SeedSourceEnc):
|
|||
'{} {}'.format(make_chksum_6(es_fmt), split_into_cols(4,es_fmt))
|
||||
)
|
||||
chksum = make_chksum_6(' '.join(lines))
|
||||
self.fmt_data = '%s\n' % '\n'.join((chksum,)+lines)
|
||||
self.fmt_data = '{}\n'.format('\n'.join((chksum,)+lines))
|
||||
|
||||
def _deformat(self):
|
||||
|
||||
def check_master_chksum(lines,desc):
|
||||
|
||||
if len(lines) != 6:
|
||||
msg('Invalid number of lines (%s) in %s data' %
|
||||
(len(lines),desc))
|
||||
msg('Invalid number of lines ({}) in {} data'.format(len(lines),desc))
|
||||
return False
|
||||
|
||||
if not is_chksum_6(lines[0]):
|
||||
msg('Incorrect master checksum (%s) in %s data' %
|
||||
(lines[0],desc))
|
||||
msg('Incorrect master checksum ({}) in {} data'.format(lines[0],desc))
|
||||
return False
|
||||
|
||||
chk = make_chksum_6(' '.join(lines[1:]))
|
||||
|
|
@ -674,17 +664,16 @@ class Wallet (SeedSourceEnc):
|
|||
hpdata = lines[3].split()
|
||||
|
||||
d.hash_preset = hp = hpdata[0][:-1] # a string!
|
||||
qmsg("Hash preset of wallet: '%s'" % hp)
|
||||
qmsg("Hash preset of wallet: '{}'".format(hp))
|
||||
if 'hash_preset' in opt.set_by_user:
|
||||
uhp = opt.hash_preset
|
||||
if uhp != hp:
|
||||
qmsg("Warning: ignoring user-requested hash preset '%s'" % uhp)
|
||||
qmsg("Warning: ignoring user-requested hash preset '{}'".format(uhp))
|
||||
|
||||
hash_params = map(int,hpdata[1:])
|
||||
|
||||
if hash_params != get_hash_params(d.hash_preset):
|
||||
msg("Hash parameters '%s' don't match hash preset '%s'" %
|
||||
(' '.join(hash_params), d.hash_preset))
|
||||
msg("Hash parameters '{}' don't match hash preset '{}'".format(' '.join(hash_params),d.hash_preset))
|
||||
return False
|
||||
|
||||
lmin,foo,lmax = [v for k,v in baseconv.b58pad_lens] # 22,33,44
|
||||
|
|
@ -694,7 +683,7 @@ class Wallet (SeedSourceEnc):
|
|||
b58_val = ''.join(l)
|
||||
|
||||
if len(b58_val) < lmin or len(b58_val) > lmax:
|
||||
msg('Invalid format for %s in %s: %s' % (key,self.desc,l))
|
||||
msg('Invalid format for {} in {}: {}'.format(key,self.desc,l))
|
||||
return False
|
||||
|
||||
if not compare_chksums(chk,key,
|
||||
|
|
@ -703,7 +692,7 @@ class Wallet (SeedSourceEnc):
|
|||
|
||||
val = baseconv.b58decode(b58_val,pad=True)
|
||||
if val == False:
|
||||
msg('Invalid base 58 number: %s' % b58_val)
|
||||
msg('Invalid base 58 number: {}'.format(b58_val))
|
||||
return False
|
||||
|
||||
setattr(d,key,val)
|
||||
|
|
@ -756,9 +745,9 @@ class Brainwallet (SeedSourceEnc):
|
|||
seed_len,d.hash_preset = self.get_bw_params()
|
||||
else:
|
||||
if 'seed_len' not in opt.set_by_user:
|
||||
m1 = 'Using default seed length of %s bits'
|
||||
m1 = 'Using default seed length of {} bits\n'
|
||||
m2 = 'If this is not what you want, use the --seed-len option'
|
||||
qmsg((m1+'\n'+m2) % yellow(str(opt.seed_len)))
|
||||
qmsg((m1+m2).format(yellow(str(opt.seed_len))))
|
||||
self._get_hash_preset()
|
||||
seed_len = opt.seed_len
|
||||
qmsg_r('Hashing brainwallet data. Please wait...')
|
||||
|
|
@ -767,7 +756,7 @@ class Brainwallet (SeedSourceEnc):
|
|||
d.hash_preset, buflen=seed_len/8)
|
||||
qmsg('Done')
|
||||
self.seed = Seed(seed)
|
||||
msg('Seed ID: %s' % self.seed.sid)
|
||||
msg('Seed ID: {}'.format(self.seed.sid))
|
||||
qmsg('Check this value against your records')
|
||||
return True
|
||||
|
||||
|
|
@ -796,7 +785,7 @@ Try again? (Y)es, (n)o, (m)ore information:
|
|||
If the Seed ID above is correct but you're seeing this message, then you need
|
||||
to exit and re-run the program with the '--old-incog-fmt' option.
|
||||
""".strip(),
|
||||
'dec_chk': " %s hash preset"
|
||||
'dec_chk': " {} hash preset"
|
||||
}
|
||||
|
||||
def _make_iv_chksum(self,s): return sha256(s).hexdigest()[:8].upper()
|
||||
|
|
@ -813,16 +802,14 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
return True
|
||||
else:
|
||||
if opt.old_incog_fmt:
|
||||
msg('WARNING: old-style incognito format requested. ' +
|
||||
'Are you sure this is correct?')
|
||||
msg(('Invalid incognito data size (%s bytes) for this ' +
|
||||
'seed length (%s bits)') % (dlen,opt.seed_len))
|
||||
msg('Valid data size for this seed length: %s bytes' % valid_dlen)
|
||||
msg('WARNING: old-style incognito format requested. Are you sure this is correct?')
|
||||
m = 'Invalid incognito data size ({} bytes) for this seed length ({} bits)'
|
||||
msg(m.format(dlen,opt.seed_len))
|
||||
msg('Valid data size for this seed length: {} bytes'.format(valid_dlen))
|
||||
for sl in g.seed_lens:
|
||||
if dlen == self._get_incog_data_len(sl):
|
||||
die(1,'Valid seed length for this data size: %s bits' % sl)
|
||||
msg(('This data size (%s bytes) is invalid for all available ' +
|
||||
'seed lengths') % dlen)
|
||||
die(1,'Valid seed length for this data size: {} bits'.format(sl))
|
||||
msg('This data size ({} bytes) is invalid for all available seed lengths'.format(dlen))
|
||||
return False
|
||||
|
||||
def _encrypt (self):
|
||||
|
|
@ -833,7 +820,7 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
# IV is used BOTH to initialize counter and to salt password!
|
||||
d.iv = get_random(g.aesctr_iv_len)
|
||||
d.iv_id = self._make_iv_chksum(d.iv)
|
||||
msg('New Incog Wallet ID: %s' % d.iv_id)
|
||||
msg('New Incog Wallet ID: {}'.format(d.iv_id))
|
||||
qmsg('Make a record of this value')
|
||||
vmsg(self.msg['record_incog_id'])
|
||||
|
||||
|
|
@ -844,7 +831,7 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
|
||||
d.wrapper_key = make_key(d.passwd, d.iv, d.hash_preset, 'incog wrapper key')
|
||||
d.key_id = make_chksum_8(d.wrapper_key)
|
||||
vmsg('Key ID: %s' % d.key_id)
|
||||
vmsg('Key ID: {}'.format(d.key_id))
|
||||
d.target_data_len = self._get_incog_data_len(self.seed.length)
|
||||
|
||||
def _format(self):
|
||||
|
|
@ -876,7 +863,7 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
d.iv = self.fmt_data[0:g.aesctr_iv_len]
|
||||
d.incog_id = self._make_iv_chksum(d.iv)
|
||||
d.enc_incog_data = self.fmt_data[g.aesctr_iv_len:]
|
||||
msg('Incog Wallet ID: %s' % d.incog_id)
|
||||
msg('Incog Wallet ID: {}'.format(d.incog_id))
|
||||
qmsg('Check this value against your records')
|
||||
vmsg(self.msg['check_incog_id'])
|
||||
|
||||
|
|
@ -885,14 +872,14 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
def _verify_seed_newfmt(self,data):
|
||||
chk,seed = data[:8],data[8:]
|
||||
if sha256(seed).digest()[:8] == chk:
|
||||
qmsg('Passphrase%s are correct' % (self.msg['dec_chk'] % 'and'))
|
||||
qmsg('Passphrase{} are correct'.format(self.msg['dec_chk'].format('and')))
|
||||
return seed
|
||||
else:
|
||||
msg('Incorrect passphrase%s' % (self.msg['dec_chk'] % 'or'))
|
||||
msg('Incorrect passphrase{}'.format(self.msg['dec_chk'].format('or')))
|
||||
return False
|
||||
|
||||
def _verify_seed_oldfmt(self,seed):
|
||||
m = 'Seed ID: %s. Is the Seed ID correct?' % make_chksum_8(seed)
|
||||
m = 'Seed ID: {}. Is the Seed ID correct?'.format(make_chksum_8(seed))
|
||||
if keypress_confirm(m, True):
|
||||
return seed
|
||||
else:
|
||||
|
|
@ -912,7 +899,7 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
d.enc_seed = dd[g.salt_len:]
|
||||
|
||||
key = make_key(d.passwd, d.salt, d.hash_preset, 'main key')
|
||||
qmsg('Key ID: %s' % make_chksum_8(key))
|
||||
qmsg('Key ID: {}'.format(make_chksum_8(key)))
|
||||
|
||||
verify_seed = getattr(self,'_verify_seed_'+
|
||||
('newfmt','oldfmt')[bool(opt.old_incog_fmt)])
|
||||
|
|
@ -921,7 +908,7 @@ to exit and re-run the program with the '--old-incog-fmt' option.
|
|||
|
||||
if seed:
|
||||
self.seed = Seed(seed)
|
||||
msg('Seed ID: %s' % self.seed.sid)
|
||||
msg('Seed ID: {}'.format(self.seed.sid))
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
|
@ -969,7 +956,7 @@ harder to find, you're advised to choose a much larger file size than this.
|
|||
identify the incog wallet data in the future and to locate the offset
|
||||
where the data is hidden in the event you forget it.
|
||||
""",
|
||||
'dec_chk': ', hash preset, offset %s seed length'
|
||||
'dec_chk': ', hash preset, offset {} seed length'
|
||||
}
|
||||
|
||||
def _get_hincog_params(self,wtype):
|
||||
|
|
@ -980,15 +967,14 @@ harder to find, you're advised to choose a much larger file size than this.
|
|||
d = self.ssdata
|
||||
m = ('Input','Destination')[action=='write']
|
||||
if fn.size < d.hincog_offset + d.target_data_len:
|
||||
die(1,
|
||||
"%s file '%s' has length %s, too short to %s %s bytes of data at offset %s"
|
||||
% (m,fn.name,fn.size,action,d.target_data_len,d.hincog_offset))
|
||||
fs = "{} file '{}' has length {}, too short to {} {} bytes of data at offset {}"
|
||||
die(1,fs.format(m,fn.name,fn.size,action,d.target_data_len,d.hincog_offset))
|
||||
|
||||
def _get_data(self):
|
||||
d = self.ssdata
|
||||
d.hincog_offset = self._get_hincog_params('input')[1]
|
||||
|
||||
qmsg("Getting hidden incog data from file '%s'" % self.infile.name)
|
||||
qmsg("Getting hidden incog data from file '{}'".format(self.infile.name))
|
||||
|
||||
# Already sanity-checked:
|
||||
d.target_data_len = self._get_incog_data_len(opt.seed_len)
|
||||
|
|
@ -999,8 +985,7 @@ harder to find, you're advised to choose a much larger file size than this.
|
|||
os.lseek(fh,int(d.hincog_offset),os.SEEK_SET)
|
||||
self.fmt_data = os.read(fh,d.target_data_len)
|
||||
os.close(fh)
|
||||
qmsg("Data read from file '%s' at offset %s" %
|
||||
(self.infile.name,d.hincog_offset), 'Data read from file')
|
||||
qmsg("Data read from file '{}' at offset {}".format(self.infile.name,d.hincog_offset))
|
||||
|
||||
# overrides method in SeedSource
|
||||
def write_to_file(self):
|
||||
|
|
@ -1019,15 +1004,13 @@ harder to find, you're advised to choose a much larger file size than this.
|
|||
try:
|
||||
os.stat(fn)
|
||||
except:
|
||||
if keypress_confirm("Requested file '%s' does not exist. Create?"
|
||||
% fn, default_yes=True):
|
||||
if keypress_confirm("Requested file '{}' does not exist. Create?".format(fn),default_yes=True):
|
||||
min_fsize = d.target_data_len + d.hincog_offset
|
||||
msg(self.msg['choose_file_size'].format(min_fsize))
|
||||
while True:
|
||||
fsize = parse_nbytes(my_raw_input('Enter file size: '))
|
||||
if fsize >= min_fsize: break
|
||||
msg('File size must be an integer no less than %s' %
|
||||
min_fsize)
|
||||
msg('File size must be an integer no less than {}'.format(min_fsize))
|
||||
|
||||
from mmgen.tool import Rand2file # threaded routine
|
||||
Rand2file(fn,str(fsize))
|
||||
|
|
@ -1037,17 +1020,16 @@ harder to find, you're advised to choose a much larger file size than this.
|
|||
|
||||
f = Filename(fn,ftype=type(self),write=True)
|
||||
|
||||
dmsg('%s data len %s, offset %s' % (
|
||||
capfirst(self.desc),d.target_data_len,d.hincog_offset))
|
||||
dmsg('{} data len {}, offset {}'.format(capfirst(self.desc),d.target_data_len,d.hincog_offset))
|
||||
|
||||
if check_offset:
|
||||
self._check_valid_offset(f,'write')
|
||||
if not opt.quiet: confirm_or_exit('',"alter file '%s'" % f.name)
|
||||
if not opt.quiet:
|
||||
confirm_or_exit('',"alter file '{}'".format(f.name))
|
||||
|
||||
flgs = os.O_RDWR|os.O_BINARY if g.platform == 'win' else os.O_RDWR
|
||||
fh = os.open(f.name,flgs)
|
||||
os.lseek(fh, int(d.hincog_offset), os.SEEK_SET)
|
||||
os.write(fh, self.fmt_data)
|
||||
os.close(fh)
|
||||
msg("%s written to file '%s' at offset %s" % (
|
||||
capfirst(self.desc),f.name,d.hincog_offset))
|
||||
msg("{} written to file '{}' at offset {}".format(capfirst(self.desc),f.name,d.hincog_offset))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import sys,getopt
|
|||
# from mmgen.util import mdie,die,pdie,pmsg # DEBUG
|
||||
|
||||
def usage(opts_data):
|
||||
print('USAGE: %s %s' % (opts_data['prog_name'], opts_data['usage']))
|
||||
print('USAGE: {} {}'.format(opts_data['prog_name'], opts_data['usage']))
|
||||
sys.exit(2)
|
||||
|
||||
def print_help_and_exit(opts_data,longhelp=False):
|
||||
|
|
@ -81,10 +81,9 @@ def process_opts(argv,opts_data,short_opts,long_opts,defer_help=False):
|
|||
if (v and v_in == bool) or v == v_in:
|
||||
if o_out in opts and opts[o_out] != v_out:
|
||||
sys.stderr.write(
|
||||
'Option conflict:\n --%s=%s, with\n --%s=%s\n' % (
|
||||
o_out.replace('_','-'),opts[o_out],
|
||||
o_in.replace('_','-'),opts[o_in]
|
||||
))
|
||||
'Option conflict:\n --{}={}, with\n --{}={}\n'.format(
|
||||
o_out.replace('_','-'),opts[o_out],
|
||||
o_in.replace('_','-'),opts[o_in]))
|
||||
sys.exit(1)
|
||||
else:
|
||||
opts[o_out] = v_out
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ def cleandir(d):
|
|||
try: files = os.listdir(d)
|
||||
except: return
|
||||
|
||||
msg(green("Cleaning directory '%s'" % d))
|
||||
gmsg("Cleaning directory '{}'".format(d))
|
||||
for f in files:
|
||||
try:
|
||||
os.unlink(os.path.join(d,f))
|
||||
|
|
@ -49,7 +49,7 @@ def mk_tmpdir(d):
|
|||
except OSError as e:
|
||||
if e.errno != 17: raise
|
||||
else:
|
||||
vmsg("Created directory '%s'" % d)
|
||||
vmsg("Created directory '{}'".format(d))
|
||||
|
||||
def mk_tmpdir_path(path,cfg):
|
||||
try:
|
||||
|
|
@ -64,7 +64,7 @@ def mk_tmpdir_path(path,cfg):
|
|||
os.symlink(src,cfg['tmpdir'])
|
||||
except OSError as e:
|
||||
if e.errno != 17: raise
|
||||
else: msg("Created directory '%s'" % cfg['tmpdir'])
|
||||
else: msg("Created directory '{}'".format(cfg['tmpdir']))
|
||||
|
||||
def get_tmpfile_fn(cfg,fn):
|
||||
return os.path.join(cfg['tmpdir'],fn)
|
||||
|
|
@ -87,7 +87,7 @@ def read_from_tmpfile(cfg,fn,binary=False):
|
|||
def ok():
|
||||
if opt.profile: return
|
||||
if opt.verbose or opt.exact_output:
|
||||
sys.stderr.write(green('OK\n'))
|
||||
gmsg('OK')
|
||||
else: msg(' OK')
|
||||
|
||||
def ok_or_die(val,chk_func,s,skip_ok=False):
|
||||
|
|
@ -96,17 +96,14 @@ def ok_or_die(val,chk_func,s,skip_ok=False):
|
|||
if ret:
|
||||
if not skip_ok: ok()
|
||||
else:
|
||||
msg(red("Returned value '%s' is not a %s" % (val,s)))
|
||||
sys.exit(3)
|
||||
rdie(3,"Returned value '{}' is not a {}".format((val,s)))
|
||||
|
||||
def cmp_or_die(s,t,skip_ok=False):
|
||||
if s == t:
|
||||
if not skip_ok: ok()
|
||||
else:
|
||||
sys.stderr.write(red(
|
||||
'ERROR: recoded data:\n%s\ndiffers from original data:\n%s\n' %
|
||||
(repr(t),repr(s))))
|
||||
sys.exit(3)
|
||||
m = 'ERROR: recoded data:\n{}\ndiffers from original data:\n{}'
|
||||
rdie(3,m.format(repr(t),repr(s)))
|
||||
|
||||
def init_coverage():
|
||||
coverdir = os.path.join('test','trace')
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ def usage(command):
|
|||
c,h = line.split('-',1)
|
||||
Msg('MMGEN-TOOL {}: {}'.format(c.strip().upper(),h.strip()))
|
||||
cd = cmd_data[Command]
|
||||
msg('USAGE: {} {} {}'.format(g.prog_name,command,' '.join(cd)))
|
||||
msg('USAGE: {} {} {}'.format(g.prog_name,command.lower(),' '.join(cd)))
|
||||
else:
|
||||
msg("'{}': no such tool command".format(command))
|
||||
sys.exit(1)
|
||||
|
|
|
|||
30
mmgen/tw.py
30
mmgen/tw.py
|
|
@ -103,7 +103,7 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
|
|||
'addr': lambda i: i.addr,
|
||||
'age': lambda i: 0 - i.confs,
|
||||
'amt': lambda i: i.amt,
|
||||
'txid': lambda i: '%s %03s' % (i.txid,i.vout),
|
||||
'txid': lambda i: '{} {:04}'.format(i.txid,i.vout),
|
||||
'mmid': lambda i: i.twmmid.sort_key
|
||||
}
|
||||
key = key or self.sort_key
|
||||
|
|
@ -173,12 +173,11 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
|
|||
else i.twmmid if i.twmmid.type=='mmgen'
|
||||
else 'Non-{}'.format(g.proj_name),width=mmid_w,color=True)
|
||||
if self.show_mmid:
|
||||
addr_out = '%s %s' % (
|
||||
addr_out = '{} {}'.format(
|
||||
type(i.addr).fmtc(addr_dots,width=btaddr_w,color=True) if i.skip == 'addr' \
|
||||
else i.addr.fmt(width=btaddr_w,color=True),
|
||||
else i.addr.fmt(width=btaddr_w,color=True),
|
||||
'{} {}'.format(mmid_disp,i.label.fmt(width=label_w,color=True) \
|
||||
if label_w > 0 else '')
|
||||
)
|
||||
if label_w > 0 else ''))
|
||||
else:
|
||||
addr_out = type(i.addr).fmtc(addr_dots,width=addr_w,color=True) \
|
||||
if i.skip=='addr' else i.addr.fmt(width=addr_w,color=True)
|
||||
|
|
@ -239,18 +238,17 @@ watch-only wallet using '{}-addrimport' and then re-run this program.
|
|||
if ret == 'q': return None,None
|
||||
n = AddrIdx(ret,on_fail='silent') # hacky way to test and convert to integer
|
||||
if not n or n < 1 or n > len(self.unspent):
|
||||
msg('Choice must be a single number between 1 and %s' % len(self.unspent))
|
||||
msg('Choice must be a single number between 1 and {}'.format(len(self.unspent)))
|
||||
# elif not self.unspent[n-1].mmid:
|
||||
# msg('Address #%s is not an %s address. No label can be added to it' %
|
||||
# (n,g.proj_name))
|
||||
# msg('Address #{} is not an {} address. No label can be added to it'.format(n,g.proj_name))
|
||||
else:
|
||||
while True:
|
||||
s = my_raw_input("Enter label text (or 'q' to return to main menu): ")
|
||||
if s == 'q':
|
||||
return None,None
|
||||
elif s == '':
|
||||
if keypress_confirm(
|
||||
"Removing label for address #%s. Is this what you want?" % n):
|
||||
fs = "Removing label for address #{}. Is this what you want?"
|
||||
if keypress_confirm(fs.format(n)):
|
||||
return n,s
|
||||
elif s:
|
||||
if TwComment(s,on_fail='return'):
|
||||
|
|
@ -274,7 +272,7 @@ Display options: show [D]ays, [g]roup, show [m]mgen addr, r[e]draw screen
|
|||
elif reply == 'A': self.do_sort('age')
|
||||
elif reply == 'd': self.do_sort('addr')
|
||||
elif reply == 'D': self.show_days = not self.show_days
|
||||
elif reply == 'e': msg('\n%s\n%s\n%s' % (self.fmt_display,prompt,p))
|
||||
elif reply == 'e': msg('\n{}\n{}\n{}'.format(self.fmt_display,prompt,p))
|
||||
elif reply == 'g': self.group = not self.group
|
||||
elif reply == 'l':
|
||||
idx,lbl = self.get_idx_and_label_from_user()
|
||||
|
|
@ -283,17 +281,17 @@ Display options: show [D]ays, [g]roup, show [m]mgen addr, r[e]draw screen
|
|||
if type(self).add_label(e.twmmid,lbl,addr=e.addr):
|
||||
self.get_unspent_data()
|
||||
self.do_sort()
|
||||
msg('%s\n%s\n%s' % (self.fmt_display,prompt,p))
|
||||
msg('{}\n{}\n{}'.format(self.fmt_display,prompt,p))
|
||||
else:
|
||||
msg('Label could not be added\n%s\n%s' % (prompt,p))
|
||||
msg('Label could not be added\n{}\n{}'.format(prompt,p))
|
||||
elif reply == 'M': self.do_sort('mmid'); self.show_mmid = True
|
||||
elif reply == 'm': self.show_mmid = not self.show_mmid
|
||||
elif reply == 'p':
|
||||
msg('')
|
||||
of = 'listunspent[%s].out' % ','.join(self.sort_info(include_group=False)).lower()
|
||||
of = 'listunspent[{}].out'.format(','.join(self.sort_info(include_group=False))).lower()
|
||||
write_data_to_file(of,self.format_for_printing(),'unspent outputs listing')
|
||||
m = yellow("Data written to '%s'" % of)
|
||||
msg('\n%s\n%s\n\n%s' % (self.fmt_display,m,prompt))
|
||||
m = yellow("Data written to '{}'".format(of))
|
||||
msg('\n{}\n{}\n\n{}'.format(self.fmt_display,m,prompt))
|
||||
continue
|
||||
elif reply == 'q': return self.unspent
|
||||
elif reply == 'r': self.unspent.reverse(); self.reverse = not self.reverse
|
||||
|
|
|
|||
13
mmgen/tx.py
13
mmgen/tx.py
|
|
@ -87,7 +87,7 @@ def select_unspent(unspent,prompt):
|
|||
if selected:
|
||||
if selected[-1] <= len(unspent):
|
||||
return selected
|
||||
msg('Unspent output number must be <= %s' % len(unspent))
|
||||
msg('Unspent output number must be <= {}'.format(len(unspent)))
|
||||
|
||||
def mmaddr2coinaddr(mmaddr,ad_w,ad_f):
|
||||
|
||||
|
|
@ -381,12 +381,13 @@ class MMGenTX(MMGenObject):
|
|||
d = g.rpch.decoderawtransaction(self.hex)
|
||||
vsize = d['vsize'] if 'vsize' in d else d['size']
|
||||
vmsg('\nSize: {}, Vsize: {} (true) {} (estimated)'.format(d['size'],vsize,est_vsize))
|
||||
m1 = 'Estimated transaction vsize is {:1.2f} times the true vsize\n'
|
||||
m1 = '\nERROR: Estimated transaction vsize is {:1.2f} times the true vsize\n'
|
||||
m2 = 'Your transaction fee estimates will be inaccurate\n'
|
||||
m3 = 'Please re-create and re-sign the transaction using the option --vsize-adj={:1.2f}'
|
||||
# allow for 5% error
|
||||
ratio = float(est_vsize) / vsize
|
||||
assert 0.95 < ratio < 1.05, (m1+m2+m3).format(ratio,1/ratio)
|
||||
if not (0.95 < ratio < 1.05):
|
||||
die(2,(m1+m2+m3).format(ratio,1/ratio))
|
||||
|
||||
# https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending
|
||||
# 180: uncompressed, 148: compressed
|
||||
|
|
@ -847,7 +848,7 @@ class MMGenTX(MMGenObject):
|
|||
return True
|
||||
|
||||
def write_txid_to_file(self,ask_write=False,ask_write_default_yes=True):
|
||||
fn = '%s[%s].%s' % (self.txid,self.send_amt,self.txid_ext)
|
||||
fn = '{}[{}].{}'.format(self.txid,self.send_amt,self.txid_ext)
|
||||
write_data_to_file(fn,self.coin_txid+'\n','transaction ID',
|
||||
ask_write=ask_write,
|
||||
ask_write_default_yes=ask_write_default_yes)
|
||||
|
|
@ -968,7 +969,7 @@ class MMGenTX(MMGenObject):
|
|||
enl = ('\n','')[bool(terse)]
|
||||
out += enl
|
||||
if self.label:
|
||||
out += 'Comment: %s\n%s' % (self.label.hl(),enl)
|
||||
out += u'Comment: {}\n{}'.format(self.label.hl(),enl)
|
||||
out += 'Inputs:\n' + enl + format_io(self.inputs)
|
||||
out += 'Outputs:\n' + enl + format_io(self.outputs)
|
||||
|
||||
|
|
@ -1125,7 +1126,7 @@ class MMGenTX(MMGenObject):
|
|||
coin_addr = mmaddr2coinaddr(a1,ad_w,ad_f) if is_mmgen_id(a1) else CoinAddr(a1)
|
||||
self.add_output(coin_addr,g.proto.coin_amt(a2))
|
||||
else:
|
||||
die(2,"%s: invalid subargument in command-line argument '%s'" % (a1,a))
|
||||
die(2,"{}: invalid subargument in command-line argument '{}'".format(a1,a))
|
||||
elif is_mmgen_id(a) or is_coin_addr(a):
|
||||
if self.get_chg_output_idx() != None:
|
||||
die(2,'ERROR: More than one change address listed on command line')
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@ def get_seed_for_seed_id(sid,infiles,saved_seeds):
|
|||
if infiles:
|
||||
ss = SeedSource(infiles.pop(0),ignore_in_fmt=True)
|
||||
elif opt.in_fmt:
|
||||
qmsg('Need seed data for Seed ID %s' % sid)
|
||||
qmsg('Need seed data for Seed ID {}'.format(sid))
|
||||
ss = SeedSource()
|
||||
msg('User input produced Seed ID %s' % ss.seed.sid)
|
||||
msg('User input produced Seed ID {}'.format(ss.seed.sid))
|
||||
else:
|
||||
die(2,'ERROR: No seed source found for Seed ID: %s' % sid)
|
||||
die(2,'ERROR: No seed source found for Seed ID: {}'.format(sid))
|
||||
|
||||
saved_seeds[ss.seed.sid] = ss.seed
|
||||
if ss.seed.sid == sid: return ss.seed
|
||||
|
|
@ -61,7 +61,7 @@ def get_seed_for_seed_id(sid,infiles,saved_seeds):
|
|||
def generate_kals_for_mmgen_addrs(need_keys,infiles,saved_seeds):
|
||||
mmids = [e.mmid for e in need_keys]
|
||||
sids = set(i.sid for i in mmids)
|
||||
vmsg('Need seed%s: %s' % (suf(sids,'s'),' '.join(sids)))
|
||||
vmsg('Need seed{}: {}'.format(suf(sids,'s'),' '.join(sids)))
|
||||
d = MMGenList()
|
||||
from mmgen.addr import KeyAddrList
|
||||
for sid in sids:
|
||||
|
|
@ -95,7 +95,7 @@ def add_keys(tx,src,infiles=None,saved_seeds=None,keyaddr_list=None):
|
|||
else:
|
||||
die(3,wmsg['mapping_error'].format(m1,mmid,f.addr,'tx file:',e.mmid,e.addr))
|
||||
if new_keys:
|
||||
vmsg('Added %s wif key%s from %s' % (len(new_keys),suf(new_keys,'s'),desc))
|
||||
vmsg('Added {} wif key{} from {}'.format(len(new_keys),suf(new_keys,'s'),desc))
|
||||
return new_keys
|
||||
|
||||
def _pop_and_return(args,cmplist): # strips found args
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ def msg_r(s): sys.stderr.write(s.encode('utf8'))
|
|||
def Msg(s): sys.stdout.write(s.encode('utf8') + '\n')
|
||||
def Msg_r(s): sys.stdout.write(s.encode('utf8'))
|
||||
def msgred(s): msg(red(s))
|
||||
def rmsg(s): msg(red(s))
|
||||
def rmsg_r(s): msg_r(red(s))
|
||||
def ymsg(s): msg(yellow(s))
|
||||
def ymsg_r(s): msg_r(yellow(s))
|
||||
def gmsg(s): msg(green(s))
|
||||
|
|
@ -107,11 +109,11 @@ def parse_nbytes(nbytes):
|
|||
if k == m.group(2):
|
||||
return int(m.group(1)) * v
|
||||
else:
|
||||
msg("Valid byte specifiers: '%s'" % "' '".join([i[0] for i in smap]))
|
||||
msg("Valid byte specifiers: '{}'".format("' '".join([i[0] for i in smap])))
|
||||
else:
|
||||
return int(nbytes)
|
||||
|
||||
die(1,"'%s': invalid byte specifier" % nbytes)
|
||||
die(1,"'{}': invalid byte specifier".format(nbytes))
|
||||
|
||||
def check_or_create_dir(path):
|
||||
try:
|
||||
|
|
@ -152,7 +154,7 @@ def suf(arg,suf_type='s'):
|
|||
elif any(issubclass(t,c) for c in (list,tuple,set,dict)):
|
||||
n = len(arg)
|
||||
else:
|
||||
die(2,'%s: invalid parameter for suf()' % arg)
|
||||
die(2,'{}: invalid parameter for suf()'.format(arg))
|
||||
return suf_types[suf_type][n==1]
|
||||
|
||||
def get_extension(f):
|
||||
|
|
@ -300,13 +302,13 @@ class baseconv(object):
|
|||
def check_wordlist(cls,wl_id):
|
||||
|
||||
wl = baseconv.digits[wl_id]
|
||||
Msg('Wordlist: %s\nLength: %i words' % (capfirst(wl_id),len(wl)))
|
||||
Msg('Wordlist: {}\nLength: {} words'.format(capfirst(wl_id),len(wl)))
|
||||
new_chksum = cls.get_wordlist_chksum(wl_id)
|
||||
|
||||
a,b = 'generated checksum','saved checksum'
|
||||
compare_chksums(new_chksum,a,cls.wl_chksums[wl_id],b,die_on_fail=True)
|
||||
|
||||
Msg('Checksum %s matches' % new_chksum)
|
||||
Msg('Checksum {} matches'.format(new_chksum))
|
||||
Msg('List is sorted') if tuple(sorted(wl)) == wl else die(3,'ERROR: List is not sorted!')
|
||||
|
||||
|
||||
|
|
@ -330,7 +332,7 @@ class baseconv(object):
|
|||
|
||||
hexnum = hexnum.strip()
|
||||
if not is_hex_str(hexnum):
|
||||
die(2,"'%s': not a hexadecimal number" % hexnum)
|
||||
die(2,"'{}': not a hexadecimal number".format(hexnum))
|
||||
|
||||
wl = cls.digits[wl_id]
|
||||
base = len(wl)
|
||||
|
|
@ -378,7 +380,7 @@ def pretty_hexdump(data,gw=2,cols=8,line_nums=False):
|
|||
|
||||
def decode_pretty_hexdump(data):
|
||||
from string import hexdigits
|
||||
pat = r'^[%s]+:\s+' % hexdigits
|
||||
pat = r'^[{}]+:\s+'.format(hexdigits)
|
||||
lines = [re.sub(pat,'',l) for l in data.splitlines()]
|
||||
try:
|
||||
return unhexlify(''.join((''.join(lines).split())))
|
||||
|
|
@ -405,27 +407,26 @@ def get_hash_params(hash_preset):
|
|||
if hash_preset in g.hash_presets:
|
||||
return g.hash_presets[hash_preset] # N,p,r,buflen
|
||||
else: # Shouldn't be here
|
||||
die(3,"%s: invalid 'hash_preset' value" % hash_preset)
|
||||
die(3,"{}: invalid 'hash_preset' value".format(hash_preset))
|
||||
|
||||
def compare_chksums(chk1,desc1,chk2,desc2,hdr='',die_on_fail=False,verbose=False):
|
||||
|
||||
if not chk1 == chk2:
|
||||
m = "%s ERROR: %s checksum (%s) doesn't match %s checksum (%s)"\
|
||||
% ((hdr+':\n ' if hdr else 'CHECKSUM'),desc2,chk2,desc1,chk1)
|
||||
fs = "{} ERROR: {} checksum ({}) doesn't match {} checksum ({})"
|
||||
m = fs.format((hdr+':\n ' if hdr else 'CHECKSUM'),desc2,chk2,desc1,chk1)
|
||||
if die_on_fail:
|
||||
die(3,m)
|
||||
else:
|
||||
vmsg(m,force=verbose)
|
||||
return False
|
||||
|
||||
vmsg('%s checksum OK (%s)' % (capfirst(desc1),chk1))
|
||||
vmsg('{} checksum OK ({})'.format(capfirst(desc1),chk1))
|
||||
return True
|
||||
|
||||
def compare_or_die(val1, desc1, val2, desc2, e='Error'):
|
||||
if cmp(val1,val2):
|
||||
die(3,"%s: %s (%s) doesn't match %s (%s)"
|
||||
% (e,desc2,val2,desc1,val1))
|
||||
dmsg('%s OK (%s)' % (capfirst(desc2),val2))
|
||||
die(3,"{}: {} ({}) doesn't match {} ({})".format(e,desc2,val2,desc1,val1))
|
||||
dmsg('{} OK ({})'.format(capfirst(desc2),val2))
|
||||
return True
|
||||
|
||||
def open_file_or_exit(filename,mode,silent=False):
|
||||
|
|
@ -450,16 +451,15 @@ def check_file_type_and_access(fname,ftype,blkdev_ok=False):
|
|||
|
||||
try: mode = os.stat(fname).st_mode
|
||||
except:
|
||||
die(1,"Unable to stat requested %s '%s'" % (ftype,fname))
|
||||
die(1,"Unable to stat requested {} '{}'".format(ftype,fname))
|
||||
|
||||
for t in ok_types:
|
||||
if t[0](mode): break
|
||||
else:
|
||||
die(1,"Requested %s '%s' is not a %s" % (ftype,fname,
|
||||
' or '.join([t[1] for t in ok_types])))
|
||||
die(1,"Requested {} '{}' is not a {}".format(ftype,fname,' or '.join([t[1] for t in ok_types])))
|
||||
|
||||
if not os.access(fname, access):
|
||||
die(1,"Requested %s '%s' is not %sable by you" % (ftype,fname,m))
|
||||
die(1,"Requested {} '{}' is not {}able by you".format(ftype,fname,m))
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -506,23 +506,21 @@ def get_new_passphrase(desc,passchg=False):
|
|||
for i in range(g.passwd_max_tries):
|
||||
pw = ' '.join(get_words_from_user('Enter {}: '.format(w)))
|
||||
pw2 = ' '.join(get_words_from_user('Repeat passphrase: '))
|
||||
dmsg('Passphrases: [%s] [%s]' % (pw,pw2))
|
||||
dmsg('Passphrases: [{}] [{}]'.format(pw,pw2))
|
||||
if pw == pw2:
|
||||
vmsg('Passphrases match'); break
|
||||
else: msg('Passphrases do not match. Try again.')
|
||||
else:
|
||||
die(2,'User failed to duplicate passphrase in %s attempts' %
|
||||
g.passwd_max_tries)
|
||||
die(2,'User failed to duplicate passphrase in {} attempts'.format(g.passwd_max_tries))
|
||||
|
||||
if pw == '': qmsg('WARNING: Empty passphrase')
|
||||
return pw
|
||||
|
||||
def confirm_or_exit(message,question,expect='YES',exit_msg='Exiting at user request'):
|
||||
def confirm_or_exit(message,q,expect='YES',exit_msg='Exiting at user request'):
|
||||
m = message.strip()
|
||||
if m: msg(m)
|
||||
a = question+' ' if question[0].isupper() else \
|
||||
'Are you sure you want to %s?\n' % question
|
||||
b = "Type uppercase '%s' to confirm: " % expect
|
||||
a = q+' ' if q[0].isupper() else 'Are you sure you want to {}?\n'.format(q)
|
||||
b = "Type uppercase '{}' to confirm: ".format(expect)
|
||||
if my_raw_input(a+b).strip() != expect:
|
||||
die(1,exit_msg)
|
||||
|
||||
|
|
@ -553,22 +551,22 @@ def write_data_to_file(
|
|||
qmsg('Output to STDOUT requested')
|
||||
if sys.stdout.isatty():
|
||||
if no_tty:
|
||||
die(2,'Printing %s to screen is not allowed' % desc)
|
||||
die(2,'Printing {} to screen is not allowed'.format(desc))
|
||||
if (ask_tty and not opt.quiet) or binary:
|
||||
confirm_or_exit('','output %s to screen' % desc)
|
||||
confirm_or_exit('','output {} to screen'.format(desc))
|
||||
else:
|
||||
try: of = os.readlink('/proc/%d/fd/1' % os.getpid()) # Linux
|
||||
try: of = os.readlink('/proc/{}/fd/1'.format(os.getpid())) # Linux
|
||||
except: of = None # Windows
|
||||
|
||||
if of:
|
||||
if of[:5] == 'pipe:':
|
||||
if no_tty:
|
||||
die(2,'Writing %s to pipe is not allowed' % desc)
|
||||
die(2,'Writing {} to pipe is not allowed'.format(desc))
|
||||
if ask_tty and not opt.quiet:
|
||||
confirm_or_exit('','output %s to pipe' % desc)
|
||||
confirm_or_exit('','output {} to pipe'.format(desc))
|
||||
msg('')
|
||||
of2,pd = os.path.relpath(of),os.path.pardir
|
||||
msg("Redirecting output to file '%s'" % (of2,of)[of2[:len(pd)] == pd])
|
||||
msg("Redirecting output to file '{}'".format((of2,of)[of2[:len(pd)] == pd]))
|
||||
else:
|
||||
msg('Redirecting output to file')
|
||||
|
||||
|
|
@ -583,27 +581,27 @@ def write_data_to_file(
|
|||
outfile = make_full_path(opt.outdir,outfile)
|
||||
|
||||
if ask_write:
|
||||
if not ask_write_prompt: ask_write_prompt = 'Save %s?' % desc
|
||||
if not ask_write_prompt: ask_write_prompt = 'Save {}?'.format(desc)
|
||||
if not keypress_confirm(ask_write_prompt,
|
||||
default_yes=ask_write_default_yes):
|
||||
die(1,'%s not saved' % capfirst(desc))
|
||||
die(1,'{} not saved'.format(capfirst(desc)))
|
||||
|
||||
hush = False
|
||||
if file_exists(outfile) and ask_overwrite:
|
||||
q = "File '%s' already exists\nOverwrite?" % outfile
|
||||
q = "File '{}' already exists\nOverwrite?".format(outfile)
|
||||
confirm_or_exit('',q)
|
||||
msg("Overwriting file '%s'" % outfile)
|
||||
msg("Overwriting file '{}'".format(outfile))
|
||||
hush = True
|
||||
|
||||
f = open_file_or_exit(outfile,('w','wb')[bool(binary)])
|
||||
try:
|
||||
f.write(data)
|
||||
except:
|
||||
die(2,"Failed to write %s to file '%s'" % (desc,outfile))
|
||||
die(2,"Failed to write {} to file '{}'".format(desc,outfile))
|
||||
f.close
|
||||
|
||||
if not (hush or silent):
|
||||
msg("%s written to file '%s'" % (capfirst(desc),outfile))
|
||||
msg(u"{} written to file '{}'".format(capfirst(desc),outfile))
|
||||
|
||||
return True
|
||||
|
||||
|
|
@ -617,21 +615,19 @@ def write_data_to_file(
|
|||
def get_words_from_user(prompt):
|
||||
# split() also strips
|
||||
words = my_raw_input(prompt, echo=opt.echo_passphrase).split()
|
||||
dmsg('Sanitized input: [%s]' % ' '.join(words))
|
||||
dmsg('Sanitized input: [{}]'.format(' '.join(words)))
|
||||
return words
|
||||
|
||||
|
||||
def get_words_from_file(infile,desc,silent=False):
|
||||
if not silent:
|
||||
qmsg("Getting %s from file '%s'" % (desc,infile))
|
||||
qmsg(u"Getting {} from file '{}'".format(desc,infile))
|
||||
f = open_file_or_exit(infile, 'r')
|
||||
# split() also strips
|
||||
words = f.read().split()
|
||||
f.close()
|
||||
dmsg('Sanitized input: [%s]' % ' '.join(words))
|
||||
dmsg('Sanitized input: [{}]'.format(' '.join(words)))
|
||||
return words
|
||||
|
||||
|
||||
def get_words(infile,desc,prompt):
|
||||
if infile:
|
||||
return get_words_from_file(infile,desc)
|
||||
|
|
@ -643,7 +639,7 @@ def mmgen_decrypt_file_maybe(fn,desc='',silent=False):
|
|||
have_enc_ext = get_extension(fn) == g.mmenc_ext
|
||||
if have_enc_ext or not is_utf8(d):
|
||||
m = ('Attempting to decrypt','Decrypting')[have_enc_ext]
|
||||
msg("%s %s '%s'" % (m,desc,fn))
|
||||
msg("{} {} '{}'".format(m,desc,fn))
|
||||
from mmgen.crypto import mmgen_decrypt_retry
|
||||
d = mmgen_decrypt_retry(d,desc)
|
||||
return d
|
||||
|
|
@ -658,13 +654,13 @@ def get_lines_from_file(fn,desc='',trim_comments=False,silent=False):
|
|||
def get_data_from_user(desc='data',silent=False):
|
||||
p = ('','Enter {}: '.format(desc))[g.stdin_tty]
|
||||
data = my_raw_input(p,echo=opt.echo_passphrase)
|
||||
dmsg('User input: [%s]' % data)
|
||||
dmsg('User input: [{}]'.format(data))
|
||||
return data
|
||||
|
||||
def get_data_from_file(infile,desc='data',dash=False,silent=False,binary=False):
|
||||
if dash and infile == '-': return sys.stdin.read()
|
||||
if not opt.quiet and not silent and desc:
|
||||
qmsg("Getting %s from file '%s'" % (desc,infile))
|
||||
qmsg(u"Getting {} from file '{}'".format(desc,infile))
|
||||
f = open_file_or_exit(infile,('r','rb')[bool(binary)],silent=silent)
|
||||
data = f.read()
|
||||
f.close()
|
||||
|
|
@ -672,7 +668,7 @@ def get_data_from_file(infile,desc='data',dash=False,silent=False,binary=False):
|
|||
|
||||
def pwfile_reuse_warning():
|
||||
if 'passwd_file_used' in globals():
|
||||
qmsg("Reusing passphrase from file '%s' at user request" % opt.passwd_file)
|
||||
qmsg(u"Reusing passphrase from file '{}' at user request".format(opt.passwd_file))
|
||||
return True
|
||||
globals()['passwd_file_used'] = True
|
||||
return False
|
||||
|
|
@ -736,7 +732,7 @@ def prompt_and_get_char(prompt,chars,enter_ok=False,verbose=False):
|
|||
from mmgen.term import get_char
|
||||
|
||||
while True:
|
||||
reply = get_char('%s: ' % prompt).strip('\n\r')
|
||||
reply = get_char('{}: '.format(prompt)).strip('\n\r')
|
||||
|
||||
if reply in chars or (enter_ok and not reply):
|
||||
msg('')
|
||||
|
|
@ -777,7 +773,7 @@ def do_license_msg(immed=False):
|
|||
|
||||
p = "Press 'w' for conditions and warranty info, or 'c' to continue:"
|
||||
msg(gpl.warning)
|
||||
prompt = '%s ' % p.strip()
|
||||
prompt = '{} '.format(p.strip())
|
||||
|
||||
from mmgen.term import get_char
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,5 @@ start = (1,0)[bool(opt.include_first_line)]
|
|||
a = make_chksum_6(' '.join(lines[start:]))
|
||||
if start == 1:
|
||||
b = lines[0]
|
||||
m = ("Checksum in file (%s) doesn't match computed value!" % b,'Checksum in file OK')[a==b]
|
||||
msg(m)
|
||||
msg(("Checksum in file ({}) doesn't match computed value!".format(b),'Checksum in file OK')[a==b])
|
||||
Msg(a)
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ def find_block_by_time(timestamp):
|
|||
bot = block_num
|
||||
block_num = (top + bot) / 2
|
||||
if top - bot < 2:
|
||||
msg('\nFound: %s ' % block_num)
|
||||
msg('\nFound: {} '.format(block_num))
|
||||
break
|
||||
|
||||
return block_num
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ def compare_test():
|
|||
|
||||
for i in range(rounds):
|
||||
if opt.verbose or time.time() - last_t >= 0.1:
|
||||
qmsg_r('\rRound %s/%s ' % (i+1,rounds))
|
||||
qmsg_r('\rRound {}/{} '.format(i+1,rounds))
|
||||
last_t = time.time()
|
||||
sec = PrivKey(os.urandom(32),compressed=addr_type.compressed,pubkey_type=addr_type.pubkey_type)
|
||||
ph = kg_a.to_pubhex(sec)
|
||||
|
|
@ -188,10 +188,10 @@ def compare_test():
|
|||
match_error(sec,sec.wif,sec.wif,b_wif,a,b)
|
||||
else:
|
||||
b_addr = ag.to_addr(kg_b.to_pubhex(sec))
|
||||
vmsg('\nkey: %s\naddr: %s\n' % (sec.wif,a_addr))
|
||||
vmsg('\nkey: {}\naddr: {}\n'.format(sec.wif,a_addr))
|
||||
if a_addr != b_addr:
|
||||
match_error(sec,sec.wif,a_addr,b_addr,a,ext_lib if b == 'ext' else b)
|
||||
qmsg_r('\rRound %s/%s ' % (i+1,rounds))
|
||||
qmsg_r('\rRound {}/{} '.format(i+1,rounds))
|
||||
qmsg(green(('\n','')[bool(opt.verbose)] + 'OK'))
|
||||
|
||||
def speed_test():
|
||||
|
|
@ -206,19 +206,19 @@ def speed_test():
|
|||
|
||||
for i in range(rounds):
|
||||
if time.time() - last_t >= 0.1:
|
||||
qmsg_r('\rRound %s/%s ' % (i+1,rounds))
|
||||
qmsg_r('\rRound {}/{} '.format(i+1,rounds))
|
||||
last_t = time.time()
|
||||
sec = PrivKey(seed+pack('I',i),compressed=addr_type.compressed,pubkey_type=addr_type.pubkey_type)
|
||||
a_addr = ag.to_addr(kg_a.to_pubhex(sec))
|
||||
vmsg('\nkey: %s\naddr: %s\n' % (sec.wif,a_addr))
|
||||
qmsg_r('\rRound %s/%s ' % (i+1,rounds))
|
||||
vmsg('\nkey: {}\naddr: {}\n'.format(sec.wif,a_addr))
|
||||
qmsg_r('\rRound {}/{} '.format(i+1,rounds))
|
||||
qmsg('\n{} addresses generated in {:.2f} seconds'.format(rounds,time.time()-start))
|
||||
|
||||
def dump_test():
|
||||
m = "Comparing output of address generator '{}' against wallet dump '{}'"
|
||||
qmsg(green(m.format(kg_a.desc,cmd_args[1])))
|
||||
for n,[wif,a_addr] in enumerate(dump,1):
|
||||
qmsg_r('\rKey %s/%s ' % (n,len(dump)))
|
||||
qmsg_r('\rKey {}/{} '.format(n,len(dump)))
|
||||
try:
|
||||
sec = PrivKey(wif=wif)
|
||||
except:
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue