autosign: support terse summary for XMR

This commit is contained in:
The MMGen Project 2026-11-15 10:56:44 +00:00
commit a93de25fca
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
7 changed files with 77 additions and 41 deletions

View file

@ -121,7 +121,8 @@ class Signable:
for nm in non_mmgen:
yield fs.format(
tx.txid.fmt(t_wid, color=True) if nm is non_mmgen[0] else ' '*t_wid,
nm.addr.fmt(nm.addr.view_pref, a_wid, color=True),
nm.addr.fmt(nm.addr.view_pref, a_wid, color=True)
if nm.addr else '-'.ljust(a_wid),
nm.amt.hl() + ' ' + yellow(tx.coin))
msg('\n' + '\n'.join(gen()))
@ -247,10 +248,9 @@ class Signable:
'no_restart_wallet_daemon': old_idx == new_idx})
def print_summary(self, signables):
info_func = 'get_info' if self.cfg.full_summary else 'get_info_oneline'
bmsg('\nAutosign summary:')
msg('\n'.join(
s.get_info(indent=' ') if hasattr(s, 'get_info') else s.info.format()
for s in signables) + self.summary_footer)
msg('\n'.join(getattr(s, info_func)(indent=' ') for s in signables) + self.summary_footer)
class xmr_transaction(xmr_signable, automount_transaction):
desc = 'Monero non-compat transaction'
@ -292,6 +292,13 @@ class Signable:
tx2.file.write(ask_write=False, outdir=self.dir)
return tx2
def print_summary(self, signables):
terse = not self.cfg.full_summary
bmsg('\nAutosign summary:')
msg(
('' if terse else '\n')
+ '\n'.join(tx.info.format(terse=terse) for tx in signables))
class xmr_wallet_outputs_file(xmr_signable, base):
desc = 'Monero wallet outputs file'
dir_name = 'xmr_outputs_dir'

View file

@ -11,7 +11,7 @@ proto.xmr.tx.completed: Monero completed transaction class
"""
from ....util import cached_property, make_timestamp
from ....color import cyan
from ....color import yellow, cyan
from ....tx.completed import Completed as TxCompleted
from .base import Base
@ -41,12 +41,19 @@ class Completed(Base, TxCompleted):
def info(self):
from ....tx.info import TxInfo
class info_cls(TxInfo):
def format(info_self, *args, **kwargs):
def format(info_self, *, terse=False, sort='addr'):
swap_hdr = (
(''.join(info_self.gen_swap_subhdr()) + '\n')
if (self.compat_data or self.raw_compat_data) and self.is_swap else
'')
return (
swap_hdr
+ yellow('XMR ')
+ self.compat_tx.get_info_oneline()
+ '\n'
) if terse else (
cyan(self.data_desc.upper())
+ '\n'
+ ((''.join(info_self.gen_swap_subhdr()) + '\n')
if (self.compat_data or self.raw_compat_data) and self.is_swap
else '')
+ swap_hdr
+ self.compat_tx.get_info(full_address=True, indent=' ', is_swap=self.is_swap))
return info_cls(self.cfg, self)

View file

@ -73,6 +73,8 @@ class MoneroWalletOutputsFile:
else:
return f'{indent}{self.wallet_fn.name}: no key images'
get_info_oneline = get_info
class New(Base):
ext = 'raw'

View file

@ -80,21 +80,27 @@ class MoneroMMGenTX:
def src_wallet_idx(self):
return int(self.data.source.split(':')[0])
def get_info_oneline(self, *, indent='', addr_col_w=None):
def get_info_oneline(self, *, indent='', addr_col_w=None, full_address=False, is_swap=False):
d = self.data
if addr_col_w:
e = purple(d.op.ljust(9))
f = red('{}:{}'.format(d.source.wallet, d.source.account).ljust(6))
g = red('{}:{}'.format(d.dest.wallet, d.dest.account).ljust(6)) if d.dest else cyan('ext ')
h = d.amount.fmt(4, color=True, prec=12)
j = d.dest_address.fmt(0, addr_col_w, color=True)
else:
e = purple(d.op)
f = red('{}:{}'.format(d.source.wallet, d.source.account))
g = red('{}:{}'.format(d.dest.wallet, d.dest.account)) if d.dest else cyan('ext')
h = d.amount.hl(color=True)
j = d.dest_address.hl(0)
return self.oneline_fs.format(
a = yellow(d.network),
b = d.seed_id.hl(),
c = make_timestr(d.submit_time if d.submit_time is not None else d.create_time),
d = orange(self.file_id),
e = purple(d.op.ljust(9)),
f = red('{}:{}'.format(d.source.wallet, d.source.account).ljust(6)),
g = red('{}:{}'.format(d.dest.wallet, d.dest.account).ljust(6))
if d.dest else cyan('ext '),
h = d.amount.fmt(4, color=True, prec=12),
j = d.dest_address.fmt(0, addr_col_w, color=True) if addr_col_w else
d.dest_address.hl(0),
x = '->')
a = yellow(d.network),
b = d.seed_id.hl(),
c = make_timestr(d.submit_time if d.submit_time is not None else d.create_time),
d = orange(self.file_id),
e=e, f=f, g=g, h=h, j=j,
x = '->')
def get_info(self, *, indent='', addr_col_w=None, full_address=False, is_swap=False):
d = self.data

View file

@ -584,6 +584,7 @@ class CmdTestAutosignThreaded(CmdTestAutosignBase):
dump_hex = False,
expect_pat = None,
is_xmr = False,
tx_view_resp = 't',
mark_sent = False):
if need_rbf and not self.proto.cap('rbf'):
@ -603,13 +604,13 @@ class CmdTestAutosignThreaded(CmdTestAutosignBase):
if '--status' in add_opts:
if '--verbose' in add_opts:
t.expect('view: ', 't')
t.expect('view: ', tx_view_resp)
if expect_pat:
t.expect(expect_pat, regex=True)
elif mark_sent:
t.written_to_file('Sent automount transaction')
else:
t.view_tx('t', expect_pat=expect_pat)
t.view_tx(tx_view_resp, expect_pat=expect_pat)
if not is_xmr:
t.do_comment(comment)
if dump_hex:
@ -641,25 +642,26 @@ class CmdTestAutosignThreaded(CmdTestAutosignBase):
self.remove_device_online()
return t
def _wait_loop_start(self, opts=[], add_opts=[]):
def _wait_loop_start(self, opts=[], add_opts=[], full_summary=True):
t = self.spawn(
'mmgen-autosign',
(opts or self.opts)
+ add_opts
# ensure that changes to online cfg file don’t affect autosign:
+ [f'--data-dir={autosign_data_dir}', '--regtest=1']
+ ['--full-summary', 'wait'],
+ (['--full-summary'] if full_summary else [])
+ ['wait'],
direct_exec = True,
no_passthru_opts = True,
env = {'EXEC_WRAPPER_DO_RUNTIME_MSG': ''})
self.write_to_tmpfile('autosign_thread_pid', str(t.ep.pid))
return t
def wait_loop_start(self, opts=[], add_opts=[]):
def wait_loop_start(self, opts=[], add_opts=[], full_summary=True):
import threading
threading.Thread(
target = self._wait_loop_start,
kwargs = {'opts': opts, 'add_opts': add_opts},
kwargs = {'opts': opts, 'add_opts': add_opts, 'full_summary': full_summary},
name = 'Autosign wait loop').start()
time.sleep(0.1) # try to ensure test output is displayed before next test starts
return 'silent'

View file

@ -78,10 +78,12 @@ class CmdTestXMRAutosign(CmdTestXMRWallet, CmdTestAutosignThreaded, CmdTestShare
('check_bal_user1', 'mining, checking balance (wallet #1)'),
('fund_user2', 'sending funds to user (wallet #2)'),
('check_bal_user2', 'mining, checking balance (wallet #2)'),
('wait_loop_start', 'starting autosign wait loop'),
('export_outputs1', 'exporting outputs from user’s watch-only wallet #1'),
('create_transfer_tx1', 'creating a transfer TX'),
('wait_loop_start_terse', 'starting autosign wait loop (no full summary)'),
('submit_transfer_tx1', 'submitting the transfer TX'),
('wait_loop_kill', 'stopping autosign wait loop'),
('wait_loop_start', 'starting autosign wait loop'),
('resubmit_transfer_tx1', 'resubmitting the transfer TX'),
('export_outputs2', 'exporting outputs from user’s watch-only wallet #1'),
('import_key_images1', 'importing signed key images into user’s online wallets'),
@ -125,6 +127,9 @@ class CmdTestXMRAutosign(CmdTestXMRWallet, CmdTestAutosignThreaded, CmdTestShare
self.autosign_setup_opts = ['--regtest=1', f'--xmrwallets={self.users[self.user].kal_range}']
self.spawn_env['MMGEN_TEST_SUITE_BOGUS_SEND'] = ''
def wait_loop_start_terse(self):
return self.wait_loop_start(full_summary=False)
def create_tmp_wallets(self):
self.spawn(msg_only=True)
data = self.users[self.user]
@ -844,7 +849,7 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
return t
def wait_loop_start_compat(self):
return self.wait_loop_start(opts=['--xmrwallet-compat', '--coins=xmr'])
return self.wait_loop_start(opts=['--xmrwallet-compat', '--coins=xmr'], full_summary=False)
wait_loop_start_compat2 = wait_loop_start_compat
@ -889,7 +894,7 @@ class CmdTestXMRCompat(CmdTestXMRAutosign):
return self._user_txstatus(['--quiet'], expect_str='confirmations')
def user_txstatus3(self):
return self._user_txstatus(['--verbose'], expect_str='TRANSACTION DATA')
return self._user_txstatus(['--verbose'], expect_str='transfer')
def _user_txstatus(self, add_opts=[], expect_str=None):
return self._user_txops(
@ -984,7 +989,7 @@ class CmdTestXMRAutosignDev(CmdTestXMRAutosign):
('check_bal_user1', 'mining, checking balance (wallet #1)'),
('export_outputs1', 'exporting outputs from user’s watch-only wallet #1'),
('create_transfer_tx1', 'creating a transfer TX'),
('wait_loop_start', 'starting autosign wait loop'),
('wait_loop_start_terse', 'starting autosign wait loop (no full summary)'),
# ('wait_signed1', 'autosigning the transaction'),
('submit_transfer_tx1', 'submitting the transfer TX'),
('wait_loop_kill', 'stopping autosign wait loop'),
@ -1028,7 +1033,7 @@ class CmdTestXMRCompatDev(CmdTestXMRCompat):
return self._user_txops('txcreate', menu='s', sweep_menu='1', sweep_type='sweep')
def wait_loop_start_xmr(self):
return self.wait_loop_start(opts=['--xmrwallet-compat', '--coins=xmr'])
return self.wait_loop_start(opts=['--xmrwallet-compat', '--coins=xmr'], full_summary=False)
async def user_gettxdata(self):
self.insert_device_online()

View file

@ -32,6 +32,7 @@ class CmdTestXMRSwapMethods:
auto_dest_addr = None,
reload_quote = False,
menu_prompt = None,
tx_view_resp = 't',
expect_pats = []):
if auto_chg_addr:
t.expect(rf'Using.*{auto_chg_addr}.*as change address.*: ', 'y', regex=True)
@ -50,7 +51,7 @@ class CmdTestXMRSwapMethods:
t.expect('(Y/n): ', 'y') # change OK?
if tx_type != 'xmr_swap':
t.expect('(y/N): ', 'n') # add comment?
t.expect('view: ', 't')
t.expect('view: ', tx_view_resp)
for pat in expect_pats:
t.expect(pat, regex=True)
t.expect('to continue: ', '\n')
@ -107,6 +108,7 @@ class CmdTestXMRSwapMethods:
'inputs': inputs,
'auto_chg_addr': auto_chg_addr,
'auto_dest_addr': auto_dest_addr,
'tx_view_resp': 'y',
'expect_pats': expect_pats},
output_args = args)
@ -117,6 +119,7 @@ class CmdTestXMRSwapMethods:
expect_pat = expect_pat,
is_xmr = is_xmr,
no_wait = no_wait,
tx_view_resp = 'y',
need_rbf = True)
class CmdTestXMRSwap(CmdTestXMRSwapMethods, CmdTestSwap):
@ -137,10 +140,8 @@ class CmdTestXMRSwap(CmdTestXMRSwapMethods, CmdTestSwap):
('subgroup.rune_setup', ['ltc_setup']),
('subgroup.autosign_setup', []),
('subgroup.xmr_setup', ['ltc_setup', 'autosign_setup']),
('subgroup.wait_loop', ['autosign_setup']),
('subgroup.swap', ['rune_setup', 'xmr_setup', 'wait_loop']),
('subgroup.swap', ['rune_setup', 'xmr_setup']),
('subgroup.xmr_swap', ['swap']),
('xmr_wait_loop_kill', ''),
('xmr_stop_daemons', ''))
cmd_subgroups = {
@ -183,10 +184,6 @@ class CmdTestXMRSwap(CmdTestXMRSwapMethods, CmdTestSwap):
('xmr_mine_blocks_10', ''),
('xmr_user_listaddresses_refresh', ''),
),
'wait_loop': (
'starting the autosign wait loop',
('xmr_wait_loop_start_compat', ''),
),
'swap': (
'swap operations (LTC -> XMR)',
('remote_get_refnum', 'getting the reference number'),
@ -195,6 +192,7 @@ class CmdTestXMRSwap(CmdTestXMRSwapMethods, CmdTestSwap):
('swaptxcreate_refreq2', 'creating an LTC->XMR registration transaction (auto chg, 1:0)'),
('swaptxcreate_abort2', 'aborting the transaction'),
('swaptxcreate_refreq3', 'creating an LTC->XMR registration transaction (auto chg, mmid dest)'),
('wait_loop_start_terse', 'starting the signing loop (terse summary)'),
('swaptxsend_refreq1', 'sending the transaction'),
('swaptxcreate_refreq4', 'creating an LTC->XMR registration transaction (auto chg, 1:1)'),
('swaptxsend_refreq2', 'sending the transaction'),
@ -203,6 +201,7 @@ class CmdTestXMRSwap(CmdTestXMRSwapMethods, CmdTestSwap):
('generate_ltc', 'generating a block'),
('swaptxcreate_refnum2', 'creating an LTC->XMR swap transaction (no chg, auto dest)'),
('swaptxsend_refnum2', 'sending the swap transaction'),
('wait_loop_kill', 'killing the signing loop'),
('generate_ltc', 'generating a block'),
('bob_bal2', 'Bob’s balance')),
'xmr_swap': (
@ -210,11 +209,13 @@ class CmdTestXMRSwap(CmdTestXMRSwapMethods, CmdTestSwap):
('remote_get_refnum_xmr', 'getting the reference number'),
('swaptxcreate_refreq7_bad', 'creating an XMR->LTC registration transaction (bad, no amount)'),
('swaptxcreate_refreq7', 'creating an XMR->LTC registration transaction (auto chg, auto dest)'),
('wait_loop_start_xmrcompat', 'starting the signing loop (--xmrwallet-compat)'),
('swaptxsend_refreq7', 'sending the transaction'),
('swaptxcreate_refnum7_bad', 'creating an XMR->LTC swap transaction (bad, no amount)'),
('swaptxcreate_refnum7', 'creating an XMR->LTC swap transaction (auto chg, auto dest)'),
('xmr_swaptxview_refnum7', ''),
('swaptxsend_refnum7', 'sending the transaction'),
('wait_loop_kill', 'killing the signing loop'),
('swaptxstatus_refnum7a', 'getting the transaction status (mempool)'),
('xmr_mine_blocks_10', ''),
('swaptxstatus_refnum7b', 'getting the transaction status (confirmations)'),
@ -233,6 +234,12 @@ class CmdTestXMRSwap(CmdTestXMRSwapMethods, CmdTestSwap):
globals()[self.cross_group] = self.create_cross_runner(trunner, add_cfg={})
def wait_loop_start_terse(self):
return self.wait_loop_start(opts=['--coins=ltc'], full_summary=False)
def wait_loop_start_xmrcompat(self):
return self.wait_loop_start(opts=['--coins=xmr', '--xmrwallet-compat'])
def fund_bob1(self):
return self.fund_wallet('bob', 500, mmtype='C')