Skip to content

Commit b8b775e

Browse files
committed
Fix missing type and description when saved to json file
1 parent 943c39e commit b8b775e

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

pycardano/serialization.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,26 +561,23 @@ def json_description(self) -> str:
561561
"""
562562
return self.__class__.__doc__ or "Generated with PyCardano"
563563

564-
def to_json(self, **kwargs) -> str:
564+
def to_json(self, key_type: Optional[str] = None, description: Optional[str] = None) -> str:
565565
"""
566566
Convert the CBORSerializable object to a JSON string containing type, description, and CBOR hex.
567567
568568
This method returns a JSON representation of the object, including its type, description, and CBOR hex encoding.
569569
570570
Args:
571-
**kwargs: Additional keyword arguments that can include:
572-
- key_type (str): The type to use in the JSON output. Defaults to the class name.
573-
- description (str): The description to use in the JSON output. Defaults to the class docstring.
571+
key_type (str): The type to use in the JSON output. Defaults to the class name.
572+
description (str): The description to use in the JSON output. Defaults to the class docstring.
574573
575574
Returns:
576575
str: The JSON string representation of the object.
577576
"""
578-
key_type = kwargs.pop("key_type", self.json_type)
579-
description = kwargs.pop("description", self.json_description)
580577
return json.dumps(
581578
{
582-
"type": key_type,
583-
"description": description,
579+
"type": key_type or self.json_type,
580+
"description": description or self.json_description,
584581
"cborHex": self.to_cbor_hex(),
585582
},
586583
indent=2,
@@ -625,8 +622,8 @@ def save(
625622
626623
Args:
627624
path (str): The file path to save the object to.
628-
key_type (str, optional): The type to use in the JSON output.
629-
description (str, optional): The description to use in the JSON output.
625+
key_type (str, optional): The type to use in the JSON output. Defaults to the class name.
626+
description (str, optional): The description to use in the JSON output. Defaults to the class docstring.
630627
631628
Raises:
632629
IOError: If the file already exists and is not empty.

pycardano/transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ class Transaction(ArrayCBORSerializable):
698698
def json_type(self) -> str:
699699
return (
700700
"Unwitnessed Tx ConwayEra"
701-
if self.transaction_witness_set.is_empty()
701+
if self.transaction_witness_set.vkey_witnesses is None
702702
else "Signed Tx ConwayEra"
703703
)
704704

0 commit comments

Comments
 (0)