From c04512a42fda5bb4c8011c4f3be9dd206180a1ad Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 18 Jun 2025 12:55:47 +0000 Subject: [PATCH] minor fixes and cleanups --- mmgen/main_txbump.py | 10 +++++----- mmgen/main_txsign.py | 19 ++++++++----------- mmgen/proto/btc/tx/unsigned.py | 3 ++- mmgen/proto/vm/tx/unsigned.py | 3 ++- mmgen/tx/sign.py | 2 +- test/cmdtest_d/ethswap.py | 4 ++-- test/cmdtest_d/httpd/etherscan.py | 12 ++++++------ 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/mmgen/main_txbump.py b/mmgen/main_txbump.py index a72f36c3..c5ec2419 100755 --- a/mmgen/main_txbump.py +++ b/mmgen/main_txbump.py @@ -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) diff --git a/mmgen/main_txsign.py b/mmgen/main_txsign.py index e347ec45..bdbc5cd4 100755 --- a/mmgen/main_txsign.py +++ b/mmgen/main_txsign.py @@ -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) diff --git a/mmgen/proto/btc/tx/unsigned.py b/mmgen/proto/btc/tx/unsigned.py index 5dd3f1fe..443062d3 100755 --- a/mmgen/proto/btc/tx/unsigned.py +++ b/mmgen/proto/btc/tx/unsigned.py @@ -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: diff --git a/mmgen/proto/vm/tx/unsigned.py b/mmgen/proto/vm/tx/unsigned.py index 1e780050..e7f262e4 100755 --- a/mmgen/proto/vm/tx/unsigned.py +++ b/mmgen/proto/vm/tx/unsigned.py @@ -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: diff --git a/mmgen/tx/sign.py b/mmgen/tx/sign.py index 2a170e0d..54ff9104 100755 --- a/mmgen/tx/sign.py +++ b/mmgen/tx/sign.py @@ -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 diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index b1d7b8ed..326804b3 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -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': ( diff --git a/test/cmdtest_d/httpd/etherscan.py b/test/cmdtest_d/httpd/etherscan.py index ac4299cf..272c7d22 100755 --- a/test/cmdtest_d/httpd/etherscan.py +++ b/test/cmdtest_d/httpd/etherscan.py @@ -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()