whitespace, variable renames

This commit is contained in:
The MMGen Project 2026-09-06 10:08:41 +00:00
commit f6f56b9e1f
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 39 additions and 51 deletions

View file

@ -150,7 +150,10 @@ async def main():
proto = cfg._proto
from .tx import NewTX
tx1 = NewTX(cfg=cfg, proto=proto, target=target)
tx1 = NewTX(
cfg = cfg,
proto = proto,
target = target)
tx2 = await tx1.create(
args = cfg._args,

View file

@ -29,10 +29,7 @@ class Bump(Completed, NewSwap, TxBase.Bump):
return self.sum_inputs() - self.sum_outputs() + self.relay_fee
def bump_fee(self, idx, fee):
self.update_output_amt(
idx,
self.sum_inputs() - self.sum_outputs(exclude=idx) - fee
)
self.update_output_amt(idx, self.sum_inputs() - self.sum_outputs(exclude=idx) - fee)
def convert_and_check_fee(self, fee, desc):
ret = super().convert_and_check_fee(fee, desc)

View file

@ -19,14 +19,10 @@ from ..util import msg, pp_fmt
from ..objmethods import HiliteStr, InitErrors
def dmsg_rpc(fs, data=None, *, is_json=False):
msg(
fs if data is None else
fs.format(pp_fmt(json.loads(data) if is_json else data))
)
msg(fs if data is None else fs.format(pp_fmt(json.loads(data) if is_json else data)))
def dmsg_rpc_backend(host_url, host_path, payload):
msg(
f'\n RPC URL: {host_url}{host_path}' +
msg(f'\n RPC URL: {host_url}{host_path}' +
'\n RPC PAYLOAD data (httplib) ==>' +
f'\n{pp_fmt(payload)}\n')

View file

@ -30,7 +30,7 @@ def get_monero_proto(tx, data):
from ..protocol import init_proto
return init_proto(tx.cfg, 'XMR', network=data['MoneroMMGenTX']['data']['network'])
class txdata_json_encoder(json.JSONEncoder):
class txfile_json_encoder(json.JSONEncoder):
def default(self, o):
if type(o).__name__.endswith('Amt'):
return str(o)
@ -39,8 +39,8 @@ class txdata_json_encoder(json.JSONEncoder):
else:
return json.JSONEncoder.default(self, o)
def json_dumps(data):
return json.dumps(data, separators = (',', ':'), cls=txdata_json_encoder)
def txfile_json_dumps(data):
return json.dumps(data, separators = (',', ':'), cls=txfile_json_encoder)
def get_proto_from_coin_id(tx, coin_id, chain):
coin, tokensym = coin_id.split(':') if ':' in coin_id else (coin_id, None)
@ -99,8 +99,8 @@ class MMGenTxFile(MMGenObject):
tx.proto = get_monero_proto(tx, outer_data)
return None
data = outer_data[self.data_label]
if outer_data['chksum'] != make_chksum_6(json_dumps(data)):
chk = make_chksum_6(json_dumps(data))
if outer_data['chksum'] != make_chksum_6(txfile_json_dumps(data)):
chk = make_chksum_6(txfile_json_dumps(data))
die(3, f'{self.data_label}: invalid checksum for TxID {data["txid"]} ({chk} != {outer_data["chksum"]})')
tx.proto = get_proto_from_coin_id(tx, data['coin_id'], data['chain'])
@ -283,7 +283,7 @@ class MMGenTxFile(MMGenObject):
return '\n'.join([make_chksum_6(' '.join(lines))] + lines) + '\n'
def format_data_json():
data = json_dumps({
data = txfile_json_dumps({
'coin_id': coin_id
} | {
k: getattr(tx, k) for k in self.attrs

View file

@ -18,7 +18,7 @@ from mmgen.cfg import Config
from mmgen.util import make_chksum_6
from mmgen.protocol import init_proto
from mmgen.wallet.mmgen import wallet as MMGenWallet
from mmgen.tx.file import json_dumps
from mmgen.tx.file import txfile_json_dumps
from ..include.common import imsg, make_burn_addr, gr_uc
@ -270,7 +270,10 @@ class CmdTestSwapMethods:
ret.parent_group = self
return ret
class CmdTestSwap(CmdTestSwapMethods, CmdTestRegtest, CmdTestAutosignThreaded):
class CmdTestSwap(
CmdTestSwapMethods,
CmdTestRegtest,
CmdTestAutosignThreaded):
'swap operations (LTC <=> BCH)'
bdb_wallet = True
@ -638,7 +641,7 @@ class CmdTestSwap(CmdTestSwapMethods, CmdTestRegtest, CmdTestAutosignThreaded):
with open(fn) as fh:
data = json.load(fh)
data['MMGenTransaction']['swap_quote_expiry'] -= 2400
data['chksum'] = make_chksum_6(json_dumps(data['MMGenTransaction']))
data['chksum'] = make_chksum_6(txfile_json_dumps(data['MMGenTransaction']))
with open(fn, 'w') as fh:
json.dump(data, fh)
t = self.spawn('mmgen-txsend', ['-d', self.tmpdir, '--bob', fn], exit_val=1)

View file

@ -13,7 +13,7 @@ from mmgen.protocol import init_proto
from ..include.common import cfg, qmsg, vmsg, gr_uc
async def do_txfile_test(desc, fns, cfg=cfg, check=False):
async def do_txfile_test(desc, fns, cfg=cfg, do_format=True):
qmsg(f'\n Testing CompletedTX initializer ({desc})')
for fn in fns:
qmsg(f' parsing: {os.path.basename(fn)}')
@ -30,9 +30,9 @@ async def do_txfile_test(desc, fns, cfg=cfg, check=False):
assert fn_gen == os.path.basename(fn), f'{fn_gen} != {fn}'
if check:
if do_format:
import json
from mmgen.tx.file import json_dumps
from mmgen.tx.file import txfile_json_dumps
from mmgen.util import make_chksum_6
text = f.format()
with open(fpath) as fh:
@ -41,8 +41,8 @@ async def do_txfile_test(desc, fns, cfg=cfg, check=False):
outputs = data_chk['MMGenTransaction']['outputs']
for n, o in enumerate(outputs):
outputs[n] = {k:v for k,v in o.items() if not (type(v) is bool and v is False)}
data_chk['chksum'] = make_chksum_6(json_dumps(data_chk['MMGenTransaction']))
text_chk_fixed = json_dumps(data_chk)
data_chk['chksum'] = make_chksum_6(txfile_json_dumps(data_chk['MMGenTransaction']))
text_chk_fixed = txfile_json_dumps(data_chk)
assert text == text_chk_fixed, f'\nformatted text:\n{text}\n !=\noriginal file:\n{text_chk_fixed}'
qmsg(' OK')
@ -52,54 +52,46 @@ class unit_tests:
altcoin_deps = ('txfile_alt', 'txfile_alt_legacy')
async def txfile(self, name, ut, desc='displaying transaction files (BTC)'):
async def txfile(self, name, ut, desc='displaying and formatting transaction files (BTC)'):
return await do_txfile_test(
'Bitcoin',
(
'Bitcoin', (
'tx/7A8157[6.65227,34].rawtx',
'tx/B498CE[5.55788,38].rawtx',
'tx/BB3FD2[7.57134314,123].sigtx',
'tx/0A869F[1.23456,32].regtest.asubtx',
),
check = True
)
))
async def txfile_alt(self, name, ut, desc='displaying transaction files (LTC, BCH, ETH)'):
async def txfile_alt(self, name, ut, desc='displaying and formatting transaction files (LTC, BCH, ETH)'):
return await do_txfile_test(
'altcoins',
(
'altcoins', (
'tx/C09D73-LTC[981.73747,2000].testnet.rawtx',
'tx/91060A-BCH[1.23456].regtest.arawtx',
'tx/D850C6-MM1[43.21,50000].subtx', # token tx
),
# token resolved by tracking wallet under data_dir:
cfg = Config({'data_dir': 'test/ref/data_dir'}),
check = True
)
cfg = Config({'data_dir': 'test/ref/data_dir'}))
async def txfile_legacy(self, name, ut, desc='displaying transaction files (legacy format, BTC)'):
return await do_txfile_test(
'Bitcoin - legacy file format',
(
'Bitcoin - legacy file format', (
'0B8D5A[15.31789,14,tl=1320969600].rawtx',
'542169[5.68152,34].sigtx',
'0C7115[15.86255,14,tl=1320969600].testnet.rawtx',
'25EFA3[2.34].testnet.rawtx',
)
)
),
do_format = False)
async def txfile_alt_legacy(self, name, ut, desc='displaying transaction files (legacy format, LTC, BCH, ETH)'):
return await do_txfile_test(
'altcoins - legacy file format',
(
'altcoins - legacy file format', (
'460D4D-BCH[10.19764,tl=1320969600].rawtx',
'ethereum/5881D2-MM1[1.23456,50000].rawtx',
'ethereum/6BDB25-MM1[1.23456,50000].testnet.rawtx',
'ethereum/88FEFD-ETH[23.45495,40000].rawtx',
'litecoin/A5A1E0-LTC[1454.64322,1453,tl=1320969600].testnet.rawtx',
'litecoin/AF3CDF-LTC[620.76194,1453,tl=1320969600].rawtx',
)
)
),
do_format = False)
def errors(self, name, ut, desc='reading transaction files (error handling)'):
async def bad1():
@ -108,8 +100,7 @@ class unit_tests:
UnsignedTX(cfg, filename='foo') # pylint: disable=too-many-function-args
bad_data = (
('forbidden positional args', 'TypeError', 'positional arguments', bad1),
('forbidden positional args', 'TypeError', 'positional arguments', bad2),
)
('forbidden positional args', 'TypeError', 'positional arguments', bad2))
ut.process_bad_data(bad_data)
return True
@ -133,8 +124,7 @@ class unit_tests:
'data:a',
'data:a\n',
'data:a\tb',
'data:' + gr_uc[:24],
]
'data:' + gr_uc[:24]]
assert DataOutput(proto, vecs[0]) == DataOutput(proto, vecs[1])
@ -160,8 +150,7 @@ class unit_tests:
'hexdata:xyz',
'hexdata:abcde',
b'data:abc',
'hexdata:' + 'dd' * (max_len + 1),
]
'hexdata:' + 'dd' * (max_len + 1)]
def bad(n):
return lambda: DataOutput(proto, bad_data[n])