tx.file, xmrwallet.file: encapsulated compat data changes

This commit is contained in:
The MMGen Project 2026-10-23 17:01:32 +00:00
commit 3cf9dfebb2
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 10 additions and 10 deletions

View file

@ -83,6 +83,7 @@ class Base(MMGenObject):
is_refreq = False
is_memoless = False
is_compat = False
compat_data = None
has_comment = True
swap_attrs = {
'swap_proto': None,

View file

@ -283,13 +283,13 @@ class MMGenTxFile(MMGenObject):
data = txfile_json_dumps({
'coin_id': coin_id,
'version': tx.txfile_version
} | {
} | (tx.compat_data or ({
k: getattr(tx, k) for k in self.attrs
} | {
'inputs': [e._asdict() for e in tx.inputs],
'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, None)
} | ({
k: getattr(tx, k) for k in tx.swap_attrs if getattr(tx, k, None)

View file

@ -40,18 +40,17 @@ class MoneroMMGenFile:
b = d_wrap[k]
assert a == b, f'{k} mismatch: {a} != {b}'
def make_wrapped_json_data(self, in_data):
return json.dumps(self.make_wrapped_data(in_data), cls=json_encoder, indent=2)
def make_wrapped_data(self, in_data):
out = {
return {self.data_label: {
'base_chksum': self.base_chksum,
'full_chksum': self.full_chksum,
'data': in_data,
} if self.full_chksum else {
'base_chksum': self.base_chksum,
'data': in_data}
return json.dumps(
{self.data_label: out},
cls = json_encoder,
indent = 2)
'data': in_data}}
def extract_data_from_file(self, cfg, fn):
return json.loads(

View file

@ -47,7 +47,7 @@ class MoneroWalletOutputsFile:
write_data_to_file(
cfg = self.cfg,
outfile = str(self.get_outfile(self.cfg, self.wallet_fn)) + add_suf,
data = self.make_wrapped_data(self.data._asdict()),
data = self.make_wrapped_json_data(self.data._asdict()),
desc = self.desc,
ask_overwrite = False,
quiet = quiet,

View file

@ -170,7 +170,7 @@ class MoneroMMGenTX:
write_data_to_file(
cfg = self.cfg,
outfile = str(fn),
data = self.make_wrapped_data(dict_data),
data = self.make_wrapped_json_data(dict_data),
desc = self.desc,
ask_write = ask_write,
ask_write_default_yes = not ask_write,