Define 'apply_parameter' method on 'Project'
This commit is contained in:
parent
12f4768008
commit
592d3d7a1c
|
@ -53,7 +53,10 @@ impl Blueprint<Schema> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Blueprint<T> {
|
||||
impl<T> Blueprint<T>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
pub fn lookup(
|
||||
&self,
|
||||
title: Option<&String>,
|
||||
|
@ -83,10 +86,10 @@ impl<T> Blueprint<T> {
|
|||
action: F,
|
||||
) -> Result<A, E>
|
||||
where
|
||||
F: Fn(&Validator<T>) -> Result<A, E>,
|
||||
F: Fn(Validator<T>) -> Result<A, E>,
|
||||
{
|
||||
match self.lookup(title, purpose) {
|
||||
Some(LookupResult::One(validator)) => action(validator),
|
||||
Some(LookupResult::One(validator)) => action(validator.to_owned()),
|
||||
Some(LookupResult::Many) => Err(when_too_many(
|
||||
self.validators
|
||||
.iter()
|
||||
|
|
|
@ -122,7 +122,12 @@ impl Validator<Schema> {
|
|||
.unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Validator<T>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
pub fn apply(&mut self, arg: &Term<DeBruijn>) -> Result<(), Error> {
|
||||
match self.parameters.split_first() {
|
||||
None => Err(Error::NoParametersToApply),
|
||||
|
|
|
@ -12,7 +12,7 @@ pub mod pretty;
|
|||
pub mod script;
|
||||
pub mod telemetry;
|
||||
|
||||
use crate::blueprint::{schema::Schema, validator, Blueprint, LookupResult};
|
||||
use crate::blueprint::{schema::Schema, validator, Blueprint};
|
||||
use aiken_lang::{
|
||||
ast::{Definition, Function, ModuleKind, TypedDataType, TypedFunction},
|
||||
builder::{DataTypeKey, FunctionAccessKey},
|
||||
|
@ -37,7 +37,7 @@ use std::{
|
|||
};
|
||||
use telemetry::EventListener;
|
||||
use uplc::{
|
||||
ast::{Constant, Term},
|
||||
ast::{Constant, DeBruijn, Term},
|
||||
machine::cost_model::ExBudget,
|
||||
};
|
||||
|
||||
|
@ -306,9 +306,8 @@ where
|
|||
};
|
||||
|
||||
// Read blueprint
|
||||
let filepath = self.blueprint_path();
|
||||
let blueprint =
|
||||
File::open(filepath).map_err(|_| blueprint::error::Error::InvalidOrMissingFile)?;
|
||||
let blueprint = File::open(self.blueprint_path())
|
||||
.map_err(|_| blueprint::error::Error::InvalidOrMissingFile)?;
|
||||
let blueprint: Blueprint<serde_json::Value> =
|
||||
serde_json::from_reader(BufReader::new(blueprint))?;
|
||||
|
||||
|
@ -323,6 +322,33 @@ where
|
|||
})
|
||||
}
|
||||
|
||||
pub fn apply_parameter(
|
||||
&self,
|
||||
title: Option<&String>,
|
||||
purpose: Option<&validator::Purpose>,
|
||||
param: &Term<DeBruijn>,
|
||||
) -> Result<Blueprint<serde_json::Value>, Error> {
|
||||
// Read blueprint
|
||||
let blueprint = File::open(self.blueprint_path())
|
||||
.map_err(|_| blueprint::error::Error::InvalidOrMissingFile)?;
|
||||
let blueprint: Blueprint<serde_json::Value> =
|
||||
serde_json::from_reader(BufReader::new(blueprint))?;
|
||||
|
||||
// Apply parameters
|
||||
let when_too_many =
|
||||
|known_validators| Error::MoreThanOneValidatorFound { known_validators };
|
||||
let when_missing = |known_validators| Error::NoValidatorNotFound { known_validators };
|
||||
blueprint.with_validator(
|
||||
title,
|
||||
purpose,
|
||||
when_too_many,
|
||||
when_missing,
|
||||
|mut validator| validator.apply(param).map_err(|e| e.into()),
|
||||
)?;
|
||||
|
||||
Ok(blueprint)
|
||||
}
|
||||
|
||||
fn compile_deps(&mut self) -> Result<(), Error> {
|
||||
let manifest = deps::download(
|
||||
&self.event_listener,
|
||||
|
|
Loading…
Reference in New Issue