From 73210a3932f7d40ef6302b04311d79cf7a3b4fb5 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 20 Mar 2025 04:50:45 +0300 Subject: [PATCH] tx.new_swap: new `check_addr_is_wallet_addr()` method --- mmgen/proto/btc/tx/new.py | 21 ++++----------------- mmgen/tx/new.py | 7 +++++++ mmgen/tx/new_swap.py | 10 ++++++++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index 5c89ad72..0b7ad853 100755 --- a/mmgen/proto/btc/tx/new.py +++ b/mmgen/proto/btc/tx/new.py @@ -15,7 +15,7 @@ proto.btc.tx.new: Bitcoin new transaction class from ....tx.new import New as TxNew from ....obj import MMGenTxID from ....util import msg, fmt, make_chksum_6, die, suf -from ....color import pink, yellow +from ....color import pink from .base import Base class New(Base, TxNew): @@ -126,22 +126,9 @@ class New(Base, TxNew): def final_inputs_ok_msg(self, funds_left): return 'Transaction produces {} {} in change'.format(funds_left.hl(), self.coin) - def check_chg_addr_is_wallet_addr( - self, - output = None, - *, - message = 'Change address is not an MMGen wallet address!'): - def do_err(): - from ....ui import confirm_or_raise - confirm_or_raise( - cfg = self.cfg, - message = yellow(message), - action = 'Are you sure this is what you want?') - if output: - if not output.mmid: - do_err() - elif len(self.nondata_outputs) > 1 and not self.chg_output.mmid: - do_err() + def check_chg_addr_is_wallet_addr(self): + if len(self.nondata_outputs) > 1 and not self.chg_output.mmid: + self._non_wallet_addr_confirm('Change address is not an MMGen wallet address!') async def create_serialized(self, *, locktime=None): diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index 36504e01..03512276 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -424,6 +424,13 @@ class New(Base): else: self.warn_insufficient_funds(funds.amt, self.coin) + def _non_wallet_addr_confirm(self, message): + from ..ui import confirm_or_raise + confirm_or_raise( + cfg = self.cfg, + message = yellow(message), + action = 'Are you sure this is what you want?') + async def create(self, cmd_args, *, locktime=None, do_info=False, caller='txcreate'): assert isinstance(locktime, (int, type(None))), 'locktime must be of type int' diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index 71f9939d..ee444ff3 100755 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -28,6 +28,10 @@ class NewSwap(New): self.swap_proto_mod = importlib.import_module(f'mmgen.swap.proto.{self.swap_proto}') New.__init__(self, *args, **kwargs) + def check_addr_is_wallet_addr(self, output, *, message): + if not output.mmid: + self._non_wallet_addr_confirm(message) + async def get_swap_output(self, proto, arg, addrfiles, desc): ret = namedtuple('swap_output', ['coin', 'network', 'addr', 'mmid']) if arg: @@ -117,11 +121,13 @@ class NewSwap(New): if args.send_amt else None) if chg_output: - self.check_chg_addr_is_wallet_addr(chg_output) + self.check_addr_is_wallet_addr( + chg_output, + message = 'Change address is not an MMGen wallet address!') recv_output = await self.get_swap_output(self.recv_proto, args.recv_spec, addrfiles, 'destination address') - self.check_chg_addr_is_wallet_addr( + self.check_addr_is_wallet_addr( recv_output, message = ( 'Swap destination address is not an MMGen wallet address!\n'