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
31mod arithmetic;
32pub mod contract;
33mod key;
34pub mod reflect;
35pub mod sol;
36pub mod types;
37
38pub use self::{
39 key::{
40 Key,
41 KeyComposer,
42 },
43 reflect::{
44 DecodeDispatch,
45 DispatchError,
46 },
47 sol::{
48 SolBytes,
49 SolDecode,
50 SolEncode,
51 },
52 types::{
53 AccountId,
54 AccountIdMapper,
55 Address,
56 Clear,
57 DepositLimit,
58 Hash,
59 },
60};
61
62pub use primitive_types::{
63 H160,
64 H256,
65 U256,
66};
67
68/// An error emitted by the smart contracting language.
69///
70/// This is different than errors from:
71/// - Errors from the contract, which are programmer defined
72/// - Errors from the underlying execution environment (e.g `pallet-revive`)
73#[non_exhaustive]
74#[repr(u32)]
75#[derive(Debug, Copy, Clone, PartialEq, Eq, ::scale::Encode, ::scale::Decode)]
76#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))]
77pub enum LangError {
78 /// Failed to read execution input for the dispatchable.
79 CouldNotReadInput = 1u32,
80}
81
82/// The `Result` type for ink! messages.
83pub type MessageResult<T> = ::core::result::Result<T, LangError>;
84
85/// The `Result` type for ink! constructors.
86pub type ConstructorResult<T> = ::core::result::Result<T, LangError>;