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

View File

@ -390,8 +390,8 @@ impl CheckedModule {
} }
Definition::Validator(Validator { Definition::Validator(Validator {
params, params,
fun, handlers,
other_fun, fallback,
.. ..
}) => { }) => {
for param in params { for param in params {
@ -404,18 +404,8 @@ impl CheckedModule {
} }
} }
for argument in fun.arguments.iter_mut() { for handler in handlers.iter_mut() {
let docs: Vec<&str> = for argument in handler.arguments.iter_mut() {
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() {
let docs: Vec<&str> = comments_before( let docs: Vec<&str> = comments_before(
&mut doc_comments, &mut doc_comments,
argument.location.start, 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 modules
} }
// todo: this might need fixing
pub fn validators(&self) -> impl Iterator<Item = (&CheckedModule, &TypedValidator)> { pub fn validators(&self) -> impl Iterator<Item = (&CheckedModule, &TypedValidator)> {
let mut items = vec![]; let mut items = vec![];