tx.file.format(): remove false boolean values from outputs

This commit is contained in:
The MMGen Project 2025-02-24 11:27:48 +00:00
commit 73efa84b48
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 12 additions and 2 deletions

View file

@ -269,7 +269,8 @@ class MMGenTxFile(MMGenObject):
k: getattr(tx, k) for k in self.attrs
} | {
'inputs': [e._asdict() for e in tx.inputs],
'outputs': [e._asdict() for e in tx.outputs]
'outputs': [{k:v for k,v in e._asdict().items() if not (type(v) is bool and v is False)}
for e in tx.outputs]
} | {
k: getattr(tx, k) for k in self.extra_attrs if getattr(tx, k)
})

View file

@ -30,10 +30,19 @@ async def do_txfile_test(desc, fns, cfg=cfg, check=False):
assert fn_gen == os.path.basename(fn), f'{fn_gen} != {fn}'
if check:
import json
from mmgen.tx.file import json_dumps
from mmgen.util import make_chksum_6
text = f.format()
with open(fpath) as fh:
text_chk = fh.read()
assert text == text_chk, f'\nformatted text:\n{text}\n !=\noriginal file:\n{text_chk}'
data_chk = json.loads(text_chk)
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)
assert text == text_chk_fixed, f'\nformatted text:\n{text}\n !=\noriginal file:\n{text_chk_fixed}'
qmsg(' OK')
return True