aiken-lang / aiken

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

Pair missing from plutus.json definition #970

Open SebastienGllmt opened 3 weeks ago

SebastienGllmt commented 3 weeks 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 PairTest =
  Pair<Int, ByteArray>

pub type Action {
  PairTest { val: PairTest }
}

the following definition in plutus.json gets created

{
"my_project/validation/MintActions": {
  "title": "Action",
  "anyOf": [
    {
      "title": "PairTest",
      "dataType": "constructor",
      "index": 0,
      "fields": [
        {
          "title": "val",
          "$ref": "#/definitions/Pair$Int_ByteArray"
        }
      ]
    }
  ]
}

However, there is no definition entry for #/definitions/Pair$Int_ByteArray created

Note that this bug doesn't exist for List types or Tuple types. A proper List entry gets created. This issue seems to only affect Pair, and is probably because Pair is not mentioned in CIP57

What should be the expected behavior?

Either generate an entry for Pair, or change the schema to something else

KtorZ commented 1 week ago

I am unable to reproduce this @SebastienGllmt?

With the following code:

pub type PairTest =
  Pair<Int, ByteArray>

pub type Action {
  PairTest { val: PairTest }
}

validator {
  fn foo(redeemer: Action, ctx: Data) {
    True
  }
}

I end up with the following blueprint, which does contain a definition for Pair$Int_ByteArray as expected:

{
  "preamble": {
    "title": "aiken-lang/scratchpad",
    "description": "Aiken contracts for project 'aiken-lang/scratchpad'",
    "version": "0.0.0",
    "plutusVersion": "v2",
    "compiler": {
      "name": "Aiken",
      "version": "v1.0.29-alpha+c52ba9c"
    },
    "license": "Apache-2.0"
  },
  "validators": [
    {
      "title": "scratchpad.foo",
      "redeemer": {
        "title": "redeemer",
        "schema": {
          "$ref": "#/definitions/scratchpad~1Action"
        }
      },
      "compiledCode": "<redacted>",
      "hash": "57689de1175e1f5de429ef7075211b7002a08c66034de7db5500ffb7"
    }
  ],
  "definitions": {
    "ByteArray": {
      "dataType": "bytes"
    },
    "Int": {
      "dataType": "integer"
    },
    "Pair$Int_ByteArray": {
      "title": "Pair",
      "dataType": "#pair",
      "left": {
        "$ref": "#/definitions/Int"
      },
      "right": {
        "$ref": "#/definitions/ByteArray"
      }
    },
    "scratchpad/Action": {
      "title": "Action",
      "anyOf": [
        {
          "title": "PairTest",
          "dataType": "constructor",
          "index": 0,
          "fields": [
            {
              "title": "val",
              "$ref": "#/definitions/Pair$Int_ByteArray"
            }
          ]
        }
      ]
    }
  }
}