aiken-lang / aiken

A modern smart contract platform for Cardano
https://aiken-lang.org
Apache License 2.0
470 stars 91 forks source link

Data missing from CIP57 specification #973

Closed SebastienGllmt closed 3 months ago

SebastienGllmt commented 3 months ago

What Git revision are you using?

aiken v1.0.29-alpha+16fb02e

What operating system are you using, and which version?

Describe what the problem is?

Given the following Aiken code

pub type Test{
  DataType { val: Data}
}

the following definition in plutus.json gets created

{
"Data": {
  "title": "Data",
  "description": "Any Plutus data."
},

This type has no dataType as expected (since Data isn't a primitive in cip57`).

What should be the expected behavior?

I'm not sure how this should be handled. From a plutus.json parsing tool, I can just hardcode `title === 'Data'), but maybe this should be mentioned in cip57? If Data is an Aiken-only type, then maybe there needs to be a way for CIP57 to be more clear on handling of custom compiler-specific types

There is a precedent for handle this because of the Void type in Aiken which is a custom type represented as

"Void": {
  "title": "Unit",
  "description": "The nullary constructor.",
  "anyOf": [
    {
      "dataType": "constructor",
      "index": 0,
      "fields": []
    }
  ]
},

But there are also other cases of custom types missing such as https://github.com/aiken-lang/aiken/issues/970

KtorZ commented 3 months ago

It isn't missing, it's actually part of the spec:

dataType

The value of this keyword must be a string, with one of the following value listed in the first column of the table above. This keyword is optional. When missing, the instance is implicitly typed as an opaque Plutus Data.

The rationale here being that Data actually represent any possible value that can appear in a contract ABI. So it can be the default to anything. dataType allows to constraint further down the type. But when unspecified, it simply is Data.