OpShin / opshin

A simple pythonic programming language for Smart Contracts on Cardano
https://book.opshin.dev/
MIT License
141 stars 28 forks source link

Allow Unions of PlutusData and BuiltinData #367

Open nielstron opened 7 months ago

nielstron commented 7 months ago

Is your feature request related to a problem? Please describe. Currently, OpShin only allows Union between PlutusData objects with unique constructor IDs. In theory however, we could also allow Union with bytes, int, dict and list objects. This is currently only supported by wrapping the data in another PlutusData layer.

Describe the solution you'd like In practice this would be treated by the compiler as Anything, and using ChooseData we can choose the appropriate datatype and downcast in isinstance(x, int/bytes/...) calls and x: int/bytes/... = x. This could be tricky to get right however.

Describe alternatives you've considered Currently (as of #70 ) the status is to simply disallow such unions. There could be legitimate use cases that speak for it though.

Additional context Note that there is no native plutusdata type for str and bool so these should not be allowed in Unions (or at least not together with int / bytes as they are not distinguishable on the plutusdata level)

Bug bounty: 1000 ADA

SCMusson commented 3 months ago

Claiming this issue