Python-Cardano / pycardano

A lightweight Cardano library in Python
https://pycardano.readthedocs.io
MIT License
215 stars 67 forks source link

Cannot deserialize PlutusV2 script attached to transaction #251

Closed nielstron closed 9 months ago

nielstron commented 1 year ago

Describe the bug Trying to deserialize a transaction from cborhex that was generated and hexlified by PyCardano before, I get the following error

Jun 07 23:45:25 ********[12055]: pycardano.exception.DeserializeException: Cannot deserialize object:
Jun 07 23:45:25 ********[12055]: [b'Y,\x1e\x01\x00\x002222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222>
Jun 07 23:45:25 *********[12055]:  in any valid type from (typing.List[pycardano.plutus.PlutusV2Script], <class 'NoneType'>).

To Reproduce Serialize a Tx with a PlutusV2 script attached, then deserialize again.

Logs Logs are above

Expected behavior Transaction.from_cbor(tx.to_cbor()) should work without problems

Environment and software version (please complete the following information):

Additional context None

MartinSchere commented 1 year ago

Happening for me too with PlutusV1 scripts

cffls commented 12 months ago

Does the issue still persist in the latest main branch?

theeldermillenial commented 9 months ago

Yes, I can also confirm this is still a problem. It appears as though it's trying to interpret it as a list of bytes rather than just bytes. If you instantiate the Plutus script class with the bytes that throw the error, it instantiates properly.

theeldermillenial commented 9 months ago

I think I figured it out. For types that are just wrappers around Python raw data types, there is no attempt to instantiate them. I ran into this issue when implementing ByteString. We should maybe add in a more generic attempt to cast bytes to their wrapper class.

I'll take a stab at this today.

https://github.com/Python-Cardano/pycardano/blob/d1ec4392a28de0853d8c111657f4992e7452187b/pycardano/serialization.py#L509-L570