feat: adjust blueprint stuff to be aware of handlers

This commit is contained in:
rvcas 2024-08-06 15:33:48 -04:00 committed by KtorZ
parent 471bbe2175
commit 466a4f0b39
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 37 additions and 42 deletions

View File

@ -52,34 +52,32 @@ impl Validator {
def: &TypedValidator,
plutus_version: &PlutusVersion,
) -> Vec<Result<Validator, Error>> {
let is_multi_validator = def.other_fun.is_some();
let mut program = MemoProgram::new();
let mut validators = vec![Validator::create_validator_blueprint(
generator,
modules,
module,
def,
&def.fun,
is_multi_validator,
&mut program,
plutus_version,
)];
let mut validators = vec![];
if let Some(ref other_func) = def.other_fun {
for handler in &def.handlers {
validators.push(Validator::create_validator_blueprint(
generator,
modules,
module,
def,
other_func,
is_multi_validator,
hander,
&mut program,
plutus_version,
));
}
validators.push(Validator::create_validator_blueprint(
generator,
modules,
module,
def,
&def.fallback,
&mut program,
plutus_version,
));
validators
}
@ -90,7 +88,6 @@ impl Validator {
module: &CheckedModule,
def: &TypedValidator,
func: &TypedFunction,
is_multi_validator: bool,
program: &mut MemoProgram,
plutus_version: &PlutusVersion,
) -> Result<Validator, Error> {
@ -160,16 +157,11 @@ impl Validator {
})
.map(|schema| Parameter {
title: Some(redeemer.arg_name.get_label()),
schema: match datum {
Some(..) if is_multi_validator => {
Annotated::as_wrapped_redeemer(&mut definitions, schema, redeemer.tipo.clone())
}
_ => schema,
},
schema,
})?;
Ok(Validator {
title: format!("{}.{}", &module.name, &func.name),
title: format!("{}.{}_{}", &module.name, &def.name, &func.name),
description: func.doc.clone(),
parameters,
datum,
@ -848,11 +840,13 @@ mod tests {
let mut definitions = fixture_definitions();
definitions.insert(
&schema,
Schema::Data(Data::AnyOf(vec![Constructor {
Schema::Data(Data::AnyOf(vec![
Constructor {
index: 0,
fields: vec![Declaration::Referenced(Reference::new("Bool")).into()],
}
.into()]))
.into(),
]))
.into(),
);

View File

@ -390,8 +390,8 @@ impl CheckedModule {
}
Definition::Validator(Validator {
params,
fun,
other_fun,
handlers,
fallback,
..
}) => {
for param in params {
@ -404,18 +404,8 @@ impl CheckedModule {
}
}
for argument in fun.arguments.iter_mut() {
let docs: Vec<&str> =
comments_before(&mut doc_comments, argument.location.start, &self.code);
if !docs.is_empty() {
let doc = docs.join("\n");
argument.put_doc(doc);
}
}
if let Some(fun) = other_fun {
for argument in fun.arguments.iter_mut() {
for handler in handlers.iter_mut() {
for argument in handler.arguments.iter_mut() {
let docs: Vec<&str> = comments_before(
&mut doc_comments,
argument.location.start,
@ -428,6 +418,16 @@ impl CheckedModule {
}
}
}
for argument in fallback.arguments.iter_mut() {
let docs: Vec<&str> =
comments_before(&mut doc_comments, argument.location.start, &self.code);
if !docs.is_empty() {
let doc = docs.join("\n");
argument.put_doc(doc);
}
}
}
_ => (),
}
@ -463,6 +463,7 @@ impl CheckedModules {
modules
}
// todo: this might need fixing
pub fn validators(&self) -> impl Iterator<Item = (&CheckedModule, &TypedValidator)> {
let mut items = vec![];