From b625d9ba5525e221c233c08139bed1ab0371b518 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 22 Nov 2026 09:28:48 +0000 Subject: [PATCH] TxKeys: set `num_mkeys` correctly; check_swap_memo(): cleanup --- mmgen/tx/completed.py | 5 +++-- mmgen/tx/keys.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mmgen/tx/completed.py b/mmgen/tx/completed.py index b1677c63..1f363d2f 100644 --- a/mmgen/tx/completed.py +++ b/mmgen/tx/completed.py @@ -100,15 +100,16 @@ class Completed(Base): r.coin, tokensym = r.tokensym, need_amt = True) + if mmid := getattr(self, 'swap_recv_addr_mmid', None): - pass + return self.Output(proto, addr=p.address, mmid=mmid, amt=proto.coin_amt('0')) elif not self.is_swap: pass elif self.cfg.allow_non_wallet_swap: ymsg('Warning: allowing swap to non-wallet address (--allow-non-wallet-swap)') + return self.Output(proto, addr=p.address, mmid=None, amt=proto.coin_amt('0')) else: raise ValueError('Swap to non-wallet address forbidden (override with --allow-non-wallet-swap)') - return self.Output(proto, addr=p.address, mmid=mmid, amt=proto.coin_amt('0')) if self.is_swap and not self.is_memoless: raise ValueError('missing or invalid memo in swap transaction') diff --git a/mmgen/tx/keys.py b/mmgen/tx/keys.py index 5c9ae9eb..820ff71b 100644 --- a/mmgen/tx/keys.py +++ b/mmgen/tx/keys.py @@ -215,12 +215,12 @@ class TxKeys: memo_output = self.tx.check_swap_memo() # do this for non-swap transactions too! okeys, mkeys = ([], []) num_okeys = len([e for e in self.tx.outputs if e.mmid and not e.have_wif]) - num_mkeys = 1 + num_mkeys = 1 if memo_output and memo_output.mmid else None if self.keyaddrlist: ret += self.add_keys('inputs', self.tx.inputs, from_keyaddrlist=True) okeys += self.add_keys('outputs', self.tx.outputs, from_keyaddrlist=True) - if memo_output: + if num_mkeys: mkeys += self.add_keys('swap destination address', [memo_output], from_keyaddrlist=True) ret += self.add_keys('inputs', self.tx.inputs) @@ -229,7 +229,7 @@ class TxKeys: if len(okeys) != num_okeys: die('TxKeysError', 'Could not resolve all MMGen outputs') - if memo_output: + if num_mkeys: mkeys += self.add_keys('swap destination address', [memo_output]) if len(mkeys) != num_mkeys and not self.cfg.allow_non_wallet_swap: die('TxKeysError', 'Unable to resolve memo destination address')