Define 'is_library' for 'CheckedModule'
So that we can separate libraries from executable modules if necessary.
This commit is contained in:
parent
1edbf57943
commit
71e71fffe8
|
@ -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<T>
|
||||
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 {
|
||||
|
|
|
@ -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<String, CheckedModule>);
|
||||
|
||||
|
|
Loading…
Reference in New Issue