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 initial support for recursive PlutusData types and fixed kupmiosv5 provider's script converting issue caused my previous PR #29

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

ilap
Copy link
Contributor

@ilap ilap commented Jan 7, 2024

Added initial support for recursive PlutusData types. It is very simple patch, but it's required for handling recursive datatypes with translucent. It still requires manual intervention see example below:
Define the relevant types in aiken

pub type Node {
  Link { value: ByteArray, next: Node }
  Value { value: ByteArray}
}

pub type MintRedeemer {
  node: Node,
}

Modify the blueprint.ts generated plutus.ts

import { applyParamsToScript, Data, Validator } from 'translucent-cardano'

export type Node =
  | {
      Link: { value: string; next: Node }
    }
  | {
      Value: { value: string }
    }

export type MintRedeemer =
  | {
      Minting: [
        {
          node: Node
        },
      ]
    }
  | 'Burning'

export interface MyMinting {
  new (params: {
...
  }): Validator
  // It can be the MintRedeemer type too
  // MintRedeemer
  rdmr:
    | {
        Minting: [
          {
            node: Node
          },
        ]
      }
    | 'Burning'
}
...
                    {
                      title: 'node',
                      anyOf: [
                        {
                          title: 'Link',
                          dataType: 'constructor',
                          index: 0,
                          fields: [
                            { dataType: 'bytes', title: 'value' },
                            {
                              title: 'next',
                              $ref: '#/definitions/ilap~1example~1types~1Node',
                            }
                          ],
                        },
                        {
                          title: 'Value',
                          dataType: 'constructor',
                          index: 1,
                          fields: [{ dataType: 'bytes', title: 'value' }],
                        },
                      ],
                    },

Use it witg translucent

import * as P from './plutus.ts'
...

const node: P.Node = {
  Link: {
    value: "test1",
    next: {
      Link: {
        value: "test2",
        next: { Value: { value: "test3", } },
      },
    },
  },
}
...
    const rdmr: P.MintRedeemer = {
      Minting: [
        {
          Node: node,
        },
      ], // Use 'as const' to assert that Minting is a tuple with a single element
    }

    const rdmr = Data.to(mintRedeemer, P.MyMinting.rdmr, 'node')
   // pass this to the MyMinting script as redeemer.

@micahkendall micahkendall merged commit 4dd6903 into butaneprotocol:main Jan 17, 2024
1 check failed
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.

2 participants