From da32c52a0fbf32492c12976313557a2cc146a2e4 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Tue, 3 Oct 2023 14:27:58 +0000 Subject: [PATCH] a few minor cleanups --- mmgen/addrlist.py | 1 + mmgen/autosign.py | 2 +- mmgen/cfg.py | 4 ++-- mmgen/data/release_date | 2 +- mmgen/data/version | 2 +- mmgen/devtools.py | 16 +++++++++------- mmgen/msg.py | 3 ++- mmgen/tx/info.py | 9 ++++----- test/unit_tests_d/ut_flags.py | 1 - test/unit_tests_d/ut_rpc.py | 3 ++- 10 files changed, 23 insertions(+), 20 deletions(-) diff --git a/mmgen/addrlist.py b/mmgen/addrlist.py index 68570b44..98a6109c 100755 --- a/mmgen/addrlist.py +++ b/mmgen/addrlist.py @@ -200,6 +200,7 @@ class AddrList(MMGenObject): # Address info for a single seed ID adata = AddrListData([AddrListEntry(proto=proto,addr=a) for a in addrlist]) elif keylist: # data from flat key list self.al_id = None + from .util import remove_dups keylist = remove_dups(keylist,edesc='key',desc='key list',hide=True) adata = AddrListData([AddrListEntry(proto=proto,sec=PrivKey(proto=proto,wif=k)) for k in keylist]) elif seed or addr_idxs: diff --git a/mmgen/autosign.py b/mmgen/autosign.py index ccbf155d..0cff4a13 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -536,6 +536,7 @@ class Autosign: def do_shred(f): nonlocal count msg_r('.') + from .fileutil import shred_file shred_file( f, verbose=self.cfg.verbose ) count += 1 @@ -565,7 +566,6 @@ class Autosign: asi = get_autosign_obj( self.cfg, 'btc,xmr' ) count = 0 - from .fileutil import shred_file for s_name in Signable.signables: clean_dir(s_name) diff --git a/mmgen/cfg.py b/mmgen/cfg.py index 3142cf69..119b10c4 100755 --- a/mmgen/cfg.py +++ b/mmgen/cfg.py @@ -679,6 +679,8 @@ class Config(Lockable): def check_opts(cfg): # Raises exception if any check fails + from .util import is_int,Msg + def get_desc(desc_pfx=''): return ( (desc_pfx + ' ' if desc_pfx else '') @@ -831,8 +833,6 @@ def check_opts(cfg): # Raises exception if any check fails def columns(): opt_compares(val,'>',10) - from .util import is_int,Msg - # TODO: add checks for token, rbf, tx_fee check_funcs_names = tuple(check_funcs.__dict__) for name in tuple(cfg._uopts) + cfg._envopts + cfg._cfgfile_opts.non_auto: diff --git a/mmgen/data/release_date b/mmgen/data/release_date index 2aa79658..74e85a7c 100644 --- a/mmgen/data/release_date +++ b/mmgen/data/release_date @@ -1 +1 @@ -September 2023 +October 2023 diff --git a/mmgen/data/version b/mmgen/data/version index d8969871..3f375980 100644 --- a/mmgen/data/version +++ b/mmgen/data/version @@ -1 +1 @@ -14.0.dev5 +14.0.dev6 diff --git a/mmgen/devtools.py b/mmgen/devtools.py index ad95c208..32a861ea 100755 --- a/mmgen/devtools.py +++ b/mmgen/devtools.py @@ -120,8 +120,17 @@ class MMGenObjectMethods: # mixin class for MMGenObject self.pdie(exit_val=0) def pfmt(self,lvl=0,id_list=[],color=None): + from decimal import Decimal scalars = (str,int,float,Decimal) + + def isDict(obj): + return isinstance(obj,dict) + def isList(obj): + return isinstance(obj,list) + def isScalar(obj): + return isinstance(obj,scalars) + def do_list(out,e,lvl=0,is_dict=False): out.append('\n') for i in e: @@ -155,13 +164,6 @@ class MMGenObjectMethods: # mixin class for MMGenObject if not e: out.append(f'{e!r}\n') - def isDict(obj): - return isinstance(obj,dict) - def isList(obj): - return isinstance(obj,list) - def isScalar(obj): - return isinstance(obj,scalars) - out = [f'<{type(self).__name__}>{" "+repr(self) if isScalar(self) else ""}\n'] if id(self) in id_list: diff --git a/mmgen/msg.py b/mmgen/msg.py index 9035fecd..5a63bf2d 100755 --- a/mmgen/msg.py +++ b/mmgen/msg.py @@ -220,6 +220,8 @@ class coin_msg: async def sign(self,wallet_files): + from .addrlist import KeyAddrList + async def sign_list(al_in,seed): al = KeyAddrList( cfg = self.cfg, @@ -254,7 +256,6 @@ class coin_msg: self.rpc = await rpc_init( self.cfg, self.proto, ignore_wallet=True ) from .wallet import Wallet - from .addrlist import KeyAddrList wallet_seeds = [Wallet(cfg=self.cfg,fn=fn).seed for fn in wallet_files] need_sids = remove_dups([al.sid for al in self.addrlists], quiet=True) saved_seeds = list() diff --git a/mmgen/tx/info.py b/mmgen/tx/info.py index 86f6ca60..627944bb 100755 --- a/mmgen/tx/info.py +++ b/mmgen/tx/info.py @@ -36,11 +36,10 @@ class TxInfo: blockcount = None def get_max_mmwid(io): - if io == tx.inputs: - sel_f = lambda o: len(o.mmid) + 2 # len('()') - else: - sel_f = lambda o: len(o.mmid) + (2,8)[bool(o.is_chg)] # + len(' (chg)') - return max(max([sel_f(o) for o in io if o.mmid] or [0]),len(nonmm_str)) + sel_f = ( + (lambda o: len(o.mmid) + 2) if io == tx.inputs else # 2 = len('()') + (lambda o: len(o.mmid) + (2,8)[bool(o.is_chg)]) ) # 6 = len(' (chg)') + return max(max([sel_f(o) for o in io if o.mmid] or [0]),len(nonmm_str)) nonmm_str = f'(non-{gc.proj_name} address)' max_mmwid = max(get_max_mmwid(tx.inputs),get_max_mmwid(tx.outputs)) diff --git a/test/unit_tests_d/ut_flags.py b/test/unit_tests_d/ut_flags.py index b78a1ca7..830b89fe 100755 --- a/test/unit_tests_d/ut_flags.py +++ b/test/unit_tests_d/ut_flags.py @@ -33,7 +33,6 @@ class unit_test(object): avail_opts = ('foo',) def __init__(self,opts=None,flags=None): self.opt = MyClassOpts(self,opts) - self.flag = MyClassFlags(self,flags) def test_flags(): def gen(): diff --git a/test/unit_tests_d/ut_rpc.py b/test/unit_tests_d/ut_rpc.py index af69175c..b6962db0 100755 --- a/test/unit_tests_d/ut_rpc.py +++ b/test/unit_tests_d/ut_rpc.py @@ -181,6 +181,8 @@ class unit_tests: rpc.call_raw('get_height') rpc.call('get_last_block_header') + from mmgen.xmrseed import xmrseed + async def run(): networks = init_proto( cfg, 'xmr' ).networks daemons = [( @@ -224,7 +226,6 @@ class unit_tests: gmsg('OK') - from mmgen.xmrseed import xmrseed import shutil shutil.rmtree('test/trash2',ignore_errors=True) os.makedirs('test/trash2/wallet_rpc')