From 0b3982fcbf9b134d732ac3b5aa9527ad2cb8c15a Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 6 Sep 2026 10:08:41 +0000 Subject: [PATCH] tx.new, tx.new_swap, tx.info: minor cleanups --- mmgen/proto/rune/tx/info.py | 9 +++++---- mmgen/proto/rune/tx/new.py | 2 +- mmgen/tx/base.py | 10 ++-------- mmgen/tx/bump.py | 2 +- mmgen/tx/new.py | 1 + test/cmdtest_d/ethdev.py | 4 ++-- test/cmdtest_d/rune.py | 8 ++++---- test/cmdtest_d/swap.py | 7 ++++--- 8 files changed, 20 insertions(+), 23 deletions(-) diff --git a/mmgen/proto/rune/tx/info.py b/mmgen/proto/rune/tx/info.py index 123ae383..722a1406 100755 --- a/mmgen/proto/rune/tx/info.py +++ b/mmgen/proto/rune/tx/info.py @@ -23,13 +23,14 @@ class TxInfo(VmTxInfo, TxInfo): def format_body(self, blockcount, nonmm_str, max_mmwid, enl, *, terse, sort): tx = self.tx t = tx.txobj + has_memo = tx.is_swap fs = """ From: {f}{f_mmid} Amount: {a} {c} Gas limit: {G} Sequence: {N} Memo: {m} - """ if tx.is_swap else """ + """ if has_memo else """ From: {f}{f_mmid} To: {t}{t_mmid} Amount: {a} {c} @@ -38,14 +39,14 @@ class TxInfo(VmTxInfo, TxInfo): """ return fs.strip().replace('\t', '').format( f = t['from'].hl(0), - t = None if tx.is_swap else t['to'].hl(0), + t = None if has_memo else t['to'].hl(0), a = t['amt'].hl(), N = NonNegativeInt(t['sequence']).hl(), - m = pink(tx.swap_memo) if tx.is_swap else None, + m = pink(tx.swap_memo) if has_memo else None, c = tx.proto.dcoin if tx.outputs else '', G = NonNegativeInt(tx.total_gas).hl(), f_mmid = mmid_disp(tx.inputs[0], nonmm_str), - t_mmid = None if tx.is_swap else mmid_disp(tx.outputs[0], nonmm_str)) + '\n\n' + t_mmid = None if has_memo else mmid_disp(tx.outputs[0], nonmm_str)) + '\n\n' def format_abs_fee(self, iwidth, /, *, color=None): return self.tx.fee.fmt(iwidth, color=color) diff --git a/mmgen/proto/rune/tx/new.py b/mmgen/proto/rune/tx/new.py index d71c94fd..6e90099b 100755 --- a/mmgen/proto/rune/tx/new.py +++ b/mmgen/proto/rune/tx/new.py @@ -39,7 +39,7 @@ class New(VmNew, Base, TxBase.New): self.txobj = { 'from': self.inputs[0].addr, 'to': self.outputs[0].addr if self.outputs else None, - 'amt': self.outputs[0].amt if self.outputs else self.swap_amt, + 'amt': self.sum_outputs(), 'gas': self.gas, 'account_number': int(acct_info['account_number']), 'sequence': int(acct_info['sequence']), diff --git a/mmgen/tx/base.py b/mmgen/tx/base.py index c120f0ad..ead711b8 100755 --- a/mmgen/tx/base.py +++ b/mmgen/tx/base.py @@ -79,7 +79,6 @@ class Base(MMGenObject): locktime = None chain = None signed = False - is_bump = False is_swap = False is_compat = False has_comment = True @@ -151,13 +150,8 @@ class Base(MMGenObject): return sum(e.amt for e in self.inputs) def sum_outputs(self, *, exclude=None): - if exclude is None: - olist = self.outputs - else: - olist = self.outputs[:exclude] + self.outputs[exclude+1:] - if not olist: - return self.proto.coin_amt('0') - return sum(e.amt for e in olist) + olist = self.outputs if exclude is None else self.outputs[:exclude] + self.outputs[exclude+1:] + return sum(e.amt for e in olist) if olist else self.proto.coin_amt('0') def _chg_output_ops(self, op, attr): is_chgs = [getattr(x, attr) for x in self.outputs] diff --git a/mmgen/tx/bump.py b/mmgen/tx/bump.py index 6b2d0400..ee11ca19 100755 --- a/mmgen/tx/bump.py +++ b/mmgen/tx/bump.py @@ -49,7 +49,7 @@ class Bump(Completed, NewSwap): if check_sent and not self.coin_txid: die(1, f'Transaction {self.txid!r} was not broadcast to the network') - self.coin_txid = '' + self.coin_txid = None self.sent_timestamp = None async def get_inputs(self, outputs_sum): diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index db8e6451..8b66c096 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -80,6 +80,7 @@ class New(Base): fee_is_approximate = False is_sweep = False + is_bump = False msg_wallet_low_coin = 'Wallet has insufficient funds for this transaction ({} {} needed)' msg_no_change_output = """ ERROR: No change address specified. If you wish to create a transaction with diff --git a/test/cmdtest_d/ethdev.py b/test/cmdtest_d/ethdev.py index 10b54a5d..f7974f4b 100755 --- a/test/cmdtest_d/ethdev.py +++ b/test/cmdtest_d/ethdev.py @@ -137,10 +137,10 @@ class CmdTestEthdevMethods: t.expect(f"'{addr}' deleted") return t - def _addrgen(self, addrs='1-3,11-13,21-23', no_msg=False): + def _addrgen(self, addrs='1-3,11-13,21-23', no_msg=False, coin=None): t = self.spawn( 'mmgen-addrgen', - [f'--coin={self.proto.coin}'] + self.eth_opts + [dfl_words_file, addrs], + [f'--coin={coin or self.proto.coin}'] + self.eth_opts + [dfl_words_file, addrs], no_msg = no_msg, no_passthru_opts = True) t.written_to_file('Addresses') diff --git a/test/cmdtest_d/rune.py b/test/cmdtest_d/rune.py index 32b2ef6d..d78e3d9d 100755 --- a/test/cmdtest_d/rune.py +++ b/test/cmdtest_d/rune.py @@ -38,12 +38,12 @@ class CmdTestRuneMethods: t.expect(prompt, 'q') return t - def _rune_txcreate(self, add_opts=[]): - t = self.spawn('mmgen-txcreate', self.rune_opts + add_opts + ['98831F3A:X:2,54.321']) - t.expect(self.menu_prompt, 'q') + def _rune_txcreate(self, args=['98831F3A:X:2,54.321'], add_opts=[], append_args=[], menu_prompt=None): + t = self.spawn('mmgen-txcreate', self.rune_opts + add_opts + args + append_args) + t.expect(menu_prompt or self.menu_prompt, 'q') t.expect('spend from: ', '3\n') t.expect('(y/N): ', 'y') # add comment? - t.expect('Comment: ', 'RUNE Boy\n') + t.expect('Comment: ', 'THOR Chad #1\n') t.expect('view: ', 'y') t.expect('to continue: ', 'z') t.expect('(y/N): ', 'y') # save? diff --git a/test/cmdtest_d/swap.py b/test/cmdtest_d/swap.py index 06397208..40ddfd3d 100755 --- a/test/cmdtest_d/swap.py +++ b/test/cmdtest_d/swap.py @@ -100,8 +100,9 @@ class CmdTestSwapMethods: reload_quote = False, sign_and_send = False, need_passphrase = True, - expect = None): - t.expect(self.menu_prompt, 'q') + menu_prompt = None, + expect = None): + t.expect(menu_prompt or self.menu_prompt, 'q') t.expect(self.input_sels_prompt, f'{inputs}\n') if reload_quote: t.expect('to continue: ', 'r') # reload swap quote @@ -292,7 +293,7 @@ class CmdTestSwap( ('subgroup.signsend', ['init_swap']), ('subgroup.signsend_bad', ['init_swap']), ('subgroup.autosign', ['signsend']), - ('swap_server_stop', 'stopping the Thornode server'), + ('swap_server_stop', 'stopping the Thornode swap server'), ('stop', 'stopping regtest daemons'), ) cmd_subgroups = {