From e053553221b9855820d5f716dbdb5bd6eb47d0ea Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 17 Aug 2026 09:05:13 +0000 Subject: [PATCH] proto.btc.tx.info: cleanups --- mmgen/proto/btc/tx/info.py | 48 ++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/mmgen/proto/btc/tx/info.py b/mmgen/proto/btc/tx/info.py index f0c292db..91d93784 100755 --- a/mmgen/proto/btc/tx/info.py +++ b/mmgen/proto/btc/tx/info.py @@ -99,37 +99,35 @@ class TxInfo(TxInfo): if have_bch and e.addr: yield '{:3} [{}]\n'.format('', e.addr.hl(vp2, color=False)) else: - def gen(n, e): - mmid_fmt = get_mmid_fmt(e, is_input) - if is_input: - yield (n+1, 'tx,vout:', f'{e.txid.hl()},{red(str(e.vout))}') - yield ('', 'address:', f'{e.addr.hl(vp1)} {mmid_fmt}') - if have_bch: - yield ('', '', f'[{e.addr.hl(vp2, color=False)}]') - else: - yield ( - n + 1, - 'address:', - (f'{e.addr.hl(vp1)} {mmid_fmt}' if e.addr else e.data.hl(add_label=True))) - if have_bch and e.addr: - yield ('', '', f'[{e.addr.hl(vp2, color=False)}]') - + def gen_common(e): if e.comment: - yield ('', 'comment:', e.comment.hl()) + yield ('', 'comment:', e.comment.hl()) + yield ('', 'amount:', f'{e.amt.hl()} {tx.dcoin}') - yield ('', 'amount:', f'{e.amt.hl()} {tx.dcoin}') + def gen_input(n, e): + yield (n + 1, 'tx,vout:', f'{e.txid.hl()},{red(str(e.vout))}') + yield ('', 'address:', f'{e.addr.hl(vp1)} {get_mmid_fmt(e, True)}') + if have_bch: + yield ('', '', f'[{e.addr.hl(vp2, color=False)}]') + yield from gen_common(e) + if blockcount: + nc = e.confs + blockcount - tx.blockcount + yield ('', 'confirmations:', f'{nc} (around {nc // confs_per_day} days)') - if is_input and blockcount: - confs = e.confs + blockcount - tx.blockcount - yield ('', 'confirmations:', f'{confs} (around {confs // confs_per_day} days)') + def gen_output(n, e): + yield (n + 1, 'address:', (f'{e.addr.hl(vp1)} {get_mmid_fmt(e, False)}' + if e.addr else e.data.hl(add_label=True))) + if have_bch and e.addr: + yield ('', '', f'[{e.addr.hl(vp2, color=False)}]') + yield from gen_common(e) + if e.is_chg: + yield ('', 'change:', green('True')) - if not is_input and e.is_chg: - yield ('', 'change:', green('True')) - - col1_w = len(str(len(io))) + 1 + lcw = len(str(len(io))) + 1 + gen = gen_input if is_input else gen_output for n, e in enumerate(io_sorted()): - yield '\n'.join('{:>{w}} {:<8} {}'.format(*d, w=col1_w) for d in gen(n, e)) + '\n\n' + yield '\n'.join(f'{a:>{lcw}} {b:<8} {c}' for a, b, c in gen(n, e)) + '\n\n' tx = self.tx