diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index eb45600d..cd5e5077 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -7,6 +7,7 @@ pub mod pretty; pub mod script; pub mod telemetry; +use crate::module::{CERT, MINT, SPEND, VALIDATOR_NAMES, WITHDRAW}; use aiken_lang::{ ast::{Definition, Function, ModuleKind, TypedDataType, TypedDefinition, TypedFunction}, builder::{DataTypeKey, FunctionAccessKey}, @@ -50,12 +51,6 @@ pub struct Source { pub kind: ModuleKind, } -pub const SPEND: &str = "spend"; -pub const CERT: &str = "cert"; -pub const MINT: &str = "mint"; -pub const WITHDRAWL: &str = "withdrawl"; -pub const VALIDATOR_NAMES: [&str; 4] = [SPEND, CERT, MINT, WITHDRAWL]; - pub struct Project where T: EventListener, @@ -351,7 +346,7 @@ where // depending on name, validate the minimum number of arguments // if too low, push a new error on to errors - if [MINT, CERT, WITHDRAWL].contains(&func_def.name.as_str()) + if [MINT, CERT, WITHDRAW].contains(&func_def.name.as_str()) && func_def.arguments.len() < 2 { errors.push(Error::WrongValidatorArity { diff --git a/crates/project/src/module.rs b/crates/project/src/module.rs index 022d369b..4a50ddf1 100644 --- a/crates/project/src/module.rs +++ b/crates/project/src/module.rs @@ -4,7 +4,7 @@ use std::{ path::PathBuf, }; -use aiken_lang::ast::{ModuleKind, TypedModule, UntypedModule}; +use aiken_lang::ast::{Definition, ModuleKind, TypedModule, UntypedModule}; use petgraph::{algo, graph::NodeIndex, Direction, Graph}; use crate::error::Error; @@ -155,6 +155,12 @@ fn find_cycle( false } +pub const SPEND: &str = "spend"; +pub const CERT: &str = "cert"; +pub const MINT: &str = "mint"; +pub const WITHDRAW: &str = "withdraw"; +pub const VALIDATOR_NAMES: [&str; 4] = [SPEND, CERT, MINT, WITHDRAW]; + #[derive(Debug, Clone)] pub struct CheckedModule { pub name: String, @@ -165,6 +171,15 @@ pub struct CheckedModule { // pub extra: ModuleExtra, } +impl CheckedModule { + pub fn is_library(&self) -> bool { + self.ast.definitions().any(|def| match def { + Definition::Fn(func_def) => VALIDATOR_NAMES.contains(&func_def.name.as_str()), + _ => false, + }) + } +} + #[derive(Debug, Clone)] pub struct CheckedModules(HashMap);