tx.new_swap: new check_addr_is_wallet_addr() method

This commit is contained in:
The MMGen Project 2025-03-20 04:50:45 +03:00
commit 73210a3932
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 19 additions and 19 deletions

View file

@ -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):

View file

@ -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'

View file

@ -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'