minor fixes and cleanups

This commit is contained in:
The MMGen Project 2025-06-18 12:55:47 +00:00
commit c04512a42f
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
7 changed files with 26 additions and 27 deletions

View file

@ -143,7 +143,7 @@ cfg = Config(opts_data=opts_data)
from .tx import CompletedTX, BumpTX, UnsignedTX, OnlineSignedTX
from .tx.sign import txsign, get_seed_files, get_keyaddrlist, get_keylist
seed_files = get_seed_files(
seedfiles = get_seed_files(
cfg,
cfg._args,
ignore_dfl_wallet = not cfg.send,
@ -176,12 +176,12 @@ async def main():
f'your {state} transaction, abort it with ‘mmgen-txsend --abort’ and create\n'
'a new one.')
orig_tx = await si.get_last_created()
kal = kl = sign_and_send = None
sign_and_send = False
else:
orig_tx = await CompletedTX(cfg=cfg, filename=tx_file)
kal = get_keyaddrlist(cfg, orig_tx.proto)
kl = get_keylist(cfg)
sign_and_send = any([seed_files, kl, kal])
kal = get_keyaddrlist(cfg, orig_tx.proto)
sign_and_send = any([seedfiles, kl, kal])
if not silent:
msg(green('ORIGINAL TRANSACTION'))
@ -207,7 +207,7 @@ async def main():
if sign_and_send:
tx2 = UnsignedTX(cfg=cfg, data=tx.__dict__)
tx3 = await txsign(cfg, tx2, seed_files, kl, kal)
tx3 = await txsign(cfg, tx2, seedfiles, kl, kal)
if tx3:
tx4 = await OnlineSignedTX(cfg=cfg, data=tx3.__dict__)
tx4.file.write(ask_write=False)

View file

@ -35,8 +35,7 @@ opts_data = {
-h, --help Print this help message
--, --longhelp Print help message for long (global) options
-a, --autosign Sign a transaction created for offline autosigning (see
mmgen-autosign). The removable device is mounted and
unmounted automatically
mmgen-autosign)
-b, --brain-params=l,p Use seed length 'l' and hash preset 'p' for
brainwallet input
-d, --outdir= d Specify an alternate directory 'd' for output
@ -102,13 +101,11 @@ column below:
cfg = Config(opts_data=opts_data)
infiles = cfg._args
if not infiles:
if not cfg._args:
cfg._usage()
from .fileutil import check_infile
for i in infiles:
for i in cfg._args:
check_infile(i)
if not cfg.info and not cfg.terse_info:
@ -117,19 +114,19 @@ if not cfg.info and not cfg.terse_info:
from .tx.sign import txsign, get_tx_files, get_seed_files, get_keylist, get_keyaddrlist
tx_files = get_tx_files(cfg, infiles)
seed_files = get_seed_files(cfg, infiles)
txfiles = get_tx_files(cfg, cfg._args)
seed_files = get_seed_files(cfg, cfg._args)
async def main():
bad_tx_count = 0
tx_num_disp = ''
for tx_num, tx_file in enumerate(tx_files, 1):
for tx_num, tx_file in enumerate(txfiles, 1):
if len(tx_files) > 1:
if len(txfiles) > 1:
tx_num_disp = f' #{tx_num}'
msg(orange(f'\nTransaction{tx_num_disp} of {len(tx_files)}:'))
msg(orange(f'\nTransaction{tx_num_disp} of {len(txfiles)}:'))
from .tx import UnsignedTX
tx1 = UnsignedTX(cfg=cfg, filename=tx_file)

View file

@ -20,7 +20,8 @@ from .completed import Completed
class Unsigned(Completed, TxBase.Unsigned):
desc = 'unsigned transaction'
async def sign(self, tx_num_str, keys): # return signed object or False; don't exit or raise exception
# Return signed object or False. Don’t exit or raise exception:
async def sign(self, keys, tx_num_str=''):
from ....exception import TransactionChainMismatch
try:

View file

@ -17,7 +17,8 @@ from ....util import msg, msg_r, die
class Unsigned:
desc = 'unsigned transaction'
async def sign(self, tx_num_str, keys): # return TX object or False; don't exit or raise exception
# Return signed object or False. Don’t exit or raise exception:
async def sign(self, keys, tx_num_str=''):
from ....exception import TransactionChainMismatch
try:

View file

@ -205,4 +205,4 @@ async def txsign(cfg_parm, tx, seed_files, kl, kal, *, tx_num_str='', passwd_fil
if extra_sids:
msg(f"Unused Seed ID{suf(extra_sids)}: {' '.join(extra_sids)}")
return await tx.sign(tx_num_str, keys) # returns signed TX object or False
return await tx.sign(keys, tx_num_str) # returns signed TX object or False

View file

@ -140,9 +140,9 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest):
('subgroup.token_init', ['eth_fund']),
('subgroup.token_swap', ['fund', 'token_init']),
('subgroup.eth_token_swap', ['fund', 'token_init']),
('stop', 'stopping regtest daemon'),
('eth_stop', 'stopping Ethereum daemon'),
('swap_server_stop', 'stopping the Thornode server'),
('eth_stop', 'stopping the Ethereum daemon'),
('stop', 'stopping the regtest daemon'),
)
cmd_subgroups = {
'init': (

View file

@ -12,6 +12,8 @@
test.cmdtest_d.httpd.etherscan: Etherscan WSGI http server
"""
from mmgen.util2 import get_keccak
from . import HTTPD
class EtherscanServer(HTTPD):
@ -26,13 +28,11 @@ class EtherscanServer(HTTPD):
target = 'result'
length = int(environ.get('CONTENT_LENGTH', '0'))
qs = environ['wsgi.input'].read(length).decode()
tx = [s for s in qs.split('&') if 'RawTx=' in s][0].split('=')[1][:10]
if tx == '0xf86f0185':
txid = '1c034395c9aa2217abbbf3ed4d89c5ad1aa0f0215aa11d02efeea33a5ac8331c'
else:
txid = 'beadcafebeadcafebeadcafebeadcafebeadcafebeadcafebeadcafebeadcafe'
tx = [s for s in qs.split('&') if 'RawTx=' in s][0].split('=')[1]
keccak_256 = get_keccak()
txid = '0x' + keccak_256(bytes.fromhex(tx[2:])).hexdigest()
with open(f'test/ref/ethereum/etherscan-{target}.html') as fh:
text = fh.read()
return (text if method == 'GET' else text.format(txid='0x'+txid)).encode()
return (text if method == 'GET' else text.format(txid=txid)).encode()