From 2c3fa1c49a7d6f963da69b00342ee6dbc4872b79 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 15 Mar 2025 18:24:53 +0000 Subject: [PATCH] minor cleanups --- mmgen/main_txsend.py | 4 ++-- mmgen/proto/eth/tx/base.py | 4 ++-- mmgen/proto/eth/tx/bump.py | 2 +- mmgen/proto/eth/tx/new.py | 5 ++--- mmgen/util2.py | 9 +++++++++ test/cmdtest_d/ct_xmrwallet.py | 10 +--------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/mmgen/main_txsend.py b/mmgen/main_txsend.py index 2b66c74a..cf35fe33 100755 --- a/mmgen/main_txsend.py +++ b/mmgen/main_txsend.py @@ -43,7 +43,7 @@ opts_data = { -A, --abort Abort an unsent transaction created by ‘mmgen-txcreate --autosign’ and delete it from the removable device. The transaction may be signed or unsigned. --d, --outdir= d Specify an alternate directory 'd' for output +-d, --outdir=d Specify an alternate directory 'd' for output -H, --dump-hex=F Instead of sending to the network, dump the transaction hex to file ‘F’. Use filename ‘-’ to dump to standard output. -m, --mark-sent Mark the transaction as sent by adding it to the removable @@ -97,6 +97,7 @@ if not cfg.status: do_license_msg(cfg) from .tx import OnlineSignedTX, SentTX +from .ui import keypress_confirm async def post_send(tx): tx2 = await SentTX(cfg=cfg, data=tx.__dict__, automount=cfg.autosign) @@ -153,7 +154,6 @@ async def main(): ask_overwrite = False, ask_tty = False) if cfg.autosign: - from .ui import keypress_confirm if keypress_confirm(cfg, 'Mark transaction as sent on removable device?'): await post_send(tx) else: diff --git a/mmgen/proto/eth/tx/base.py b/mmgen/proto/eth/tx/base.py index 60042364..980fa92f 100755 --- a/mmgen/proto/eth/tx/base.py +++ b/mmgen/proto/eth/tx/base.py @@ -42,10 +42,10 @@ class Base(TxBase.Base): # given absolute fee in ETH, return gas price for display in selected unit def fee_abs2rel(self, abs_fee, *, to_unit='Gwei'): return self.pretty_fmt_fee( - self.fee_abs2gas(abs_fee).to_unit(to_unit)) + self.fee_abs2gasprice(abs_fee).to_unit(to_unit)) # given absolute fee in ETH, return gas price in ETH - def fee_abs2gas(self, abs_fee): + def fee_abs2gasprice(self, abs_fee): return self.proto.coin_amt(int(abs_fee.toWei() // self.gas.toWei()), from_unit='wei') # given rel fee (gasPrice) in wei, return absolute fee using self.gas (Ethereum-only method) diff --git a/mmgen/proto/eth/tx/bump.py b/mmgen/proto/eth/tx/bump.py index a68981c1..1ac70e14 100755 --- a/mmgen/proto/eth/tx/bump.py +++ b/mmgen/proto/eth/tx/bump.py @@ -29,7 +29,7 @@ class Bump(Completed, New, TxBase.Bump): return self.fee * Decimal('1.101') def bump_fee(self, idx, fee): - self.txobj['gasPrice'] = self.fee_abs2gas(fee) + self.txobj['gasPrice'] = self.fee_abs2gasprice(fee) async def get_nonce(self): return self.txobj['nonce'] diff --git a/mmgen/proto/eth/tx/new.py b/mmgen/proto/eth/tx/new.py index 58568dd5..117be9bc 100755 --- a/mmgen/proto/eth/tx/new.py +++ b/mmgen/proto/eth/tx/new.py @@ -55,12 +55,11 @@ class New(Base, TxBase.New): 'from': self.inputs[0].addr, 'to': self.outputs[0].addr if self.outputs else None, 'amt': self.outputs[0].amt if self.outputs else self.proto.coin_amt('0'), - 'gasPrice': self.fee_abs2gas(self.usr_fee), + 'gasPrice': self.fee_abs2gasprice(self.usr_fee), 'startGas': self.start_gas, 'nonce': await self.get_nonce(), 'chainId': self.rpc.chainID, - 'data': self.usr_contract_data, - } + 'data': self.usr_contract_data} # Instead of serializing tx data as with BTC, just create a JSON dump. # This complicates things but means we avoid using the rlp library to deserialize the data, diff --git a/mmgen/util2.py b/mmgen/util2.py index 3039374d..9bc1ee41 100755 --- a/mmgen/util2.py +++ b/mmgen/util2.py @@ -220,6 +220,15 @@ def cliargs_convert(args): return tuple(gen()) +def port_in_use(port): + import socket + try: + socket.create_connection(('localhost', port)).close() + except: + return False + else: + return True + class ExpInt(int): 'encode or parse an integer in exponential notation with specified precision' diff --git a/test/cmdtest_d/ct_xmrwallet.py b/test/cmdtest_d/ct_xmrwallet.py index 387b996c..07eeab35 100755 --- a/test/cmdtest_d/ct_xmrwallet.py +++ b/test/cmdtest_d/ct_xmrwallet.py @@ -25,6 +25,7 @@ from subprocess import run, PIPE from collections import namedtuple from mmgen.util import msg, fmt, async_run, capfirst, is_int, die, list_gen +from mmgen.util2 import port_in_use from mmgen.obj import MMGenRange from mmgen.amt import XMRAmt from mmgen.addrlist import ViewKeyAddrList, KeyAddrList, AddrIdxList @@ -155,15 +156,6 @@ class CmdTestXMRWallet(CmdTestBase): @classmethod def init_proxy(cls, external_call=False): - def port_in_use(port): - import socket - try: - socket.create_connection(('localhost', port)).close() - except: - return False - else: - return True - def start_proxy(): if external_call or not cfg.no_daemon_autostart: run(a+b2)