ink/
lib.rs

1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![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#[macro_use]
22#[doc(hidden)]
23pub mod option_info;
24
25#[macro_use]
26#[doc(hidden)]
27pub mod result_info;
28
29#[cfg_attr(not(feature = "show-codegen-docs"), doc(hidden))]
30pub mod codegen;
31
32pub use ink_env::reflect;
33
34mod contract_ref;
35mod env_access;
36mod message_builder;
37pub mod sol;
38
39pub use ink_env as env;
40#[cfg(feature = "std")]
41pub use ink_metadata as metadata;
42pub use ink_prelude as prelude;
43pub use ink_primitives as primitives;
44pub use ink_primitives::abi;
45pub use scale;
46#[cfg(feature = "std")]
47pub use scale_info;
48#[cfg(feature = "xcm")]
49pub use xcm;
50
51pub extern crate polkavm_derive;
52#[doc(hidden)]
53pub use polkavm_derive::*;
54
55pub mod storage {
56    pub mod traits {
57        pub use ink_macro::{
58            Storable,
59            StorableHint,
60            StorageKey,
61            StorageLayout,
62        };
63        pub use ink_storage::traits::*;
64    }
65    pub use ink_storage::{
66        Lazy,
67        Mapping,
68        StorageVec,
69    };
70}
71
72pub use self::{
73    contract_ref::ToAddr,
74    env_access::EnvAccess,
75    prelude::IIP2_WILDCARD_COMPLEMENT_SELECTOR,
76};
77pub use ink_macro::{
78    Event,
79    EventMetadata,
80    SolDecode,
81    SolEncode,
82    SolErrorDecode,
83    SolErrorEncode,
84    SolErrorMetadata,
85    blake2x256,
86    contract,
87    contract_ref,
88    error,
89    event,
90    scale_derive,
91    selector_bytes,
92    selector_id,
93    storage_item,
94    test,
95    trait_definition,
96};
97pub use ink_primitives::{
98    Address,
99    ConstructorResult,
100    H160,
101    H256,
102    LangError,
103    MessageResult,
104    SolDecode,
105    SolEncode,
106    U256,
107};
108
109#[cfg(feature = "std")]
110#[doc(hidden)]
111pub use linkme;
112
113#[cfg(feature = "std")]
114use ink_metadata::EventSpec;
115
116/// Any event which derives `#[derive(ink::EventMetadata)]` and is used in the contract
117/// binary will have its implementation added to this distributed slice at linking time.
118#[cfg(feature = "std")]
119#[linkme::distributed_slice]
120#[linkme(crate = linkme)]
121pub static CONTRACT_EVENTS: [fn() -> EventSpec] = [..];
122
123/// Collect the [`EventSpec`] metadata of all event definitions linked and used in the
124/// binary.
125#[cfg(feature = "std")]
126pub fn collect_events() -> Vec<EventSpec> {
127    CONTRACT_EVENTS.iter().map(|event| event()).collect()
128}
129
130/// Any event whose parameters type implement `ink::SolDecode` and `ink::SolEncode`
131/// and is used in the contract binary will have its implementation added to this
132/// distributed slice at linking time.
133#[cfg(all(feature = "std", any(ink_abi = "sol", ink_abi = "all")))]
134#[linkme::distributed_slice]
135#[linkme(crate = linkme)]
136pub static CONTRACT_EVENTS_SOL: [fn() -> ink_metadata::sol::EventMetadata] = [..];
137
138/// Collect the Solidity ABI compatible metadata of all event definitions linked and used
139/// in the binary.
140#[cfg(all(feature = "std", any(ink_abi = "sol", ink_abi = "all")))]
141pub fn collect_events_sol() -> Vec<ink_metadata::sol::EventMetadata> {
142    crate::CONTRACT_EVENTS_SOL
143        .iter()
144        .map(|event| event())
145        .collect()
146}
147
148/// Any error which derives `#[derive(ink::SolErrorMetadata)]` and is used in the contract
149/// binary will have its implementation added to this distributed slice at linking time.
150#[cfg(feature = "std")]
151#[linkme::distributed_slice]
152#[linkme(crate = linkme)]
153pub static CONTRACT_ERRORS_SOL: [fn() -> Vec<ink_metadata::sol::ErrorMetadata>] = [..];
154
155/// Collect the Solidity ABI compatible metadata of all error definitions encoded as
156/// Solidity custom errors that are linked and used in the binary.
157#[cfg(feature = "std")]
158pub fn collect_errors_sol() -> Vec<ink_metadata::sol::ErrorMetadata> {
159    crate::CONTRACT_ERRORS_SOL
160        .iter()
161        .flat_map(|event| event())
162        .collect()
163}