#![no_std]
#[doc(hidden)]
pub extern crate alloc;
#[doc(hidden)]
pub use casper_types;
use alloc::string::String;
use casper_types::{bytesrepr, CLType, CLTyped};
pub use casper_event_standard_macro::Event;
mod cl_type2;
mod schema;
pub use cl_type2::CLType2;
pub use schema::{Schema, Schemas};
#[cfg(target_arch = "wasm32")]
mod contract;
#[cfg(target_arch = "wasm32")]
pub use contract::{emit, init};
#[cfg(not(target_arch = "wasm32"))]
pub fn init(_schemas: Schemas) {
panic!("Init can be used only in wasm32.")
}
#[cfg(not(target_arch = "wasm32"))]
pub fn emit<T>(_event: T) {
panic!("Emit can be used only in wasm32.")
}
pub const EVENTS_DICT: &str = "__events";
pub const EVENTS_LENGTH: &str = "__events_length";
pub const EVENTS_SCHEMA: &str = "__events_schema";
pub const CES_VERSION_KEY: &str = "__events_ces_version";
pub const CES_VERSION: &str = "1.1";
pub trait EventInstance {
fn name() -> String;
fn schema() -> schema::Schema;
}
pub fn try_full_name_from_bytes(bytes: &[u8]) -> Result<String, bytesrepr::Error> {
let (name, _) = bytesrepr::FromBytes::from_bytes(bytes)?;
Ok(name)
}
pub fn validate_type<T: CLTyped>(_: &T) -> Result<(), bytesrepr::Error> {
if has_any(&T::cl_type()) {
Err(bytesrepr::Error::Formatting)
} else {
Ok(())
}
}
fn has_any(ty: &CLType) -> bool {
match ty {
CLType::Any => true,
CLType::Bool
| CLType::I32
| CLType::I64
| CLType::U8
| CLType::U32
| CLType::U64
| CLType::U128
| CLType::U256
| CLType::U512
| CLType::Unit
| CLType::String
| CLType::Key
| CLType::URef
| CLType::PublicKey
| CLType::ByteArray(_) => false,
CLType::Option(ty) => has_any(ty),
CLType::List(ty) => has_any(ty),
CLType::Result { ok, err } => has_any(ok) || has_any(err),
CLType::Map { key, value } => has_any(key) || has_any(value),
CLType::Tuple1([ty]) => has_any(ty),
CLType::Tuple2([ty1, ty2]) => has_any(ty1) || has_any(ty2),
CLType::Tuple3([ty1, ty2, ty3]) => has_any(ty1) || has_any(ty2) || has_any(ty3),
}
}