From 6df695024eb81962adb35d6f44b2072937151a67 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 15 Feb 2025 09:54:19 +0000 Subject: [PATCH] tx.new: prompt user if change address is not wallet address --- mmgen/proto/btc/tx/new.py | 10 +++++++++- mmgen/proto/eth/tx/new.py | 3 +++ mmgen/tx/new.py | 2 ++ test/cmdtest_d/ct_regtest.py | 3 +++ test/cmdtest_d/ct_shared.py | 3 +++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mmgen/proto/btc/tx/new.py b/mmgen/proto/btc/tx/new.py index 0ff7f6a0..e2affba3 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 +from ....color import pink, yellow from .base import Base class New(Base, TxNew): @@ -125,6 +125,14 @@ 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): + if len([o for o in self.outputs if not o.data]) > 1 and not self.chg_output.mmid: + from ....ui import confirm_or_raise + confirm_or_raise( + cfg = self.cfg, + message = yellow('Change address is not an MMGen wallet address!'), + action = 'Are you sure this is what you want?') + async def create_serialized(self, locktime=None, bump=None): if not bump: diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index 37956979..6e618dda 100755 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -119,6 +119,9 @@ class New(Base, TxBase.New): async def get_rel_fee_from_network(self): return Int(await self.rpc.call('eth_gasPrice'), 16), 'eth_gasPrice' + def check_chg_addr_is_wallet_addr(self): + pass + def check_fee(self): if not self.disable_fee_check: assert self.usr_fee <= self.proto.max_tx_fee diff --git a/mmgen/tx/new.py b/mmgen/tx/new.py index a9cf2174..3a14eff6 100755 --- a/mmgen/tx/new.py +++ b/mmgen/tx/new.py @@ -456,6 +456,8 @@ class New(Base): self.update_change_output(funds_left) + self.check_chg_addr_is_wallet_addr() + if not self.cfg.yes: self.add_comment() # edits an existing comment diff --git a/test/cmdtest_d/ct_regtest.py b/test/cmdtest_d/ct_regtest.py index 31d90128..efeb7789 100755 --- a/test/cmdtest_d/ct_regtest.py +++ b/test/cmdtest_d/ct_regtest.py @@ -1043,6 +1043,7 @@ class CmdTestRegtest(CmdTestBase, CmdTestShared): wf = None, add_comment = tx_comment_jp, return_early = False, + tweaks = [], return_after_send = False, menu = ['M'], skip_passphrase = False, @@ -1067,6 +1068,7 @@ class CmdTestRegtest(CmdTestBase, CmdTestShared): interactive_fee = (tx_fee, '')[bool(fee)], add_comment = add_comment, return_early = return_early, + tweaks = tweaks, view = 't', save = True, used_chg_addr_resp = used_chg_addr_resp) @@ -1144,6 +1146,7 @@ class CmdTestRegtest(CmdTestBase, CmdTestShared): fee = rtFee[3], outputs_cl = outputs_cl, # alice_sid:S:2,10, alice_sid:S:3 outputs_list = '1,4-10', + tweaks = ['confirm_chg_non_mmgen'], extra_args = [f'--keys-from-file={keyfile}', '--vsize-adj=1.02']) def alice_send_estimatefee(self): diff --git a/test/cmdtest_d/ct_shared.py b/test/cmdtest_d/ct_shared.py index fbcc7f1f..c44fc9f2 100755 --- a/test/cmdtest_d/ct_shared.py +++ b/test/cmdtest_d/ct_shared.py @@ -109,6 +109,9 @@ class CmdTestShared: if 'confirm_non_mmgen' in tweaks: t.expect('Continue? (Y/n)', '\n') + if 'confirm_chg_non_mmgen' in tweaks: + t.expect('to confirm: ', 'YES\n') + t.do_comment(add_comment) if return_early: