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        DepositLimit,
58        Hash,
59    },
60};
61
62pub use primitive_types::{
63    H160,
64    H256,
65    U256,
66};
67
68pub use sp_weights::Weight;
69
70/// An error emitted by the smart contracting language.
71///
72/// This is different than errors from:
73/// - Errors from the contract, which are programmer defined
74/// - Errors from the underlying execution environment (e.g `pallet-revive`)
75#[non_exhaustive]
76#[repr(u32)]
77#[derive(Debug, Copy, Clone, PartialEq, Eq, ::scale::Encode, ::scale::Decode)]
78#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))]
79pub enum LangError {
80    /// Failed to read execution input for the dispatchable.
81    CouldNotReadInput = 1u32,
82}
83
84/// The `Result` type for ink! messages.
85pub type MessageResult<T> = ::core::result::Result<T, LangError>;
86
87/// The `Result` type for ink! constructors.
88pub type ConstructorResult<T> = ::core::result::Result<T, LangError>;