Generated wrapped schemas for multi-validators' redeemers
This commit is contained in:
parent
bb6fc76971
commit
bc690c5410
|
@ -521,11 +521,7 @@ impl<'comments> Formatter<'comments> {
|
||||||
))
|
))
|
||||||
.nest(INDENT)
|
.nest(INDENT)
|
||||||
.group()
|
.group()
|
||||||
.append(if other_fun.is_some() {
|
.append(if other_fun.is_some() { line() } else { nil() })
|
||||||
line()
|
|
||||||
} else {
|
|
||||||
nil()
|
|
||||||
})
|
|
||||||
.append(
|
.append(
|
||||||
other_fun
|
other_fun
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::blueprint::definitions::{Definitions, Reference};
|
||||||
use crate::CheckedModule;
|
use crate::CheckedModule;
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
ast::{DataType, Definition, TypedDefinition},
|
ast::{DataType, Definition, TypedDefinition},
|
||||||
|
builtins::wrapped_redeemer,
|
||||||
tipo::{pretty, Type, TypeVar},
|
tipo::{pretty, Type, TypeVar},
|
||||||
};
|
};
|
||||||
use owo_colors::{OwoColorize, Stream::Stdout};
|
use owo_colors::{OwoColorize, Stream::Stdout};
|
||||||
|
@ -12,6 +13,9 @@ use serde::{
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
|
// NOTE: Can be anything BUT 0
|
||||||
|
pub const REDEEMER_DISCRIMINANT: usize = 1;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Annotated<T> {
|
pub struct Annotated<T> {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
@ -71,6 +75,30 @@ impl<T> From<T> for Annotated<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Annotated<Schema> {
|
impl Annotated<Schema> {
|
||||||
|
pub fn as_wrapped_redeemer(
|
||||||
|
definitions: &mut Definitions<Annotated<Schema>>,
|
||||||
|
schema: Reference,
|
||||||
|
type_info: Arc<Type>,
|
||||||
|
) -> Reference {
|
||||||
|
definitions
|
||||||
|
.register(
|
||||||
|
&wrapped_redeemer(type_info),
|
||||||
|
&HashMap::new(),
|
||||||
|
|_| {
|
||||||
|
Ok::<_, Error>(Annotated {
|
||||||
|
title: Some("Wrapped Redeemer".to_string()),
|
||||||
|
description: Some("A redeemer wrapped in an extra constructor to make multi-validator detection possible on-chain.".to_string()),
|
||||||
|
annotated: Schema::Data(Data::AnyOf(vec![Constructor {
|
||||||
|
index: REDEEMER_DISCRIMINANT,
|
||||||
|
fields: vec![schema.into()],
|
||||||
|
}
|
||||||
|
.into()])),
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("cannot fail because Ok")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_type(
|
pub fn from_type(
|
||||||
modules: &HashMap<String, CheckedModule>,
|
modules: &HashMap<String, CheckedModule>,
|
||||||
type_info: &Type,
|
type_info: &Type,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
definitions::{Definitions, Reference},
|
definitions::{Definitions, Reference},
|
||||||
error::Error,
|
error::Error,
|
||||||
|
@ -8,7 +6,6 @@ use super::{
|
||||||
use crate::module::{CheckedModule, CheckedModules};
|
use crate::module::{CheckedModule, CheckedModules};
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
ast::{TypedArg, TypedFunction, TypedValidator},
|
ast::{TypedArg, TypedFunction, TypedValidator},
|
||||||
builtins::wrapped_redeemer,
|
|
||||||
uplc::CodeGenerator,
|
uplc::CodeGenerator,
|
||||||
};
|
};
|
||||||
use miette::NamedSource;
|
use miette::NamedSource;
|
||||||
|
@ -146,15 +143,15 @@ impl Validator<Reference, Annotated<Schema>> {
|
||||||
module.code.clone(),
|
module.code.clone(),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
.map(|schema| match datum {
|
.map(|schema| Argument {
|
||||||
Some(..) if is_multi_validator => {
|
|
||||||
let wrap_redeemer_type = wrapped_redeemer(redeemer.tipo);
|
|
||||||
|
|
||||||
definitions.register(&wrap_redeemer_type, &HashMap::new(), todo!());
|
|
||||||
}
|
|
||||||
_ => Argument {
|
|
||||||
title: Some(redeemer.arg_name.get_label()),
|
title: Some(redeemer.arg_name.get_label()),
|
||||||
|
schema: match datum {
|
||||||
|
Some(..) if is_multi_validator => Annotated::as_wrapped_redeemer(
|
||||||
|
&mut definitions,
|
||||||
schema,
|
schema,
|
||||||
|
redeemer.tipo.clone(),
|
||||||
|
),
|
||||||
|
_ => schema,
|
||||||
},
|
},
|
||||||
})?,
|
})?,
|
||||||
program: program.clone(),
|
program: program.clone(),
|
||||||
|
|
Loading…
Reference in New Issue