Update blueprint outputs to reflect latest specification.

Schemas of datums, redeemers and parameters are now nested under a field 'schema'. This allows to define a field 'purpose' at the same level.
This commit is contained in:
KtorZ 2023-03-02 17:17:27 +01:00
parent 433af4638b
commit 65c336cb82
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
6 changed files with 456 additions and 378 deletions

View File

@ -15,18 +15,34 @@ use uplc::ast::{DeBruijn, Program, Term};
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
pub struct Validator<T> {
pub title: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub datum: Option<Annotated<T>>,
pub redeemer: Annotated<T>,
pub datum: Option<Argument<T>>,
pub redeemer: Argument<T>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub parameters: Vec<Annotated<T>>,
pub parameters: Vec<Argument<T>>,
#[serde(flatten)]
pub program: Program<DeBruijn>,
}
#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize, serde::Deserialize)]
pub struct Argument<T> {
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub schema: T,
}
impl Display for Validator<Schema> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = serde_json::to_string_pretty(self).map_err(|_| fmt::Error)?;
@ -34,6 +50,23 @@ impl Display for Validator<Schema> {
}
}
impl Display for Argument<Schema> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = serde_json::to_string_pretty(self).map_err(|_| fmt::Error)?;
f.write_str(&s)
}
}
impl<T> From<Annotated<T>> for Argument<T> {
fn from(annotated: Annotated<T>) -> Self {
Argument {
title: annotated.title,
description: annotated.description,
schema: annotated.annotated,
}
}
}
impl Validator<Schema> {
pub fn from_checked_module(
modules: &CheckedModules,
@ -71,7 +104,7 @@ impl Validator<Schema> {
annotation.title = annotation
.title
.or_else(|| Some(param.arg_name.get_label()));
annotation
annotation.into()
})
})
.collect::<Result<_, _>>()?,
@ -88,7 +121,8 @@ impl Validator<Schema> {
},
)
})
.transpose()?,
.transpose()?
.map(|annotated| annotated.into()),
redeemer: Annotated::from_type(modules.into(), &redeemer.tipo, &HashMap::new())
.map_err(|error| Error::Schema {
error,
@ -97,7 +131,8 @@ impl Validator<Schema> {
module.input_path.display().to_string(),
module.code.clone(),
),
})?,
})?
.into(),
program: generator
.generate(&def.fun.body, &arguments, true)
.try_into()
@ -266,7 +301,8 @@ mod test {
"hash": "afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
"redeemer": {
"title": "Data",
"description": "Any Plutus data."
"description": "Any Plutus data.",
"schema": {}
},
"compiledCode": "583b010000323232323232322253330054a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae881"
}),
@ -288,12 +324,14 @@ mod test {
"hash": "a82df717fd39f5b273c4eb89ae5252e11cc272ac59d815419bf2e4c3",
"parameters": [{
"title": "utxo_ref",
"dataType": "integer"
"schema": {
"dataType": "integer"
}
}],
"redeemer": {
"title": "Data",
"description": "Any Plutus data."
"description": "Any Plutus data.",
"schema": {}
},
"compiledCode": "5840010000323232323232322322253330074a22930b1bad0013001001222533300600214984cc014c004c01c008ccc00c00cc0200080055cd2b9b5573eae855d101"
}),
@ -346,68 +384,72 @@ mod test {
"datum": {
"title": "State",
"description": "On-chain state",
"anyOf": [
{
"title": "State",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "contestationPeriod",
"description": "The contestation period as a number of seconds",
"anyOf": [
{
"title": "ContestationPeriod",
"description": "A positive, non-zero number of seconds.",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "integer"
}
]
"schema": {
"anyOf": [
{
"title": "State",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "contestationPeriod",
"description": "The contestation period as a number of seconds",
"anyOf": [
{
"title": "ContestationPeriod",
"description": "A positive, non-zero number of seconds.",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "integer"
}
]
}
]
},
{
"title": "parties",
"description": "List of public key hashes of all participants",
"dataType": "list",
"items": {
"dataType": "bytes"
}
]
},
{
"title": "parties",
"description": "List of public key hashes of all participants",
"dataType": "list",
"items": {
},
{
"title": "utxoHash",
"dataType": "bytes"
}
},
{
"title": "utxoHash",
"dataType": "bytes"
}
]
}
]
]
}
]
}
},
"redeemer": {
"title": "Input",
"anyOf": [
{
"title": "CollectCom",
"dataType": "constructor",
"index": 0,
"fields": []
},
{
"title": "Close",
"dataType": "constructor",
"index": 1,
"fields": []
},
{
"title": "Abort",
"description": "Abort a transaction",
"dataType": "constructor",
"index": 2,
"fields": []
}
]
"schema": {
"anyOf": [
{
"title": "CollectCom",
"dataType": "constructor",
"index": 0,
"fields": []
},
{
"title": "Close",
"dataType": "constructor",
"index": 1,
"fields": []
},
{
"title": "Abort",
"description": "Abort a transaction",
"dataType": "constructor",
"index": 2,
"fields": []
}
]
}
},
"compiledCode": "583b0100003232323232323222253330064a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae89"
}),
@ -428,14 +470,18 @@ mod test {
"title": "test_module.spend",
"hash": "3c6766e7a36df2aa13c0e9e6e071317ed39d05f405771c4f1a81c6cc",
"datum": {
"dataType": "list",
"items": [
{ "dataType": "integer" },
{ "dataType": "bytes" }
]
"schema": {
"dataType": "list",
"items": [
{ "dataType": "integer" },
{ "dataType": "bytes" }
]
}
},
"redeemer": {
"dataType": "#string"
"schema": {
"dataType": "#string"
}
},
"compiledCode": "585501000032323232323232232232253330084a22930b1b99375c002646466ec0c024008c024004c024004dd6000980080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae881"
}),
@ -457,22 +503,25 @@ mod test {
"hash": "f335ce0436fd7df56e727a66ada7298534a27b98f887bc3b7947ee48",
"datum": {
"title": "Tuple",
"dataType": "list",
"items": [
{
"dataType": "integer"
},
{
"dataType": "integer"
},
{
"dataType": "integer"
}
]
"schema": {
"dataType": "list",
"items": [
{
"dataType": "integer"
},
{
"dataType": "integer"
},
{
"dataType": "integer"
}
]
}
},
"redeemer": {
"title": "Data",
"description": "Any Plutus data."
"description": "Any Plutus data.",
"schema": {}
},
"compiledCode": "5840010000323232323232322322253330074a22930b1bac0013001001222533300600214984cc014c004c01c008ccc00c00cc0200080055cd2b9b5573eae855d101"
}),
@ -505,46 +554,48 @@ mod test {
"hash": "afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
"redeemer": {
"title": "Either",
"anyOf": [
{
"title": "Left",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "bytes"
}
]
},
{
"title": "Right",
"dataType": "constructor",
"index": 1,
"fields": [
{
"title": "Interval",
"anyOf": [
{
"title": "Finite",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "integer"
}
]
},
{
"title": "Infinite",
"dataType": "constructor",
"index": 1,
"fields": []
}
]
}
]
}
]
"schema": {
"anyOf": [
{
"title": "Left",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "bytes"
}
]
},
{
"title": "Right",
"dataType": "constructor",
"index": 1,
"fields": [
{
"title": "Interval",
"anyOf": [
{
"title": "Finite",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "integer"
}
]
},
{
"title": "Infinite",
"dataType": "constructor",
"index": 1,
"fields": []
}
]
}
]
}
]
}
},
"compiledCode": "583b010000323232323232322253330054a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae881"
}
@ -574,25 +625,27 @@ mod test {
"hash": "afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
"redeemer": {
"title": "Dict",
"anyOf": [
{
"title": "Dict",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "inner",
"dataType": "map",
"keys": {
"dataType": "bytes"
},
"values": {
"dataType": "integer"
"schema": {
"anyOf": [
{
"title": "Dict",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "inner",
"dataType": "map",
"keys": {
"dataType": "bytes"
},
"values": {
"dataType": "integer"
}
}
}
]
}
]
]
}
]
}
},
"compiledCode": "583b010000323232323232322253330054a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae881"
}
@ -622,12 +675,14 @@ mod test {
"hash": "afddc16c18e7d8de379fb9aad39b3d1b5afd27603e5ebac818432a72",
"redeemer": {
"title": "Dict",
"dataType": "map",
"keys": {
"dataType": "bytes"
},
"values": {
"dataType": "integer"
"schema": {
"dataType": "map",
"keys": {
"dataType": "bytes"
},
"values": {
"dataType": "integer"
}
}
},
"compiledCode": "583b010000323232323232322253330054a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae881"
@ -657,9 +712,12 @@ mod test {
"datum": {
"title": "Data",
"description": "Any Plutus data.",
"schema": {},
},
"redeemer": {
"dataType": "integer",
"schema": {
"dataType": "integer",
}
},
"compiledCode": "5840010000323232323232322232253330074a22930b1bad0013001001222533300600214984cc014c004c01c008ccc00c00cc0200080055cd2b9b5573eae855d101"
}

View File

@ -9,11 +9,13 @@
"title": "spend.spend",
"datum": {
"title": "Data",
"description": "Any Plutus data."
"description": "Any Plutus data.",
"schema": {}
},
"redeemer": {
"title": "Data",
"description": "Any Plutus data."
"description": "Any Plutus data.",
"schema": {}
},
"compiledCode": "59015f010000323232323232323232322225333006323232323233001003232323322323232323330140014a0944004c94ccc05c0045288a5000133223233223253330173370e00290010801099190009bab301e00130110033018375400400297adef6c6033223300800200100200100100237566601260140049001001a441050000000000003001001222533301300213374a900125eb804c8c8c8c94ccc04ccdc7802800899ba548000cc060dd300125eb804ccc01c01c00c014dd7180a0019bab3014002301700330150023001001222533301000214a026464a66601c600600429444ccc01401400400cc05000cc048008dd6198009801198009801001a400090021119199800800a4000006444666601866e1c0100080488ccc010010cdc0001a40046028002002460146ea8004526163001001222533300800214984cc014c004c028008ccc00c00cc02c0080055cd2b9b5573aaae7955cfaba05742ae89",
"hash": "3f46b921ead33594e1da4afa1f1ba31807c0d8deca029f96fe9fe394"
@ -23,48 +25,52 @@
"redeemer": {
"title": "Unit",
"description": "The nullary constructor.",
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
"schema": {
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
}
},
"parameters": [
{
"title": "OutputReference",
"description": "An `OutputReference` is a unique reference to an output on-chain. The `output_index`\n corresponds to the position in the output list of the transaction (identified by its id)\n that produced that output",
"anyOf": [
{
"title": "OutputReference",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "transaction_id",
"description": "A unique transaction identifier, as the hash of a transaction body. Note that the transaction id\n isn't a direct hash of the `Transaction` as visible on-chain. Rather, they correspond to hash\n digests of transaction body as they are serialized on the network.",
"anyOf": [
{
"title": "TransactionId",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "hash",
"dataType": "bytes"
}
]
}
]
},
{
"title": "output_index",
"dataType": "integer"
}
]
}
]
"schema": {
"anyOf": [
{
"title": "OutputReference",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "transaction_id",
"description": "A unique transaction identifier, as the hash of a transaction body. Note that the transaction id\n isn't a direct hash of the `Transaction` as visible on-chain. Rather, they correspond to hash\n digests of transaction body as they are serialized on the network.",
"anyOf": [
{
"title": "TransactionId",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "hash",
"dataType": "bytes"
}
]
}
]
},
{
"title": "output_index",
"dataType": "integer"
}
]
}
]
}
}
],
"compiledCode": "58e301000032323232323232323232222533300632323232533300a3370e0029000099251300400214a060166ea8004c8c8cc004dd6198019802198019802002a40009000119baf33004300500148000020c0040048894ccc03c0084cdd2a400497ae013232533300d300300213374a90001980900125eb804ccc01401400400cc04c00cc04400888c8ccc0040052000003222333300c3370e008004024466600800866e0000d200230140010012300a37540022930b180080091129998040010a4c26600a600260140046660060066016004002ae695cdaab9d5573caae7d5d02ba157441",

