Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added RawPlutusData to PlutusData primitive types #363

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

theeldermillenial
Copy link
Contributor

Some contracts are starting to include forward datums, where a field could contain an arbitrary datum that will be passed on to a subsequent address.

This requires the ability to support arbitrary plutusdata.

In Python <= 3.10, it was possible to pass in typing.Any to a field, but starting in Python 3.11 and beyond, it is no longer possible.

This PR adds RawPlutusData to the list of available of PlutusData primitives that can be used for a field.

Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (2bb4820) to head (b7756ca).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #363   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files          29       29           
  Lines        3733     3733           
  Branches      941      941           
=======================================
  Hits         3135     3135           
  Misses        433      433           
  Partials      165      165           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cffls
Copy link
Collaborator

cffls commented Jul 18, 2024

Thanks for the change. Could you add a unit test (also as an example) where RawPlutusData would be used when deserialized?

Copy link
Collaborator

@cffls cffls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test!

@cffls cffls merged commit 3d65c67 into Python-Cardano:main Jul 18, 2024
11 checks passed
@nielstron
Copy link
Contributor

nielstron commented Jul 18, 2024

It is (and was) actually possible to use Datum as type for arbitrary data in OpShin and AFAIK also in PyCardano. Could you check what difference there is to using RawPlutusData?

@theeldermillenial
Copy link
Contributor Author

@nielstron The issue is that parsing did a hard check on types. You could pass in PlutusData as a type, but it would throw an error because of constructor id. It used to be that you could use typing.Any, and it would just parse whatever was there, including using RawPlutusData to parse a datum. That seems to have changed in Python 3.11+.

@nielstron
Copy link
Contributor

nielstron commented Jul 18, 2024

I am not talking about PlutusDatum but about Datum

@theeldermillenial
Copy link
Contributor Author

To my knowledge, there is no Datum class in pycardano. I don't use OpShin (yet), so I haven't tried doing that.

Even if there were a Datum class, it's not defined in the primitive types and theres an explicit type check here:

for f in fields(self):

Sorry if I'm misunderstanding what you're saying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants