Browse Source

tx.new_swap: new `check_addr_is_wallet_addr()` method

The MMGen Project 1 week ago
parent
commit
73210a3932
3 changed files with 19 additions and 19 deletions
  1. 4 17
      mmgen/proto/btc/tx/new.py
  2. 7 0
      mmgen/tx/new.py
  3. 8 2
      mmgen/tx/new_swap.py

+ 4 - 17
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):
 

+ 7 - 0
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'

+ 8 - 2
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'