View File

@ -10,24 +10,28 @@
"datum": {
"title": "Unit",
"description": "The nullary constructor.",
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
"schema": {
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
}
},
"redeemer": {
"title": "Unit",
"description": "The nullary constructor.",
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
"schema": {
"anyOf": [
{
"dataType": "constructor",
"index": 0,
"fields": []
}
]
}
},
"compiledCode": "583b0100003232323232323222253330064a22930b180080091129998030010a4c26600a6002600e0046660060066010004002ae695cdaab9f5742ae89",
"hash": "e37db487fbd58c45d059bcbf5cd6b1604d3bec16cf888f1395a4ebc4"

View File

@ -9,11 +9,13 @@
"title": "foo.spend",
"datum": {
"title": "Data",
"description": "Any Plutus data."
"description": "Any Plutus data.",
"schema": {}
},
"redeemer": {
"title": "Data",
"description": "Any Plutus data."
"description": "Any Plutus data.",
"schema": {}
},
"compiledCode": "586001000032323232323232323222253330063370e6464640046eb4c02c008dd69804800a5ef6c6010104000101010048020526163001001222533300800214984cc014c004c024008ccc00c00cc0280080055cd2b9b5573aaae7955cfaba157441",
"hash": "7ecbfc3ae91c4d5ba3799b4d283e385d457c860cd22034d825379ae2"

View File

@ -9,156 +9,160 @@
"title": "spend.pool_contract",
"datum": {
"title": "PoolDatum",
"anyOf": [
{
"title": "PoolDatum",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "currency_symbol",
"anyOf": [
{
"title": "CurrencySymbol",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "policy_id",
"dataType": "bytes"
},
{
"title": "asset_name",
"dataType": "bytes"
}
]
}
]
},
{
"title": "balance",
"dataType": "integer"
},
{
"title": "lent_out",
"dataType": "integer"
}
]
}
]
"schema": {
"anyOf": [
{
"title": "PoolDatum",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "currency_symbol",
"anyOf": [
{
"title": "CurrencySymbol",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "policy_id",
"dataType": "bytes"
},
{
"title": "asset_name",
"dataType": "bytes"
}
]
}
]
},
{
"title": "balance",
"dataType": "integer"
},
{
"title": "lent_out",
"dataType": "integer"
}
]
}
]
}
},
"redeemer": {
"title": "PoolRedeemer",
"anyOf": [
{
"title": "PoolRedeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "action",
"anyOf": [
{
"title": "PoolWithdraw",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "integer"
}
]
},
{
"title": "PoolDeposit",
"dataType": "constructor",
"index": 1,
"fields": [
{
"title": "PoolDepositRedeemer",
"anyOf": [
{
"title": "PoolDepositRedeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "input_cs",
"anyOf": [
{
"title": "CurrencySymbol",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "policy_id",
"dataType": "bytes"
},
{
"title": "asset_name",
"dataType": "bytes"
}
]
}
]
},
{
"title": "input_amount",
"dataType": "integer"
}
]
}
]
}
]
},
{
"title": "PoolBorrow",
"dataType": "constructor",
"index": 2,
"fields": [
{
"title": "PoolBorrowRedeemer",
"anyOf": [
{
"title": "PoolBorrowRedeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "input_cs",
"anyOf": [
{
"title": "CurrencySymbol",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "policy_id",
"dataType": "bytes"
},
{
"title": "asset_name",
"dataType": "bytes"
}
]
}
]
},
{
"title": "input_amount",
"dataType": "integer"
}
]
}
]
}
]
}
]
}
]
}
]
"schema": {
"anyOf": [
{
"title": "PoolRedeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "action",
"anyOf": [
{
"title": "PoolWithdraw",
"dataType": "constructor",
"index": 0,
"fields": [
{
"dataType": "integer"
}
]
},
{
"title": "PoolDeposit",
"dataType": "constructor",
"index": 1,
"fields": [
{
"title": "PoolDepositRedeemer",
"anyOf": [
{
"title": "PoolDepositRedeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "input_cs",
"anyOf": [
{
"title": "CurrencySymbol",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "policy_id",
"dataType": "bytes"
},
{
"title": "asset_name",
"dataType": "bytes"
}
]
}
]
},
{
"title": "input_amount",
"dataType": "integer"
}
]
}
]
}
]
},
{
"title": "PoolBorrow",
"dataType": "constructor",
"index": 2,
"fields": [
{
"title": "PoolBorrowRedeemer",
"anyOf": [
{
"title": "PoolBorrowRedeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "input_cs",
"anyOf": [
{
"title": "CurrencySymbol",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "policy_id",
"dataType": "bytes"
},
{
"title": "asset_name",
"dataType": "bytes"
}
]
}
]
},
{
"title": "input_amount",
"dataType": "integer"
}
]
}
]
}
]
}
]
}
]
}
]
}
},
"compiledCode": "59030501000032323232323232323232322225333006323232323232323232533300f3370e002900009925130090021533300f3370e0029001099191919299980999b87001480084c8c8cccc8888c8c8c8c8c9289812000980b19299980e99b8748000c080dd500088008a9980fa492a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e0016330120070033022001301432533301b3370e9000180f1baa0011001153301d49012a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163300f005001300d48901ff00010001012005301b001300d00214a0602a6ea8004cc028c02c03120023017001300900213232323253330133370e0029001099191999911119191919192513024001301632533301d3370e900018101baa0011001153301f49012a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e0016330120070033022001301432533301b3370e9000180f1baa0011001153301d49012a4173736572746564206f6e20696e636f727265637420636f6e7374727563746f722076617269616e742e00163300f005001300d48901ff00010001012005301b001300d00214a0602a6ea8004cc028c02c031200230170013009002301137540026600c600e0129000119ba548000cc04ccdd2a4004660266ea40052f5c06602666e9520024bd7025eb8088cc010dd6198031803998031803801240009002119baf3300730080014800000888cc00cdd6198029803198029803001240009000119baf3300630073300630070014800920000023001001222533301000213374a900125eb804c8c94ccc034c00c0084cdd2a40006602600497ae013330050050010033014003301200222323330010014800000c888cccc030cdc3802001009919980200219b8000348008c0540040048c02cdd50008a4c2c6002002444a666012004293099802980098058011998018019806001000ab9a5736ae7155ceaab9e5573eae815d0aba201",
"hash": "c95b3842362b77afec21773b7c0b1f09e61bf5e4c58b685533e6d342"

View File

@ -10,35 +10,39 @@
"title": "hello_world.spend",
"datum": {
"title": "Datum",
"anyOf": [
{
"title": "Datum",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "owner",
"dataType": "bytes"
}
]
}
]
"schema": {
"anyOf": [
{
"title": "Datum",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "owner",
"dataType": "bytes"
}
]
}
]
}
},
"redeemer": {
"title": "Redeemer",
"anyOf": [
{
"title": "Redeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "msg",
"dataType": "bytes"
}
]
}
]
"schema": {
"anyOf": [
{
"title": "Redeemer",
"dataType": "constructor",
"index": 0,
"fields": [
{
"title": "msg",
"dataType": "bytes"
}
]
}
]
}
},
"compiledCode": "58dd0100003232323232323232222533300632323232533300a002100114a06464660026eb0cc010c014cc010c014019200048040dd7198021802804240006002002444a66601e00429404c8c94ccc038cdc78010018a5113330050050010033012003375c602000466e3cdd71980098010022400091010d48656c6c6f2c20576f726c64210022323330010014800000c888cccc030cdc3802001008119980200219b8000348008c0480040048c024dd50008a4c2c6002002444a66600e004293099802980098040011998018019804801000ab9a5736aae7955cfaba15745",
"hash": "46872294cadbacb2c3214086c0129ede75cf9f767e95a449f996685f"