feat: get bluprint stuff compiling again
This commit is contained in:
@@ -65,7 +65,7 @@ where
|
||||
let mut validator = None;
|
||||
for v in self.validators.iter() {
|
||||
let match_title = Some(&v.title) == title.or(Some(&v.title));
|
||||
let match_purpose = Some(&v.purpose) == purpose.or(Some(&v.purpose));
|
||||
let match_purpose = v.purpose.as_ref() == purpose.or(v.purpose.as_ref());
|
||||
if match_title && match_purpose {
|
||||
validator = Some(if validator.is_none() {
|
||||
LookupResult::One(v)
|
||||
@@ -81,8 +81,8 @@ where
|
||||
&self,
|
||||
title: Option<&String>,
|
||||
purpose: Option<&Purpose>,
|
||||
when_missing: fn(Vec<(String, Purpose)>) -> E,
|
||||
when_too_many: fn(Vec<(String, Purpose)>) -> E,
|
||||
when_missing: fn(Vec<(String, String)>) -> E,
|
||||
when_too_many: fn(Vec<(String, String)>) -> E,
|
||||
action: F,
|
||||
) -> Result<A, E>
|
||||
where
|
||||
@@ -93,13 +93,27 @@ where
|
||||
Some(LookupResult::Many) => Err(when_too_many(
|
||||
self.validators
|
||||
.iter()
|
||||
.map(|v| (v.title.clone(), v.purpose.clone()))
|
||||
.map(|v| {
|
||||
let mut title = v.title.split('-');
|
||||
|
||||
(
|
||||
title.next().unwrap().to_string(),
|
||||
title.next().unwrap().to_string(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
)),
|
||||
None => Err(when_missing(
|
||||
self.validators
|
||||
.iter()
|
||||
.map(|v| (v.title.clone(), v.purpose.clone()))
|
||||
.map(|v| {
|
||||
let mut title = v.title.split('-');
|
||||
|
||||
(
|
||||
title.next().unwrap().to_string(),
|
||||
title.next().unwrap().to_string(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
)),
|
||||
}
|
||||
|
||||
@@ -580,6 +580,7 @@ fn find_definition<'a>(
|
||||
match def {
|
||||
Definition::DataType(data_type) if name == data_type.name => return Some(data_type),
|
||||
Definition::Fn { .. }
|
||||
| Definition::Validator { .. }
|
||||
| Definition::DataType { .. }
|
||||
| Definition::TypeAlias { .. }
|
||||
| Definition::Use { .. }
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::{
|
||||
error::{assert_min_arity, assert_return_bool, Error},
|
||||
error::Error,
|
||||
schema::{Annotated, Schema},
|
||||
};
|
||||
use crate::module::{CheckedModule, CheckedModules};
|
||||
use aiken_lang::{ast::TypedFunction, uplc::CodeGenerator};
|
||||
use aiken_lang::{ast::TypedValidator, uplc::CodeGenerator};
|
||||
use miette::NamedSource;
|
||||
use serde;
|
||||
use std::{
|
||||
@@ -15,7 +15,8 @@ use uplc::ast::{DeBruijn, Program, Term};
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Validator<T> {
|
||||
pub title: String,
|
||||
pub purpose: Purpose,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub purpose: Option<Purpose>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -48,30 +49,21 @@ impl Validator<Schema> {
|
||||
pub fn from_checked_module(
|
||||
modules: &CheckedModules,
|
||||
generator: &mut CodeGenerator,
|
||||
validator: &CheckedModule,
|
||||
def: &TypedFunction,
|
||||
module: &CheckedModule,
|
||||
def: &TypedValidator,
|
||||
) -> Result<Validator<Schema>, Error> {
|
||||
let purpose: Purpose = def
|
||||
.name
|
||||
.clone()
|
||||
.try_into()
|
||||
.expect("unexpected validator name");
|
||||
let mut args = def.fun.arguments.iter().rev();
|
||||
let (_, redeemer, datum) = (args.next(), args.next().unwrap(), args.next());
|
||||
|
||||
assert_return_bool(validator, def)?;
|
||||
assert_min_arity(validator, def, purpose.min_arity())?;
|
||||
let mut arguments = Vec::with_capacity(def.params.len() + def.fun.arguments.len());
|
||||
|
||||
let mut args = def.arguments.iter().rev();
|
||||
let (_, redeemer) = (args.next(), args.next().unwrap());
|
||||
let datum = if purpose.min_arity() > 2 {
|
||||
args.next()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
arguments.extend(def.params.clone());
|
||||
arguments.extend(def.fun.arguments.clone());
|
||||
|
||||
Ok(Validator {
|
||||
title: validator.name.clone(),
|
||||
title: format!("{}-{}", &module.name, &def.fun.name),
|
||||
description: None,
|
||||
purpose,
|
||||
purpose: None,
|
||||
parameters: args
|
||||
.rev()
|
||||
.map(|param| {
|
||||
@@ -81,8 +73,8 @@ impl Validator<Schema> {
|
||||
error,
|
||||
location: param.location,
|
||||
source_code: NamedSource::new(
|
||||
validator.input_path.display().to_string(),
|
||||
validator.code.clone(),
|
||||
module.input_path.display().to_string(),
|
||||
module.code.clone(),
|
||||
),
|
||||
},
|
||||
);
|
||||
@@ -101,8 +93,8 @@ impl Validator<Schema> {
|
||||
error,
|
||||
location: datum.location,
|
||||
source_code: NamedSource::new(
|
||||
validator.input_path.display().to_string(),
|
||||
validator.code.clone(),
|
||||
module.input_path.display().to_string(),
|
||||
module.code.clone(),
|
||||
),
|
||||
},
|
||||
)
|
||||
@@ -113,12 +105,12 @@ impl Validator<Schema> {
|
||||
error,
|
||||
location: redeemer.location,
|
||||
source_code: NamedSource::new(
|
||||
validator.input_path.display().to_string(),
|
||||
validator.code.clone(),
|
||||
module.input_path.display().to_string(),
|
||||
module.code.clone(),
|
||||
),
|
||||
})?,
|
||||
program: generator
|
||||
.generate(&def.body, &def.arguments, true)
|
||||
.generate(&def.fun.body, &arguments, true)
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user