plutus
plutus copied to clipboard
CIP-0057 Plutus Blueprints support: generate blueprint for a contract.
This PR adds a CIP-0057 contract blueprint generation functionality:
- A Template Haskell macros
makeIsDataSchemaIndexedthat alongside theIsDatainstances makes aHasDataSchemainstance which is compatible with the generatedToData/FromDatainstances. - A set of data types to build a contract blueprint definition skeleton.
- A function to derive JSON-schema definitions.
- A function to make a safe JSON-reference to a JSON-schema definition (e.g.
{ "$ref": "#/definitions/Foo" })
@Unisay Sorry for the delay, but I'll try to review this today.
@Unisay Sorry for the delay, but I'll try to review this today.
🙏🏼 thank you, I will ll be addressing all the comments next week.
- I definitely want us to validate the output against the schema! I found at least one bug, there might be more.
I researched JSON Schema validator tools that:
- Support Draft 2020-12
- Is available in the nix packages (or flakes) and are installable/runnable with nix;
and the result is Ø
Do you think we can relax the requirement 2 and if yes then how would we make such a tool available for CI?
Do you think we can relax the requirement 2 and if yes then how would we make such a tool available for CI?
It will make our life much harder. What tools are there that satisfy requirement 1? We might just be able to package one.
What tools are there that satisfy requirement 1?
https://ajv.js.org/packages/ajv-cli.html
I use it this way atm:
nix-shell -p nodejs_21
then npx or npm install:
npx ajv-cli test \
--strict=log \
--spec=draft2020 \
-s plutus-blueprint \
-r plutus-blueprint-argument \
-r plutus-data \
-r plutus-blueprint-parameter \
-r plutus-builtin \
-d Acme.golden \
--valid
(it does catch some invalid schemas, but it doesn't catch the error you found s/constructor/index/ 🤷🏼♂️ )
Does this PR include the function for generating the blueprint? I was expecting to see something like
mkBlueprint :: CompiledCode (Datum -> Redeemer -> ScriptContext -> Bool) -> ContractBlueprintbut I'm not seeing it.
Yes, see the PlutusTx.Blueprint.Write module, its called writeBlueprint. There is also a test case that uses it.
By the way, (to be done separately) we'd also need to think about how this will interact with AsData - @michaelpj
To use it, one must instantiate
typeswith a type-level list, which they have to construct manually.
The idea is that in the minimal implementation users supply a list of types involved into a contract API manually, such that a convenience function (which derives such a list of types from a typed validator function type) could be provided on top of it .
Anyway, only providing CompiledCode (Datum -> Redeemer -> ScriptContext -> Bool) is not enough for a blueprint:
- its missing all the meta information: Preamble, titles, descriptions, comments.
- CIP-57 describes a contract blueprint that is comprised of potentially more than one validator.
By the way, (to be done separately) we'd also need to think about how this will interact with AsData
It's a bit awkward. In particular, you would like to use a schema definition based on the "real" datatype definition, which doesn't even exist with AsData. Perhaps we can still emit it with a slightly different name or something :thinking: