feat: get bluprint stuff compiling again
This commit is contained in:
parent
d03288cece
commit
673b57b81c
|
@ -65,7 +65,7 @@ where
|
||||||
let mut validator = None;
|
let mut validator = None;
|
||||||
for v in self.validators.iter() {
|
for v in self.validators.iter() {
|
||||||
let match_title = Some(&v.title) == title.or(Some(&v.title));
|
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 {
|
if match_title && match_purpose {
|
||||||
validator = Some(if validator.is_none() {
|
validator = Some(if validator.is_none() {
|
||||||
LookupResult::One(v)
|
LookupResult::One(v)
|
||||||
|
@ -81,8 +81,8 @@ where
|
||||||
&self,
|
&self,
|
||||||
title: Option<&String>,
|
title: Option<&String>,
|
||||||
purpose: Option<&Purpose>,
|
purpose: Option<&Purpose>,
|
||||||
when_missing: fn(Vec<(String, Purpose)>) -> E,
|
when_missing: fn(Vec<(String, String)>) -> E,
|
||||||
when_too_many: fn(Vec<(String, Purpose)>) -> E,
|
when_too_many: fn(Vec<(String, String)>) -> E,
|
||||||
action: F,
|
action: F,
|
||||||
) -> Result<A, E>
|
) -> Result<A, E>
|
||||||
where
|
where
|
||||||
|
@ -93,13 +93,27 @@ where
|
||||||
Some(LookupResult::Many) => Err(when_too_many(
|
Some(LookupResult::Many) => Err(when_too_many(
|
||||||
self.validators
|
self.validators
|
||||||
.iter()
|
.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(),
|
.collect(),
|
||||||
)),
|
)),
|
||||||
None => Err(when_missing(
|
None => Err(when_missing(
|
||||||
self.validators
|
self.validators
|
||||||
.iter()
|
.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(),
|
.collect(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -580,6 +580,7 @@ fn find_definition<'a>(
|
||||||
match def {
|
match def {
|
||||||
Definition::DataType(data_type) if name == data_type.name => return Some(data_type),
|
Definition::DataType(data_type) if name == data_type.name => return Some(data_type),
|
||||||
Definition::Fn { .. }
|
Definition::Fn { .. }
|
||||||
|
| Definition::Validator { .. }
|
||||||
| Definition::DataType { .. }
|
| Definition::DataType { .. }
|
||||||
| Definition::TypeAlias { .. }
|
| Definition::TypeAlias { .. }
|
||||||
| Definition::Use { .. }
|
| Definition::Use { .. }
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use super::{
|
use super::{
|
||||||
error::{assert_min_arity, assert_return_bool, Error},
|
error::Error,
|
||||||
schema::{Annotated, Schema},
|
schema::{Annotated, Schema},
|
||||||
};
|
};
|
||||||
use crate::module::{CheckedModule, CheckedModules};
|
use crate::module::{CheckedModule, CheckedModules};
|
||||||
use aiken_lang::{ast::TypedFunction, uplc::CodeGenerator};
|
use aiken_lang::{ast::TypedValidator, uplc::CodeGenerator};
|
||||||
use miette::NamedSource;
|
use miette::NamedSource;
|
||||||
use serde;
|
use serde;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -15,7 +15,8 @@ use uplc::ast::{DeBruijn, Program, Term};
|
||||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct Validator<T> {
|
pub struct Validator<T> {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub purpose: Purpose,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub purpose: Option<Purpose>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
@ -48,30 +49,21 @@ impl Validator<Schema> {
|
||||||
pub fn from_checked_module(
|
pub fn from_checked_module(
|
||||||
modules: &CheckedModules,
|
modules: &CheckedModules,
|
||||||
generator: &mut CodeGenerator,
|
generator: &mut CodeGenerator,
|
||||||
validator: &CheckedModule,
|
module: &CheckedModule,
|
||||||
def: &TypedFunction,
|
def: &TypedValidator,
|
||||||
) -> Result<Validator<Schema>, Error> {
|
) -> Result<Validator<Schema>, Error> {
|
||||||
let purpose: Purpose = def
|
let mut args = def.fun.arguments.iter().rev();
|
||||||
.name
|
let (_, redeemer, datum) = (args.next(), args.next().unwrap(), args.next());
|
||||||
.clone()
|
|
||||||
.try_into()
|
|
||||||
.expect("unexpected validator name");
|
|
||||||
|
|
||||||
assert_return_bool(validator, def)?;
|
let mut arguments = Vec::with_capacity(def.params.len() + def.fun.arguments.len());
|
||||||
assert_min_arity(validator, def, purpose.min_arity())?;
|
|
||||||
|
|
||||||
let mut args = def.arguments.iter().rev();
|
arguments.extend(def.params.clone());
|
||||||
let (_, redeemer) = (args.next(), args.next().unwrap());
|
arguments.extend(def.fun.arguments.clone());
|
||||||
let datum = if purpose.min_arity() > 2 {
|
|
||||||
args.next()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Validator {
|
Ok(Validator {
|
||||||
title: validator.name.clone(),
|
title: format!("{}-{}", &module.name, &def.fun.name),
|
||||||
description: None,
|
description: None,
|
||||||
purpose,
|
purpose: None,
|
||||||
parameters: args
|
parameters: args
|
||||||
.rev()
|
.rev()
|
||||||
.map(|param| {
|
.map(|param| {
|
||||||
|
@ -81,8 +73,8 @@ impl Validator<Schema> {
|
||||||
error,
|
error,
|
||||||
location: param.location,
|
location: param.location,
|
||||||
source_code: NamedSource::new(
|
source_code: NamedSource::new(
|
||||||
validator.input_path.display().to_string(),
|
module.input_path.display().to_string(),
|
||||||
validator.code.clone(),
|
module.code.clone(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -101,8 +93,8 @@ impl Validator<Schema> {
|
||||||
error,
|
error,
|
||||||
location: datum.location,
|
location: datum.location,
|
||||||
source_code: NamedSource::new(
|
source_code: NamedSource::new(
|
||||||
validator.input_path.display().to_string(),
|
module.input_path.display().to_string(),
|
||||||
validator.code.clone(),
|
module.code.clone(),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -113,12 +105,12 @@ impl Validator<Schema> {
|
||||||
error,
|
error,
|
||||||
location: redeemer.location,
|
location: redeemer.location,
|
||||||
source_code: NamedSource::new(
|
source_code: NamedSource::new(
|
||||||
validator.input_path.display().to_string(),
|
module.input_path.display().to_string(),
|
||||||
validator.code.clone(),
|
module.code.clone(),
|
||||||
),
|
),
|
||||||
})?,
|
})?,
|
||||||
program: generator
|
program: generator
|
||||||
.generate(&def.body, &def.arguments, true)
|
.generate(&def.fun.body, &arguments, true)
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
blueprint::{error as blueprint, validator},
|
blueprint::error as blueprint, deps::manifest::Package, package_name::PackageName, pretty,
|
||||||
deps::manifest::Package,
|
|
||||||
package_name::PackageName,
|
|
||||||
pretty,
|
|
||||||
script::EvalHint,
|
script::EvalHint,
|
||||||
};
|
};
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
|
@ -136,12 +133,12 @@ pub enum Error {
|
||||||
|
|
||||||
#[error("I didn't find any validator matching your criteria.")]
|
#[error("I didn't find any validator matching your criteria.")]
|
||||||
NoValidatorNotFound {
|
NoValidatorNotFound {
|
||||||
known_validators: Vec<(String, validator::Purpose)>,
|
known_validators: Vec<(String, String)>,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("I found multiple suitable validators and I need you to tell me which one to pick.")]
|
#[error("I found multiple suitable validators and I need you to tell me which one to pick.")]
|
||||||
MoreThanOneValidatorFound {
|
MoreThanOneValidatorFound {
|
||||||
known_validators: Vec<(String, validator::Purpose)>,
|
known_validators: Vec<(String, String)>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,16 +175,19 @@ where
|
||||||
|
|
||||||
pub fn dump_uplc(&self, blueprint: &Blueprint<Schema>) -> Result<(), Error> {
|
pub fn dump_uplc(&self, blueprint: &Blueprint<Schema>) -> Result<(), Error> {
|
||||||
let dir = self.root.join("artifacts");
|
let dir = self.root.join("artifacts");
|
||||||
|
|
||||||
self.event_listener
|
self.event_listener
|
||||||
.handle_event(Event::DumpingUPLC { path: dir.clone() });
|
.handle_event(Event::DumpingUPLC { path: dir.clone() });
|
||||||
|
|
||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
|
|
||||||
for validator in &blueprint.validators {
|
for validator in &blueprint.validators {
|
||||||
let path = dir
|
let path = dir.clone().join(format!("{}.uplc", validator.title));
|
||||||
.clone()
|
|
||||||
.join(format!("{}::{}>.uplc", validator.title, validator.purpose));
|
|
||||||
fs::write(&path, validator.program.to_pretty())
|
fs::write(&path, validator.program.to_pretty())
|
||||||
.map_err(|error| Error::FileIo { error, path })?;
|
.map_err(|error| Error::FileIo { error, path })?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use aiken_lang::{
|
use aiken_lang::{
|
||||||
ast::{
|
ast::{
|
||||||
DataType, Definition, ModuleKind, TypedDataType, TypedFunction, TypedModule, UntypedModule,
|
DataType, Definition, ModuleKind, TypedDataType, TypedFunction, TypedModule,
|
||||||
|
TypedValidator, UntypedModule,
|
||||||
},
|
},
|
||||||
builder::{DataTypeKey, FunctionAccessKey},
|
builder::{DataTypeKey, FunctionAccessKey},
|
||||||
parser::extra::{comments_before, Comment, ModuleExtra},
|
parser::extra::{comments_before, Comment, ModuleExtra},
|
||||||
tipo::TypeInfo,
|
tipo::TypeInfo,
|
||||||
uplc::CodeGenerator,
|
uplc::CodeGenerator,
|
||||||
VALIDATOR_NAMES,
|
|
||||||
};
|
};
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use petgraph::{algo, graph::NodeIndex, Direction, Graph};
|
use petgraph::{algo, graph::NodeIndex, Direction, Graph};
|
||||||
|
@ -251,17 +251,17 @@ impl CheckedModules {
|
||||||
modules
|
modules
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn validators(&self) -> impl Iterator<Item = (&CheckedModule, &TypedFunction)> {
|
pub fn validators(&self) -> impl Iterator<Item = (&CheckedModule, &TypedValidator)> {
|
||||||
let mut items = vec![];
|
let mut items = vec![];
|
||||||
for validator in self.0.values().filter(|module| module.kind.is_validator()) {
|
|
||||||
for some_definition in validator.ast.definitions() {
|
for validator_module in self.0.values().filter(|module| module.kind.is_validator()) {
|
||||||
if let Definition::Fn(def) = some_definition {
|
for some_definition in validator_module.ast.definitions() {
|
||||||
if VALIDATOR_NAMES.contains(&def.name.as_str()) {
|
if let Definition::Validator(def) = some_definition {
|
||||||
items.push((validator, def));
|
items.push((validator_module, def));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items.into_iter()
|
items.into_iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,6 +313,7 @@ impl CheckedModules {
|
||||||
Definition::TypeAlias(_)
|
Definition::TypeAlias(_)
|
||||||
| Definition::ModuleConstant(_)
|
| Definition::ModuleConstant(_)
|
||||||
| Definition::Test(_)
|
| Definition::Test(_)
|
||||||
|
| Definition::Validator { .. }
|
||||||
| Definition::Use(_) => {}
|
| Definition::Use(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
},
|
},
|
||||||
"validators": [
|
"validators": [
|
||||||
{
|
{
|
||||||
"title": "hello_world",
|
"title": "hello_world-spend",
|
||||||
"purpose": "spend",
|
|
||||||
"datum": {
|
"datum": {
|
||||||
"title": "Datum",
|
"title": "Datum",
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
|
|
Loading…
Reference in New Issue