1#![doc(
16 html_logo_url = "https://use.ink/img/crate-docs/logo.png",
17 html_favicon_url = "https://use.ink/crate-docs/favicon.png"
18)]
19#![cfg_attr(not(feature = "std"), no_std)]
20
21#[cfg(not(feature = "std"))]
22extern crate alloc;
23extern crate core;
24
25#[cfg(test)]
26mod tests;
27
28pub mod layout;
29pub mod sol;
30mod specs;
31mod utils;
32
33pub use ink_primitives::LangError;
34
35pub use self::specs::{
36 ConstructorSpec,
37 ConstructorSpecBuilder,
38 ContractSpec,
39 ContractSpecBuilder,
40 DisplayName,
41 EnvironmentSpec,
42 EnvironmentSpecBuilder,
43 EventParamSpec,
44 EventParamSpecBuilder,
45 EventSpec,
46 EventSpecBuilder,
47 MessageParamSpec,
48 MessageParamSpecBuilder,
49 MessageSpec,
50 MessageSpecBuilder,
51 ReturnTypeSpec,
52 Selector,
53 TypeSpec,
54};
55
56use impl_serde::serialize as serde_hex;
57
58pub use scale_info::TypeInfo;
59
60#[cfg(feature = "derive")]
61use scale_info::{
62 IntoPortable as _,
63 PortableRegistry,
64 Registry,
65 form::PortableForm,
66};
67use schemars::JsonSchema;
68use serde::{
69 Deserialize,
70 Serialize,
71};
72
73const METADATA_VERSION: u64 = 6;
78
79#[derive(Debug, Serialize, Deserialize, JsonSchema)]
81pub struct InkProject {
82 version: u64,
83 #[serde(flatten)]
84 registry: PortableRegistry,
85 #[serde(rename = "storage")]
86 layout: layout::Layout<PortableForm>,
88 spec: ContractSpec<PortableForm>,
89}
90
91impl InkProject {
92 pub fn new<L, S>(layout: L, spec: S) -> Self
94 where
95 L: Into<layout::Layout>,
96 S: Into<ContractSpec>,
97 {
98 let mut registry = Registry::new();
99
100 Self {
101 version: METADATA_VERSION,
102 layout: layout.into().into_portable(&mut registry),
103 spec: spec.into().into_portable(&mut registry),
104 registry: registry.into(),
105 }
106 }
107
108 pub fn new_portable(
112 layout: layout::Layout<PortableForm>,
113 spec: ContractSpec<PortableForm>,
114 registry: PortableRegistry,
115 ) -> Self {
116 Self {
117 version: METADATA_VERSION,
118 layout,
119 spec,
120 registry,
121 }
122 }
123
124 pub fn version(&self) -> u64 {
126 self.version
127 }
128
129 pub fn registry(&self) -> &PortableRegistry {
131 &self.registry
132 }
133
134 pub fn layout(&self) -> &layout::Layout<PortableForm> {
136 &self.layout
137 }
138
139 pub fn spec(&self) -> &ContractSpec<PortableForm> {
141 &self.spec
142 }
143}
144
145pub trait EventMetadata {
151 const MODULE_PATH: &'static str;
153
154 fn event_spec() -> EventSpec;
156}