cfg, txsign, test suite: minor cleanups

This commit is contained in:
The MMGen Project 2026-09-02 13:52:39 +00:00
commit 955fe5aa28
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 11 additions and 9 deletions

View file

@ -539,7 +539,7 @@ class Config(Lockable):
# Step 3: set cfg from environment, skipping already-set opts; save names set from environment:
self._envopts = tuple(self._set_cfg_from_env()) if self._use_env else ()
# Step 4: finalize some cmdline-only opts:
# Step 4: finalize some non-cfg-file opts:
self.coin = self.coin.upper()
self.token = self.token.upper() if self.token else None
if (
@ -803,7 +803,7 @@ class Config(Lockable):
bad = [k for k in self.__dict__
if k in group and k in self._uopts and getattr(self, k) is not None]
if len(bad) > 1:
die(1, 'Conflicting options: {}'.format(', '.join(map(fmt_opt, bad))))
die('UserOptError', 'Conflicting options: {}'.format(', '.join(map(fmt_opt, bad))))
def _set_quiet(self, val):
from .util import Util
@ -1004,7 +1004,7 @@ def conv_type(name, val, refval, *, src, invert_bool=False):
'cmdline': 'command-line',
'cfg': 'Config',
'env': 'environment var'}
die(1, '{a!r}: invalid value for {b} option {c!r}{d} (must be of type {e!r})'.format(
die('UserOptError', '{a!r}: invalid value for {b} option {c!r}{d} (must be of type {e!r})'.format(
a = val,
b = desc.get(src, 'config file'),
c = fmt_opt(name) if src == 'cmdline' else name,

View file

@ -143,7 +143,9 @@ async def main():
if not cfg.yes:
tx1.info.view_with_prompt(f'View data for transaction{tx_num_disp}?')
if tx2 := await tx1.sign(TxKeys(cfg, tx1, seedfiles=seedfiles).keys, tx_num_disp):
if tx2 := await tx1.sign(
TxKeys(cfg, tx1, seedfiles=seedfiles).keys,
tx_num_str = tx_num_disp):
if not cfg.yes:
tx2.add_comment() # edits an existing comment
tx2.file.write(ask_write=not cfg.yes, ask_write_default_yes=True, add_desc=tx_num_disp)

View file

@ -21,7 +21,7 @@ class Unsigned(Completed, TxBase.Unsigned):
desc = 'unsigned transaction'
# Return signed object or False. Don’t exit or raise exception:
async def proto_sign(self, keys, tx_num_str=''):
async def proto_sign(self, keys, *, tx_num_str):
if (self.has_segwit_inputs() or self.has_segwit_outputs()) and not self.proto.cap('segwit'):
ymsg(f"TX has Segwit inputs or outputs, but {self.coin} doesn't support Segwit!")

View file

@ -18,7 +18,7 @@ class Unsigned:
desc = 'unsigned transaction'
# Return signed object or False. Don’t exit or raise exception:
async def proto_sign(self, keys, tx_num_str=''):
async def proto_sign(self, keys, *, tx_num_str):
o = self.txobj

View file

@ -21,7 +21,7 @@ class Unsigned(Completed):
automount = False
# Return signed object or False. Don’t exit or raise exception, unless fatal:
async def sign(self, keys, tx_num_str=''):
async def sign(self, keys, *, tx_num_str=''):
if self.file_format == 'legacy': # fatal
die('LegacyTxSignRequestError',

View file

@ -136,7 +136,7 @@ class CmdTestRuneSwapRune(CmdTestSwapMethods, CmdTestRune):
t = self._swaptxsend(add_opts=[f'--dump-hex={self.txhex_file}'], dump_hex=True)
t.read()
txhex = get_data_from_file(self.cfg, self.txhex_file, silent=True)
if md5(txhex.encode()).hexdigest()[:8] != self.txhex_chksum:
self.tr.parent_group.tr.warn('txid mismatch')
if (chk := md5(txhex.encode()).hexdigest()[:8]) != self.txhex_chksum:
self.tr.parent_group.tr.warn(f'txid mismatch ({chk} != {self.txhex_chksum})')
return 'ok'
return t