ink_engine/
types.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//! Right now the `engine` crate can only be used with the `ink_env::DefaultEnvironment`.
16//! This is a known limitation that we want to address in the future.
17
18use derive_more::From;
19use ink_primitives::{
20    AccountId,
21    Address,
22};
23
24/// Same type as the `DefaultEnvironment::BlockNumber` type.
25pub type BlockNumber = u32;
26
27/// Same type as the `DefaultEnvironment::BlockTimestamp` type.
28pub type BlockTimestamp = u64;
29
30/// Same type as the `DefaultEnvironment::Balance` type.
31pub type Balance = u128;
32
33/// Key into the database.
34///
35/// Used to identify contract storage cells for read and write operations.
36#[derive(Default, From, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
37#[repr(transparent)]
38pub struct Key(Vec<u8>);
39
40impl Key {
41    /// Creates a new `Key` from the given raw bytes.
42    #[allow(dead_code)]
43    pub fn from_bytes(bytes: &[u8]) -> Self {
44        Self(bytes.to_vec())
45    }
46}
47
48// todo rename the whole thing
49/// Errors encountered upon interacting with accounts.
50#[derive(Clone, Debug, From, PartialEq, Eq)]
51pub enum AccountError {
52    Decoding(scale::Error),
53    #[from(ignore)]
54    UnexpectedUserAccount,
55    #[from(ignore)]
56    NoAccountForId(AccountId),
57    NoContractForId(Address),
58}
59
60/// The type of origins supported by `pallet-revive`.
61#[derive(Debug, Eq, Default, Clone, scale::Encode, scale::Decode, PartialEq)]
62//#[cfg_attr(feature = "std", derive(::scale_info::TypeInfo))]
63pub enum Origin {
64    #[default]
65    Root,
66    Signed(Vec<u8>),
67}
68
69// impl Origin {
70// Returns the AccountId of a Signed Origin or an error if the origin is Root.
71// pub fn account_id(&self) -> Result<AccountId, ()> {
72// match self {
73// Origin::Signed(id) => {
74// let mut arr = [0u8; 32];
75// arr.copy_from_slice(id.as_slice());
76// Ok(AccountId::from(arr))
77// },
78// Origin::Root => Err(()),
79// }
80// }
81// }
82//