@@ -781,11 +781,14 @@ def __deepcopy__(self, memo):
781781 return self .__class__ .from_cbor (self .to_cbor_hex ())
782782
783783
784+ RawDatum = Union [PlutusData , dict , int , bytes , IndefiniteList , RawCBOR , CBORTag ]
785+
786+
784787@dataclass (repr = False )
785788class RawPlutusData (CBORSerializable ):
786- data : CBORTag
789+ data : RawDatum
787790
788- def to_primitive (self ) -> CBORTag :
791+ def to_primitive (self ) -> RawDatum :
789792 def _dfs (obj ):
790793 if isinstance (obj , list ) and obj :
791794 return IndefiniteList ([_dfs (item ) for item in obj ])
@@ -823,6 +826,8 @@ def _dfs(obj):
823826 elif isinstance (obj , CBORTag ):
824827 constructor , fields = get_constructor_id_and_fields (obj )
825828 return {"constructor" : constructor , "fields" : [_dfs (f ) for f in fields ]}
829+ elif isinstance (obj , RawCBOR ):
830+ return RawPlutusData .from_cbor (obj .cbor ).to_dict ()
826831 raise TypeError (f"Unexpected type { type (obj )} " )
827832
828833 return _dfs (RawPlutusData .to_primitive (self ))
@@ -840,8 +845,10 @@ def to_json(self, **kwargs) -> str:
840845 return json .dumps (RawPlutusData .to_dict (self ), ** kwargs )
841846
842847 @classmethod
843- @limit_primitive_type (CBORTag )
844- def from_primitive (cls : Type [RawPlutusData ], value : CBORTag ) -> RawPlutusData :
848+ @limit_primitive_type (
849+ PlutusData , dict , int , bytes , IndefiniteList , RawCBOR , CBORTag
850+ ) # equal to RawDatum parameter list
851+ def from_primitive (cls : Type [RawPlutusData ], value : RawDatum ) -> RawPlutusData :
845852 return cls (value )
846853
847854 @classmethod
0 commit comments