Browse Source

tx.new: prompt user if change address is not wallet address

The MMGen Project 3 weeks ago
parent
commit
6df695024e

+ 9 - 1
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:

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

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

+ 3 - 0
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):

+ 3 - 0
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: