various changes and cleanups

This commit is contained in:
The MMGen Project 2026-10-12 10:04:48 +00:00
commit 9ad34f5001
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 35 additions and 15 deletions

View file

@ -53,13 +53,13 @@ class TxInfo(TxInfo):
sort,
','.join(self.sort_orders)))
def get_mmid_fmt(e, is_input):
def get_mmid_fmt(e, is_output, *, terse=False):
if e.mmid:
return e.mmid.fmt2(
max_mmwid,
encl = '()',
color = True,
append_chars = ('', ' (chg)')[bool(not is_input and e.is_chg and terse)],
append_chars = ('', ' (chg)')[bool(is_output and e.is_chg and terse)],
append_color = 'green')
else:
return MMGenID.fmtc(
@ -69,7 +69,7 @@ class TxInfo(TxInfo):
def format_io(desc):
io = getattr(tx, desc)
is_input = desc == 'inputs'
is_output = desc == 'outputs'
yield desc.capitalize() + ':\n' + enl
confs_per_day = 60*60*24 // tx.proto.avg_bdi
@ -93,7 +93,7 @@ class TxInfo(TxInfo):
for n, e in enumerate(io_sorted()):
yield '{:3} {} {} {}\n'.format(
n + 1,
e.addr.fmt(vp1, addr_w, color=True) + ' ' + get_mmid_fmt(e, is_input)
e.addr.fmt(vp1, addr_w, color=True) + ' ' + get_mmid_fmt(e, is_output, terse=True)
if e.addr else data_disp(e.data),
e.amt.fmt(iwidth, color=True),
tx.dcoin)
@ -107,7 +107,7 @@ class TxInfo(TxInfo):
def gen_input(n, e):
yield (n + 1, 'tx,vout:', f'{e.txid.hl()},{red(str(e.vout))}')
yield ('', 'address:', f'{e.addr.hl(vp1)} {get_mmid_fmt(e, True)}')
yield ('', 'address:', f'{e.addr.hl(vp1)} {get_mmid_fmt(e, False)}')
if have_bch:
yield ('', '', f'[{e.addr.hl(vp2, color=False)}]')
yield from gen_common(e)
@ -116,7 +116,7 @@ class TxInfo(TxInfo):
yield ('', 'confirmations:', f'{nc} (around {nc // confs_per_day} days)')
def gen_output(n, e):
yield (n + 1, 'address:', (f'{e.addr.hl(vp1)} {get_mmid_fmt(e, False)}'
yield (n + 1, 'address:', (f'{e.addr.hl(vp1)} {get_mmid_fmt(e, True)}'
if e.addr else e.data.hl(add_label=True)))
if have_bch and e.addr:
yield ('', '', f'[{e.addr.hl(vp2, color=False)}]')
@ -125,7 +125,7 @@ class TxInfo(TxInfo):
yield ('', 'change:', green('True'))
lcw = len(str(len(io))) + 1
gen = gen_input if is_input else gen_output
gen = gen_output if is_output else gen_input
for n, e in enumerate(io_sorted()):
yield '\n'.join(f'{a:>{lcw}} {b:<8} {c}' for a, b, c in gen(n, e)) + '\n\n'

View file

@ -24,7 +24,8 @@ def process_response(json_response, errmsg):
data = json.loads(json_response)
if isinstance(data, dict) and 'result' in data:
if data['result'] is None:
from ....util import die
from ....util import ymsg, pp_fmt, die
ymsg(pp_fmt(data))
die('RPCFailure', errmsg)
return data['result']
return data

View file

@ -22,10 +22,10 @@ from .shared import CmdTestShared
class CmdTestRuneMethods:
def _rune_bal_refresh(self, menu_prompt=None):
def _rune_bal_refresh(self, menu_prompt=None, add_opts=[]):
t = self.spawn(
'mmgen-tool',
self.rune_opts + self.add_eth_opts + ['listaddresses', 'interactive=1'])
self.rune_opts + self.add_eth_opts + add_opts + ['listaddresses', 'interactive=1'])
prompt = menu_prompt or self.menu_prompt
t.expect(prompt, 'R')
t.expect('menu): ', '3\n')
@ -55,11 +55,13 @@ class CmdTestRuneMethods:
no_passthru_opts = ['coin']),
has_label = True)
def _rune_txsend(self, add_opts=[], *, test=False, dump_hex=False):
def _rune_txsend(self, add_opts=[], *, test=False, dump_hex=False, spawn_only=False):
t = self.spawn(
'mmgen-txsend',
self.rune_opts + add_opts + [self.get_file_with_ext('sigtx')],
no_passthru_opts = ['coin'])
if spawn_only:
return t
t.expect('view: ', 'y')
t.expect('to continue: ', 'z')
t.expect('(y/N): ', 'n') # edit comment?

View file

@ -142,7 +142,14 @@ class CmdTestSwapMethods:
'--ltc-rpc-port=19571'],
spawn_only = spawn_only)
def _swaptxsend(self, *, add_opts=[], spawn_only=False, status=False, dump_hex=False):
def _swaptxsend(
self,
*,
add_opts = [],
spawn_only = False,
status = False,
dump_hex = False,
expect_pats = None):
fn = self.get_file_with_ext('sigtx')
t = self.spawn(
'mmgen-txsend',
@ -151,6 +158,8 @@ class CmdTestSwapMethods:
if spawn_only:
return t
t.view_tx('v')
if expect_pats:
t.expect(expect_pats, regex=True)
if status:
return t
t.expect('(y/N): ', 'n')
@ -174,14 +183,21 @@ class CmdTestSwapMethods:
t.written_to_file('Signed transaction')
return t
def _swaptxbump(self, fee, *, add_opts=[], output_args=[], exit_val=None):
def _swaptxbump(self, fee, *, add_opts=[], output_args=[], single_output=False, exit_val=None):
self.get_file_with_ext('rawtx', delete_all=True)
fn = self.get_file_with_ext('sigtx')
t = self.spawn(
'mmgen-txbump',
['-q', '-d', self.tmpdir] + self.bob_opt + add_opts + output_args + [fn],
exit_val = exit_val)
return self._swaptxbump_ui_common(t, interactive_fee=fee, new_outputs=bool(output_args))
t = self._swaptxbump_ui_common(
t,
interactive_fee = fee,
single_output = single_output,
new_outputs = bool(output_args))
t.read()
os.unlink(fn) # bumped sigtx replaces the original
return t
def _swaptxbump_ui_common_new_outputs(
self,
@ -205,6 +221,7 @@ class CmdTestSwapMethods:
inputs = None,
interactive_fee = None,
file_desc = None,
single_output = False,
new_outputs = False):
if new_outputs:
if not self.proto.is_vm:
@ -212,7 +229,7 @@ class CmdTestSwapMethods:
t.expect('(Y/n): ', 'y') # fee ok?
t.expect('(Y/n): ', 'y') # change ok?
else:
if not self.proto.is_vm:
if not (self.proto.is_vm or single_output):
t.expect('ENTER for the change output): ', '\n')
t.expect('(Y/n): ', 'y') # confirm deduct from chg output
t.expect('to continue: ', '\n') # exit swap quote