ink_primitives/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//! Utilities in use by ink!.
16//!
17//! These are kept separate from ink! core utilities to allow for more dynamic inter-crate
18//! dependencies. The main problem is that today Cargo manages crate features on a
19//! per-crate basis instead of a per-crate-target basis thus making dependencies from
20//! `ink` (or others) to `ink_env` or `ink_storage` impossible.
21//!
22//! By introducing `ink_primitives` we have a way to share utility components between
23//! `ink_env` or `ink_storage` and other parts of the framework, like `ink`.
24
25#![doc(
26 html_logo_url = "https://use.ink/img/crate-docs/logo.png",
27 html_favicon_url = "https://use.ink/crate-docs/favicon.png"
28)]
29#![cfg_attr(not(feature = "std"), no_std)]
30
31pub mod abi;
32mod arithmetic;
33pub mod contract;
34mod key;
35pub mod reflect;
36pub mod sol;
37pub mod types;
38
39pub use self::{
40 key::{
41 Key,
42 KeyComposer,
43 },
44 reflect::{
45 DecodeDispatch,
46 DispatchError,
47 },
48 sol::{
49 SolDecode,
50 SolEncode,
51 },
52 types::{
53 AccountId,
54 AccountIdMapper,
55 Address,
56 Clear,
57 Hash,
58 },
59};
60
61pub use primitive_types::{
62 H160,
63 H256,
64 U256,
65};
66
67pub use sp_weights::Weight;
68
69/// An error emitted by the smart contracting language.
70///
71/// This is different than errors from:
72/// - Errors from the contract, which are programmer defined
73/// - Errors from the underlying execution environment (e.g `pallet-revive`)
74#[non_exhaustive]
75#[repr(u32)]
76#[derive(Debug, Copy, Clone, PartialEq, Eq, ::scale::Encode, ::scale::Decode)]
77#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))]
78pub enum LangError {
79 /// Failed to read execution input for the dispatchable.
80 CouldNotReadInput = 1u32,
81}
82
83/// Error encountered while trying to look up a contract's hash.
84#[derive(Debug, Copy, Clone, PartialEq, Eq)]
85pub enum CodeHashErr {
86 NotContractButAccount,
87 AddressNotFound,
88}
89
90/// The `Result` type for ink! messages.
91pub type MessageResult<T> = ::core::result::Result<T, LangError>;
92
93/// The `Result` type for ink! constructors.
94pub type ConstructorResult<T> = ::core::result::Result<T, LangError>;