extern crate alloc;
use serde::Serialize;
#[derive(Debug, Clone, Copy, Serialize)]
pub struct Function {
pub name: &'static str,
pub doc: &'static str,
pub input: &'static str,
pub output: &'static str,
pub custom: bool,
}
#[derive(Debug, Clone, Copy, Serialize)]
pub struct Event {
pub topic: &'static str,
pub data: &'static str,
}
#[derive(Debug, Clone, Copy, Serialize)]
pub struct Import {
pub name: &'static str,
pub path: &'static str,
}
#[derive(Debug, Clone, Copy, Serialize)]
pub struct Contract {
pub name: &'static str,
pub imports: &'static [Import],
pub functions: &'static [Function],
pub events: &'static [Event],
}
impl Contract {
pub fn iter_imports(&self) -> impl Iterator<Item = &Import> {
self.imports.iter()
}
pub fn iter_functions(&self) -> impl Iterator<Item = &Function> {
self.functions.iter()
}
pub fn iter_events(&self) -> impl Iterator<Item = &Event> {
self.events.iter()
}
#[must_use]
pub fn get_import(&self, name: &str) -> Option<&Import> {
self.imports.iter().find(|i| i.name == name)
}
#[must_use]
pub fn get_function(&self, name: &str) -> Option<&Function> {
self.functions.iter().find(|f| f.name == name)
}
#[must_use]
pub fn get_event(&self, topic: &str) -> Option<&Event> {
self.events.iter().find(|e| e.topic == topic)
}
#[must_use]
pub fn to_json(&self) -> alloc::string::String {
serde_json::to_string(self).unwrap_or_else(|_| alloc::string::String::from("{}"))
}
}