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

Complete domain type definitions #2

Open
klntsky opened this issue Jan 30, 2024 · 2 comments
Open

Complete domain type definitions #2

klntsky opened this issue Jan 30, 2024 · 2 comments

Comments

@klntsky
Copy link
Member

klntsky commented Jan 30, 2024

Context

We need to add all Cardano Domain data types used by CTL to this library. In CTL (current develop), there are 3 conceptual domains:

  • CSL types (defined as foreign import data)
  • Cardano-domain types (mirroring cardano-api) (Ctl.Internal.Cardano.Types)
  • Plutus types (mirroring plutus-ledger-api) (Ctl.Internal.Plutus.Types)

In the CTL codebase we made a (bad?) decision to mix plutus and cardano types together for those types that are literally the same (Ctl.Internal.Types). This effort is our attempt to clean up this mess and provide reusable datatype definitions.

purescript-cardano-types (PCT) is a wrapper over PS-CSL types, that is designed as follows:

  • for simple types, like ScriptHash, we simply newtype the corresponding PS-CSL type to provide instances
  • for complex ADTs, like PlutusData, we define them as PureScript ADTs and define toCsl / fromCsl functions that cover all the cases.

Note that, in the existing code we also provide ToData/FromData instances. This was not actually needed. Please do not include them anymore and remove the existing ToData/FromData machinery (it should be in plutus domain)

The ask

Complete this library by adapting all cardano-domain types we have in CSL.

klntsky/generate-for-ctl branch must be used. PS-CSL is autogenerated, see the codegen in that repo. This codegen code relies on manual specifications of some things, like ability of functions to throw in some cases. It may be that the generated code is subtly wrong. In that case, replace toCsl/fromCsl with notImplemented and move on - I'll handle the remaining cases when I'm back.

Follow existing cardano-domain definitions in CTL (type definitions and instances should be copy-pasteable for most of the types).

For every type, we need the following

  • derive instance Generic
  • Eq instance
  • Ord instance
  • EncodeAeson instance (should be compatible with CTL if there is one there)
  • DecodeAeson instance (should be compatible with CTL if there is one there)
  • Show - using genericShow
  • AsCbor
  • fromCsl function, if a data type is not a plain newtype over CSL type
  • toCsl function, if a data type is not a plain newtype over CSL type

See Cardano.Types.Internal.Helpers module for utilities that help defining instances, and see existing code for usage examples.

@adamczykm
Copy link

Picking this up 🙌

@adamczykm
Copy link

A write access for my branch would be convenient :)

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

No branches or pull requests

2 participants