minor cleanups (8 files)

This commit is contained in:
The MMGen Project 2025-09-26 10:40:23 +00:00
commit 220dc5a31d
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
8 changed files with 19 additions and 21 deletions

View file

@ -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

View file

@ -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

View file

@ -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'])

View file

@ -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())

View file

@ -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 <seed ID>:[<type>:]<idx list>)')

View file

@ -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))

View file

@ -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())

View file

@ -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