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

This commit is contained in:
The MMGen Project 2025-02-15 09:54:19 +00:00
commit 6df695024e
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 20 additions and 1 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
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:

View file

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

View file

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

View file

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

View file

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