use alloc::{string::String, vec::Vec};
use crate::Type;
#[derive(Debug, Clone)]
pub struct Entrypoint {
pub ident: String,
pub args: Vec<Argument>,
pub is_mut: bool,
pub ret: Type,
pub ty: EntrypointType
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Argument {
pub ident: String,
pub ty: Type,
pub is_ref: bool
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum EntrypointType {
Constructor { non_reentrant: bool },
Public { non_reentrant: bool },
PublicPayable { non_reentrant: bool }
}
impl EntrypointType {
pub fn is_non_reentrant(&self) -> bool {
match self {
EntrypointType::Constructor { non_reentrant } => *non_reentrant,
EntrypointType::Public { non_reentrant } => *non_reentrant,
EntrypointType::PublicPayable { non_reentrant } => *non_reentrant
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Event {
pub ident: String,
pub args: Vec<Argument>
}
impl Event {
pub fn has_any(&self) -> bool {
self.args.iter().any(|arg| Type::has_any(&arg.ty))
}
}
pub trait HasEntrypoints {
fn entrypoints() -> Vec<Entrypoint>;
}
pub trait HasIdent {
fn ident() -> String;
}
pub trait HasEvents {
fn events() -> Vec<Event>;
}