#![doc(
html_logo_url = "https://use.ink/img/crate-docs/logo.png",
html_favicon_url = "https://use.ink/crate-docs/favicon.png"
)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]
extern crate alloc;
extern crate core;
#[cfg(test)]
mod tests;
pub mod layout;
mod specs;
mod utils;
pub use ink_primitives::LangError;
pub use self::specs::{
ConstructorSpec,
ConstructorSpecBuilder,
ContractSpec,
ContractSpecBuilder,
DisplayName,
EnvironmentSpec,
EnvironmentSpecBuilder,
EventParamSpec,
EventParamSpecBuilder,
EventSpec,
EventSpecBuilder,
MessageParamSpec,
MessageParamSpecBuilder,
MessageSpec,
MessageSpecBuilder,
ReturnTypeSpec,
Selector,
TypeSpec,
};
use impl_serde::serialize as serde_hex;
#[doc(hidden)]
pub use linkme;
pub use scale_info::TypeInfo;
#[cfg(feature = "derive")]
use scale_info::{
form::PortableForm,
IntoPortable as _,
PortableRegistry,
Registry,
};
use schemars::JsonSchema;
use serde::{
Deserialize,
Serialize,
};
const METADATA_VERSION: u64 = 5;
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct InkProject {
version: u64,
#[serde(flatten)]
registry: PortableRegistry,
#[serde(rename = "storage")]
layout: layout::Layout<PortableForm>,
spec: ContractSpec<PortableForm>,
}
impl InkProject {
pub fn new<L, S>(layout: L, spec: S) -> Self
where
L: Into<layout::Layout>,
S: Into<ContractSpec>,
{
let mut registry = Registry::new();
Self {
version: METADATA_VERSION,
layout: layout.into().into_portable(&mut registry),
spec: spec.into().into_portable(&mut registry),
registry: registry.into(),
}
}
pub fn new_portable(
layout: layout::Layout<PortableForm>,
spec: ContractSpec<PortableForm>,
registry: PortableRegistry,
) -> Self {
Self {
version: METADATA_VERSION,
layout,
spec,
registry,
}
}
pub fn version(&self) -> &u64 {
&self.version
}
pub fn registry(&self) -> &PortableRegistry {
&self.registry
}
pub fn layout(&self) -> &layout::Layout<PortableForm> {
&self.layout
}
pub fn spec(&self) -> &ContractSpec<PortableForm> {
&self.spec
}
}
#[linkme::distributed_slice]
pub static EVENTS: [fn() -> EventSpec] = [..];
pub fn collect_events() -> Vec<EventSpec> {
EVENTS.iter().map(|event| event()).collect()
}
pub trait EventMetadata {
const MODULE_PATH: &'static str;
fn event_spec() -> EventSpec;
}