Write method to apply a UPLC term to an existing 'Validator'
This commit is contained in:
parent
9c71aab3db
commit
12f4768008
|
@ -27,6 +27,7 @@ pub enum Error {
|
||||||
source_code: NamedSource,
|
source_code: NamedSource,
|
||||||
return_type: Arc<Type>,
|
return_type: Arc<Type>,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("A {} validator requires at least {} arguments.", name.purple().bold(), at_least.to_string().purple().bold())]
|
#[error("A {} validator requires at least {} arguments.", name.purple().bold(), at_least.to_string().purple().bold())]
|
||||||
#[diagnostic(code("aiken::blueprint::invalid::arity"))]
|
#[diagnostic(code("aiken::blueprint::invalid::arity"))]
|
||||||
WrongValidatorArity {
|
WrongValidatorArity {
|
||||||
|
@ -37,6 +38,7 @@ pub enum Error {
|
||||||
#[source_code]
|
#[source_code]
|
||||||
source_code: NamedSource,
|
source_code: NamedSource,
|
||||||
},
|
},
|
||||||
|
|
||||||
#[error("{}", error)]
|
#[error("{}", error)]
|
||||||
#[diagnostic(help("{}", error.help()))]
|
#[diagnostic(help("{}", error.help()))]
|
||||||
#[diagnostic(code("aiken::blueprint::interface"))]
|
#[diagnostic(code("aiken::blueprint::interface"))]
|
||||||
|
@ -52,6 +54,10 @@ pub enum Error {
|
||||||
#[diagnostic(code("aiken::blueprint::missing"))]
|
#[diagnostic(code("aiken::blueprint::missing"))]
|
||||||
#[diagnostic(help("Did you forget to {build} the project?", build = "build".purple().bold()))]
|
#[diagnostic(help("Did you forget to {build} the project?", build = "build".purple().bold()))]
|
||||||
InvalidOrMissingFile,
|
InvalidOrMissingFile,
|
||||||
|
|
||||||
|
#[error("I didn't find any parameters to apply in the given validator.")]
|
||||||
|
#[diagnostic(code("aiken::blueprint::apply::no_parameters"))]
|
||||||
|
NoParametersToApply,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn assert_return_bool(module: &CheckedModule, def: &TypedFunction) -> Result<(), Error> {
|
pub fn assert_return_bool(module: &CheckedModule, def: &TypedFunction) -> Result<(), Error> {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
};
|
};
|
||||||
use uplc::ast::{DeBruijn, Program};
|
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> {
|
||||||
|
@ -122,6 +122,18 @@ impl Validator<Schema> {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn apply(&mut self, arg: &Term<DeBruijn>) -> Result<(), Error> {
|
||||||
|
match self.parameters.split_first() {
|
||||||
|
None => Err(Error::NoParametersToApply),
|
||||||
|
Some((_, tail)) => {
|
||||||
|
// TODO: Ideally, we should control that the applied term matches its schema.
|
||||||
|
self.program = self.program.apply_term(arg);
|
||||||
|
self.parameters = tail.to_vec();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Purpose {
|
impl Purpose {
|
||||||
|
|
Loading…
Reference in New Issue