IntersectMBO / plutus-apps

The Plutus application platform
Apache License 2.0
306 stars 214 forks source link

Questions & Ideas - simplifying data reprs via Plutus Data #207

Closed t1lde closed 2 years ago

t1lde commented 2 years ago

The data formats story in Plutus is pretty complex. For any given type, depending on where it lives in the app architecture, you will may up using many of the following -

Is there a single expected source of truth for all of these formats? We currently test roundtrips/equivalences with QC - mostly to guard against subtlety of auto-derived instances.

This might be the intended use of OpenAPI, but that's not 100% clear to me.

An Idea

Can we use Plutus Data reprs as a source of truth? We don't have a schema system for Data reprs per-se, but some ground is covered by the makeIsDataIndexed derivations.

For instance, something like:

instance (ToData a) => (Aeson.ToJSON a)
instance (FromData a) => (Aeson.FromJSON a)

A Further Question - CDDL, CBOR

Noticing the usage of CDDL specs in cardano-ledger as well as cardano-serialization-lib, perhaps they also have a role to play in Plutus/PAB? CBOR and the CDDL specs are perhaps the real source of truth - at least when it comes to the plutus-ledger types.

ghost commented 2 years ago

Is there a single expected source of truth for all of these formats?

I think the one that is being used for external communication which means it can't be changed anytime. Internal representations might be changed and no-one won't notice outside of the project.

This might be the intended use of OpenAPI, but that's not 100% clear to me.

Yeah, OpenAPI is an unreliable external format as it's not really vital for anything as far as I know.

So yes, looks like CBOR might be an answer.

Can we use Plutus Data reprs as a source of truth?

I guess you can if you are sure that you can manually control the instances

instance (ToData a) => (Aeson.ToJSON a)
instance (FromData a) => (Aeson.FromJSON a)

I mean that if plutus data structure will change and it won't affect the result of encoding.