From 220dc5a31dec6ec4fe2e151c6f89e86d0b24895a Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 26 Sep 2025 10:40:23 +0000 Subject: [PATCH] minor cleanups (8 files) --- mmgen/addrlist.py | 2 +- mmgen/cfgfile.py | 3 +-- mmgen/proto/bch/cashaddr.py | 7 +++---- mmgen/proto/btc/tw/txhistory.py | 14 +++++++------- mmgen/tw/addresses.py | 3 +-- mmgen/wallet/__init__.py | 2 +- mmgen/wallet/brain.py | 4 ++-- mmgen/wallet/incog_hidden.py | 5 +++-- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/mmgen/addrlist.py b/mmgen/addrlist.py index 8446cc31..71d39764 100755 --- a/mmgen/addrlist.py +++ b/mmgen/addrlist.py @@ -34,7 +34,7 @@ class AddrIdxList(tuple, InitErrors, MMGenObject): try: if fmt_str: def gen(): - for i in (fmt_str.split(sep)): + for i in fmt_str.split(sep): match [int(x) for x in i.split('-')]: case [a]: yield a diff --git a/mmgen/cfgfile.py b/mmgen/cfgfile.py index 31713b60..9f99f5b4 100755 --- a/mmgen/cfgfile.py +++ b/mmgen/cfgfile.py @@ -228,8 +228,7 @@ class CfgFileSampleUsr(cfg_file_sample): def parse_metadata(self): if self.data: - m = re.match(r'# Version (\d+) ([a-f0-9]{40})$', self.data[-1]) - if m: + if m := re.match(r'# Version (\d+) ([a-f0-9]{40})$', self.data[-1]): self.ver = m[1] self.chksum = m[2] self.data = self.data[:-1] # remove metadata line diff --git a/mmgen/proto/bch/cashaddr.py b/mmgen/proto/bch/cashaddr.py index e233edc7..0702b1b4 100755 --- a/mmgen/proto/bch/cashaddr.py +++ b/mmgen/proto/bch/cashaddr.py @@ -51,8 +51,8 @@ def PolyMod(v): def parse_ver_byte(ver): assert not (ver >> 7), 'invalid version byte: most-significant bit must be zero' - t = namedtuple('parsed_version_byte', ['addr_type', 'bitlen']) - return t(addr_types_rev[ver >> 3], data_sizes[ver & 7]) + return namedtuple('parsed_version_byte', ['addr_type', 'bitlen'])( + addr_types_rev[ver >> 3], data_sizes[ver & 7]) def make_ver_byte(addr_type, bitlen): assert addr_type in addr_types_rev, f'{addr_type}: invalid addr type' @@ -66,8 +66,7 @@ def make_polymod_vec(pfx, payload_vec): return ([ord(c) & 31 for c in pfx] + [0] + payload_vec) def cashaddr_parse_addr(addr): - t = namedtuple('parsed_cashaddr', ['pfx', 'payload']) - return t(*addr.split(':', 1)) + return namedtuple('parsed_cashaddr', ['pfx', 'payload'])(*addr.split(':', 1)) def cashaddr_encode_addr(addr_type, size, pfx, data): t = namedtuple('encoded_cashaddr', ['addr', 'pfx', 'payload']) diff --git a/mmgen/proto/btc/tw/txhistory.py b/mmgen/proto/btc/tw/txhistory.py index 90899f45..b92910c3 100755 --- a/mmgen/proto/btc/tw/txhistory.py +++ b/mmgen/proto/btc/tw/txhistory.py @@ -297,15 +297,15 @@ class BitcoinTwTxHistory(BitcoinTwView, TwTxHistory, BitcoinTwRPC): def gen_parsed_data(): for o in rpc_data: if lbl_id in o: - l = get_tw_label(self.proto, o[lbl_id]) + lbl = get_tw_label(self.proto, o[lbl_id]) + yield o | { + 'twmmid': lbl.mmid, + 'comment': lbl.comment or ''} else: assert o['category'] == 'send', f"{o['address']}: {o['category']} != 'send'" - l = None - o.update({ - 'twmmid': l.mmid if l else None, - 'comment': (l.comment or '') if l else None, - }) - yield o + yield o | { + 'twmmid': None, + 'comment': None} data = list(gen_parsed_data()) diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index 87adcd62..097f9333 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -12,7 +12,7 @@ tw.addresses: Tracking wallet listaddresses class for the MMGen suite """ -from ..util import msg, is_int +from ..util import msg, is_int, die from ..obj import MMGenListItem, ImmutableAttr, ListItemAttr, TwComment, NonNegativeInt from ..addr import CoinAddr, MMGenID, MMGenAddrType from ..amt import CoinAmtChk @@ -113,7 +113,6 @@ class TwAddresses(TwView): if mmgen_addrs: a = mmgen_addrs.rsplit(':', 1) if len(a) != 2: - from ..util import die die(1, f'{mmgen_addrs}: invalid address list argument ' + '(must be in form :[:])') diff --git a/mmgen/wallet/__init__.py b/mmgen/wallet/__init__.py index 37848a95..a9096507 100755 --- a/mmgen/wallet/__init__.py +++ b/mmgen/wallet/__init__.py @@ -148,7 +148,7 @@ def Wallet( die(1, f'{in_fmt}: --in-fmt parameter does not match extension of input file') me = _get_me(wd.type) else: - fn = ','.join(cfg.hidden_incog_input_params.split(',')[:-1]) # permit comma in filename + fn = cfg.hidden_incog_input_params.rsplit(',', 1)[0] # permit comma in filename me = _get_me('incog_hidden') from ..filename import MMGenFile me.infile = MMGenFile(fn, subclass=type(me)) diff --git a/mmgen/wallet/brain.py b/mmgen/wallet/brain.py index 77f7e1bb..edba6b67 100755 --- a/mmgen/wallet/brain.py +++ b/mmgen/wallet/brain.py @@ -25,8 +25,8 @@ class wallet(wallet): def get_bw_params(self): # already checked - a = self.cfg.brain_params.split(',') - return int(a[0]), a[1] + a, b = self.cfg.brain_params.split(',', 1) + return int(a), b def _deformat(self): self.brainpasswd = ' '.join(self.fmt_data.split()) diff --git a/mmgen/wallet/incog_hidden.py b/mmgen/wallet/incog_hidden.py index 2049fd5c..bee3eec0 100755 --- a/mmgen/wallet/incog_hidden.py +++ b/mmgen/wallet/incog_hidden.py @@ -47,8 +47,9 @@ class wallet(wallet): } def _get_hincog_params(self, wtype): - a = getattr(self.cfg, 'hidden_incog_'+ wtype +'_params').split(',') - return ','.join(a[:-1]), int(a[-1]) # permit comma in filename + # permit comma in filename: + fn, offset = getattr(self.cfg, f'hidden_incog_{wtype}_params').rsplit(',', 1) + return fn, int(offset) def _check_valid_offset(self, fn, action): d = self.ssdata