From 73cf5814cf901f9b8e3ab379c9be591b946f04cb Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 6 Sep 2026 10:08:41 +0000 Subject: [PATCH] proto.vm.tx.new: improve cmd args processing --- mmgen/proto/vm/tx/new.py | 24 ++++++++++++------------ mmgen/tx/new.py | 2 +- mmgen/tx/new_swap.py | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mmgen/proto/vm/tx/new.py b/mmgen/proto/vm/tx/new.py index aa3bdc3a..63a3756c 100755 --- a/mmgen/proto/vm/tx/new.py +++ b/mmgen/proto/vm/tx/new.py @@ -42,20 +42,20 @@ class New: async def process_cmdline_args(self, cmd_args, ad_f, ad_w): - lc = len(cmd_args) - - if lc == 2 and self.is_swap: - data_arg = cmd_args.pop() - lc = 1 - assert data_arg.startswith('data:'), f'{data_arg}: invalid data arg (must start with "data:")' - self.swap_memo = data_arg.removeprefix('data:') + def process_data_arg(arg): + assert arg.startswith('data:'), f'{arg}: invalid data arg (must start with "data:")' + self.swap_memo = arg.removeprefix('data:') self.set_gas_with_data(self.swap_memo.encode()) - if lc == 0 and self.usr_contract_data and 'Token' not in self.name: - return - - if lc != 1: - die(1, f'{lc} output{suf(lc)} specified, but VM transactions must have exactly one') + match len(cmd_args): + case 1: + pass + case 0 if self.usr_contract_data and 'Token' not in self.name: + return + case 2 if self.is_swap: + process_data_arg(cmd_args[1]) + case n: + die(1, f'{n} output{suf(n)} specified, but VM transactions must have exactly one') a = self.parse_cmdline_arg(self.proto, cmd_args[0], ad_f, ad_w) diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index e0fa44db..a34fd75f 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -198,7 +198,7 @@ class New(Base): else: die(2, f'{arg_in}: invalid command-line argument') - return _pa(arg, mmid, coin_addr, amt, None, is_vault) + return _pa(arg, mmid or None, coin_addr, amt, None, is_vault) async def get_autochg_addr(self, proto, arg, *, exclude, desc, all_addrtypes=False): from ..tw.addresses import TwAddresses diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index 86187965..b7d96831 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -174,7 +174,7 @@ class NewSwap(New): [f'vault,{args.send_amt}', chg_output.mmid] if args.send_amt else ['vault']) - return ret + [f'data:{memo}'] + return tuple(ret + [f'data:{memo}']) def update_vault_addr(self, c, *, addr='inbound_address'): vault_idx = self.vault_idx