From fb046dc076349fbbf4cce35d40385e2e99dd0ab3 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 6 Oct 2021 13:22:32 +0000 Subject: [PATCH] minor cleanups --- mmgen/obj.py | 2 +- mmgen/tx.py | 21 ++++++++------------- mmgen/txsign.py | 14 +++++++------- mmgen/util.py | 11 ++++++----- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/mmgen/obj.py b/mmgen/obj.py index 1f07825d..bd4a6c20 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -1019,7 +1019,7 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject): 'M': ati('monero', 'monero', False,'monero', 'monero', 'spendkey',('viewkey','wallet_passwd'),'Monero address'), } def __new__(cls,proto,id_str,errmsg=None): - if type(id_str) == cls: + if isinstance(id_str,cls): return id_str try: for k,v in cls.mmtypes.items(): diff --git a/mmgen/tx.py b/mmgen/tx.py index b2520596..770d6af2 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -260,12 +260,6 @@ class MMGenTxInputList(MMGenTxIOList): desc = 'transaction inputs' member_type = 'MMGenTxInput' -# def convert_coin(self,verbose=False): -# if verbose: -# msg(f'{self.desc}:') -# for i in self: -# i.amt = self.parent.proto.coin_amt(i.amt) - # Lexicographical Indexing of Transaction Inputs and Outputs # https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki def sort_bip69(self): @@ -305,10 +299,10 @@ class MMGenTX: rel_fee_disp = 'sat/byte' non_mmgen_inputs_msg = f""" This transaction includes inputs with non-{g.proj_name} addresses. When - signing the transaction, private keys for the addresses must be supplied using - the --keys-from-file option. The key file must contain one key per line. - Please note that this transaction cannot be autosigned, as autosigning does - not support the use of key files. + signing the transaction, private keys for the addresses listed below must + be supplied using the --keys-from-file option. The key file must contain + one key per line. Please note that this transaction cannot be autosigned, + as autosigning does not support the use of key files. Non-{g.proj_name} addresses found in inputs: {{}} @@ -503,13 +497,14 @@ class MMGenTX: def check_non_mmgen_inputs(self,caller,non_mmaddrs=None): non_mmaddrs = non_mmaddrs or self.get_non_mmaddrs('inputs') if non_mmaddrs: - fs = fmt(self.non_mmgen_inputs_msg,strip_char='\t') + indent = ' ' + fs = fmt(self.non_mmgen_inputs_msg,strip_char='\t',indent=indent).strip() m = fs.format('\n '.join(non_mmaddrs)) if caller in ('txdo','txsign'): if not opt.keys_from_file: - raise UserOptError('ERROR: ' + m) + raise UserOptError(f'\n{indent}ERROR: {m}\n') else: - msg('WARNING: ' + m) + msg(f'\n{indent}WARNING: {m}\n') if not (opt.yes or keypress_confirm('Continue?',default_yes=True)): die(1,'Exiting at user request') diff --git a/mmgen/txsign.py b/mmgen/txsign.py index 6f2a9f2c..c5dfb6b8 100755 --- a/mmgen/txsign.py +++ b/mmgen/txsign.py @@ -154,13 +154,13 @@ async def txsign(tx,seed_files,kl,kal,tx_num_str=''): addrlist = non_mmaddrs, skip_chksum = True ) tmp.add_wifs(kl) - m = tmp.list_missing('sec') - if m: - die(2, fmt(""" - ERROR: a key file must be supplied for the following non-{} address{}: - {{}} - """.format( g.proj_name, suf(m,'es'), '\n '.join(m) ), - strip_char='\t').strip() ) + missing = tmp.list_missing('sec') + if missing: + sep = '\n ' + die(2,'ERROR: a key file must be supplied for the following non-{} address{}:{}'.format( + g.proj_name, + suf(missing,'es'), + sep + sep.join(missing) )) keys += tmp.data if opt.mmgen_keys_from_file: diff --git a/mmgen/util.py b/mmgen/util.py index 14646096..716a6e35 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -808,17 +808,18 @@ def my_raw_input(prompt,echo=True,insert_txt='',use_readline=True): def keypress_confirm(prompt,default_yes=False,verbose=False,no_nl=False,complete_prompt=False): - q = ('(y/N)','(Y/n)')[bool(default_yes)] - p = prompt if complete_prompt else f'{prompt} {q}: ' - nl = ('\n','\r{}\r'.format(' '*len(p)))[no_nl] + if not complete_prompt: + prompt = '{} {}: '.format( prompt, '(Y/n)' if default_yes else '(y/N)' ) + + nl = f'\r{" "*len(prompt)}\r' if no_nl else '\n' if g.accept_defaults: - msg(p) + msg(prompt) return default_yes from .term import get_char while True: - reply = get_char(p,immed_chars='yYnN').strip('\n\r') + reply = get_char(prompt,immed_chars='yYnN').strip('\n\r') if not reply: msg_r(nl) return True if default_yes else False