From 4da94df0dadd14e1bb7026a36fd4f095fd876d7c Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 26 Nov 2022 18:55:56 +0000 Subject: [PATCH] tx.info: display amounts with columnar alignment --- mmgen/proto/btc/tx/info.py | 8 +++++--- mmgen/proto/eth/tx/info.py | 4 ++-- mmgen/tx/info.py | 12 +++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/mmgen/proto/btc/tx/info.py b/mmgen/proto/btc/tx/info.py index a995a1db..93b86c99 100755 --- a/mmgen/proto/btc/tx/info.py +++ b/mmgen/proto/btc/tx/info.py @@ -36,8 +36,8 @@ class TxInfo(TxInfo): pink('{:0.6f}%'.format( tx.fee / tx.send_amt * 100 )) ) - def format_abs_fee(self): - return self.tx.proto.coin_amt(self.tx.fee).hl() + def format_abs_fee(self,color,iwidth): + return self.tx.proto.coin_amt(self.tx.fee).fmt(color=color,iwidth=iwidth) def format_verbose_footer(self): tx = self.tx @@ -67,6 +67,8 @@ class TxInfo(TxInfo): key = lambda o: (o.mmid.sort_key if o.mmid else f'+{o.addr}') + f'{o.amt:040.20f}' ), 'raw': lambda: io }[sort] + if terse: + iwidth = max(len(str(int(e.amt))) for e in io) for n,e in enumerate(io_sorted()): if is_input and blockcount: confs = e.confs + blockcount - tx.blockcount @@ -85,7 +87,7 @@ class TxInfo(TxInfo): n+1, e.addr.fmt(color=True,width=addr_w), mmid_fmt, - e.amt.hl(), + e.amt.fmt(iwidth=iwidth,color=True), tx.dcoin ) else: def gen(): diff --git a/mmgen/proto/eth/tx/info.py b/mmgen/proto/eth/tx/info.py index 9587ab0e..9b5f45b8 100755 --- a/mmgen/proto/eth/tx/info.py +++ b/mmgen/proto/eth/tx/info.py @@ -55,8 +55,8 @@ class TxInfo(TxInfo): t_mmid = m['outputs'] if len(tx.outputs) else '', f_mmid = m['inputs'] ) - def format_abs_fee(self): - return self.tx.fee.hl() + (' (max)' if self.tx.txobj['data'] else '') + def format_abs_fee(self,color,iwidth): + return self.tx.fee.fmt(color=color,iwidth=iwidth) + (' (max)' if self.tx.txobj['data'] else '') def format_rel_fee(self,terse): return ' ({} of spend amount)'.format( diff --git a/mmgen/tx/info.py b/mmgen/tx/info.py index 878acb61..c810d398 100755 --- a/mmgen/tx/info.py +++ b/mmgen/tx/info.py @@ -72,12 +72,14 @@ class TxInfo: yield self.format_body(blockcount,nonmm_str,max_mmwid,enl,terse=terse,sort=sort) + iwidth = len(str(int(tx.sum_inputs()))) + yield self.txinfo_ftr_fs.format( - i = tx.sum_inputs().hl(), - o = tx.sum_outputs().hl(), - C = tx.change.hl(), - s = tx.send_amt.hl(), - a = self.format_abs_fee(), + i = tx.sum_inputs().fmt(color=True,iwidth=iwidth), + o = tx.sum_outputs().fmt(color=True,iwidth=iwidth), + C = tx.change.fmt(color=True,iwidth=iwidth), + s = tx.send_amt.fmt(color=True,iwidth=iwidth), + a = self.format_abs_fee(color=True,iwidth=iwidth), r = self.format_rel_fee(terse), d = tx.dcoin, c = tx.coin )