Write method to apply a UPLC term to an existing 'Validator'

This commit is contained in:
KtorZ
2023-02-04 10:22:23 +01:00
parent 9c71aab3db
commit 12f4768008
2 changed files with 19 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ use std::{
collections::HashMap,
fmt::{self, Display},
};
use uplc::ast::{DeBruijn, Program};
use uplc::ast::{DeBruijn, Program, Term};
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
pub struct Validator<T> {
@@ -122,6 +122,18 @@ impl Validator<Schema> {
.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 {