From 9ad34f50017d515c19e2b48b3c57435997f6f0f7 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 12 Oct 2026 10:04:48 +0000 Subject: [PATCH] various changes and cleanups --- mmgen/proto/btc/tx/info.py | 14 +++++++------- mmgen/proto/rune/rpc/remote.py | 3 ++- test/cmdtest_d/rune.py | 8 +++++--- test/cmdtest_d/swap.py | 25 +++++++++++++++++++++---- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/mmgen/proto/btc/tx/info.py b/mmgen/proto/btc/tx/info.py index 64f21074..a19cd982 100644 --- a/mmgen/proto/btc/tx/info.py +++ b/mmgen/proto/btc/tx/info.py @@ -53,13 +53,13 @@ class TxInfo(TxInfo): sort, ','.join(self.sort_orders))) - def get_mmid_fmt(e, is_input): + def get_mmid_fmt(e, is_output, *, terse=False): if e.mmid: return e.mmid.fmt2( max_mmwid, encl = '()', color = True, - append_chars = ('', ' (chg)')[bool(not is_input and e.is_chg and terse)], + append_chars = ('', ' (chg)')[bool(is_output and e.is_chg and terse)], append_color = 'green') else: return MMGenID.fmtc( @@ -69,7 +69,7 @@ class TxInfo(TxInfo): def format_io(desc): io = getattr(tx, desc) - is_input = desc == 'inputs' + is_output = desc == 'outputs' yield desc.capitalize() + ':\n' + enl confs_per_day = 60*60*24 // tx.proto.avg_bdi @@ -93,7 +93,7 @@ class TxInfo(TxInfo): for n, e in enumerate(io_sorted()): yield '{:3} {} {} {}\n'.format( n + 1, - e.addr.fmt(vp1, addr_w, color=True) + ' ' + get_mmid_fmt(e, is_input) + e.addr.fmt(vp1, addr_w, color=True) + ' ' + get_mmid_fmt(e, is_output, terse=True) if e.addr else data_disp(e.data), e.amt.fmt(iwidth, color=True), tx.dcoin) @@ -107,7 +107,7 @@ class TxInfo(TxInfo): 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)}') + yield ('', 'address:', f'{e.addr.hl(vp1)} {get_mmid_fmt(e, False)}') if have_bch: yield ('', '', f'[{e.addr.hl(vp2, color=False)}]') yield from gen_common(e) @@ -116,7 +116,7 @@ class TxInfo(TxInfo): yield ('', 'confirmations:', f'{nc} (around {nc // confs_per_day} days)') def gen_output(n, e): - yield (n + 1, 'address:', (f'{e.addr.hl(vp1)} {get_mmid_fmt(e, False)}' + yield (n + 1, 'address:', (f'{e.addr.hl(vp1)} {get_mmid_fmt(e, True)}' if e.addr else e.data.hl(add_label=True))) if have_bch and e.addr: yield ('', '', f'[{e.addr.hl(vp2, color=False)}]') @@ -125,7 +125,7 @@ class TxInfo(TxInfo): yield ('', 'change:', green('True')) lcw = len(str(len(io))) + 1 - gen = gen_input if is_input else gen_output + gen = gen_output if is_output else gen_input for n, e in enumerate(io_sorted()): yield '\n'.join(f'{a:>{lcw}} {b:<8} {c}' for a, b, c in gen(n, e)) + '\n\n' diff --git a/mmgen/proto/rune/rpc/remote.py b/mmgen/proto/rune/rpc/remote.py index d06033bf..45f3ea32 100644 --- a/mmgen/proto/rune/rpc/remote.py +++ b/mmgen/proto/rune/rpc/remote.py @@ -24,7 +24,8 @@ def process_response(json_response, errmsg): data = json.loads(json_response) if isinstance(data, dict) and 'result' in data: if data['result'] is None: - from ....util import die + from ....util import ymsg, pp_fmt, die + ymsg(pp_fmt(data)) die('RPCFailure', errmsg) return data['result'] return data diff --git a/test/cmdtest_d/rune.py b/test/cmdtest_d/rune.py index 6dd83c97..353a7c69 100644 --- a/test/cmdtest_d/rune.py +++ b/test/cmdtest_d/rune.py @@ -22,10 +22,10 @@ from .shared import CmdTestShared class CmdTestRuneMethods: - def _rune_bal_refresh(self, menu_prompt=None): + def _rune_bal_refresh(self, menu_prompt=None, add_opts=[]): t = self.spawn( 'mmgen-tool', - self.rune_opts + self.add_eth_opts + ['listaddresses', 'interactive=1']) + self.rune_opts + self.add_eth_opts + add_opts + ['listaddresses', 'interactive=1']) prompt = menu_prompt or self.menu_prompt t.expect(prompt, 'R') t.expect('menu): ', '3\n') @@ -55,11 +55,13 @@ class CmdTestRuneMethods: no_passthru_opts = ['coin']), has_label = True) - def _rune_txsend(self, add_opts=[], *, test=False, dump_hex=False): + def _rune_txsend(self, add_opts=[], *, test=False, dump_hex=False, spawn_only=False): t = self.spawn( 'mmgen-txsend', self.rune_opts + add_opts + [self.get_file_with_ext('sigtx')], no_passthru_opts = ['coin']) + if spawn_only: + return t t.expect('view: ', 'y') t.expect('to continue: ', 'z') t.expect('(y/N): ', 'n') # edit comment? diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index 3f24ef41..e5d4ce17 100644 --- a/test/cmdtest_d/swap.py +++ b/test/cmdtest_d/swap.py @@ -142,7 +142,14 @@ class CmdTestSwapMethods: '--ltc-rpc-port=19571'], spawn_only = spawn_only) - def _swaptxsend(self, *, add_opts=[], spawn_only=False, status=False, dump_hex=False): + def _swaptxsend( + self, + *, + add_opts = [], + spawn_only = False, + status = False, + dump_hex = False, + expect_pats = None): fn = self.get_file_with_ext('sigtx') t = self.spawn( 'mmgen-txsend', @@ -151,6 +158,8 @@ class CmdTestSwapMethods: if spawn_only: return t t.view_tx('v') + if expect_pats: + t.expect(expect_pats, regex=True) if status: return t t.expect('(y/N): ', 'n') @@ -174,14 +183,21 @@ class CmdTestSwapMethods: t.written_to_file('Signed transaction') return t - def _swaptxbump(self, fee, *, add_opts=[], output_args=[], exit_val=None): + def _swaptxbump(self, fee, *, add_opts=[], output_args=[], single_output=False, exit_val=None): self.get_file_with_ext('rawtx', delete_all=True) fn = self.get_file_with_ext('sigtx') t = self.spawn( 'mmgen-txbump', ['-q', '-d', self.tmpdir] + self.bob_opt + add_opts + output_args + [fn], exit_val = exit_val) - return self._swaptxbump_ui_common(t, interactive_fee=fee, new_outputs=bool(output_args)) + t = self._swaptxbump_ui_common( + t, + interactive_fee = fee, + single_output = single_output, + new_outputs = bool(output_args)) + t.read() + os.unlink(fn) # bumped sigtx replaces the original + return t def _swaptxbump_ui_common_new_outputs( self, @@ -205,6 +221,7 @@ class CmdTestSwapMethods: inputs = None, interactive_fee = None, file_desc = None, + single_output = False, new_outputs = False): if new_outputs: if not self.proto.is_vm: @@ -212,7 +229,7 @@ class CmdTestSwapMethods: t.expect('(Y/n): ', 'y') # fee ok? t.expect('(Y/n): ', 'y') # change ok? else: - if not self.proto.is_vm: + if not (self.proto.is_vm or single_output): t.expect('ENTER for the change output): ', '\n') t.expect('(Y/n): ', 'y') # confirm deduct from chg output t.expect('to continue: ', '\n') # exit swap quote