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;
19
20/// Same type as the `DefaultEnvironment::BlockNumber` type.
21pub type BlockNumber = u32;
22
23/// Same type as the `DefaultEnvironment::BlockTimestamp` type.
24pub type BlockTimestamp = u64;
25
26/// Same type as the `DefaultEnvironment::Balance` type.
27pub type Balance = u128;
28
29/// The Account Id type used by this crate.
30#[derive(Debug, From, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
31#[repr(transparent)]
32pub struct AccountId(Vec<u8>);
33
34impl AccountId {
35    /// Creates a new `AccountId` from the given raw bytes.
36    pub fn from_bytes(bytes: &[u8]) -> Self {
37        Self(bytes.to_vec())
38    }
39
40    /// Returns the `AccountId` as bytes.
41    pub fn as_bytes(&self) -> &[u8] {
42        &self.0[..]
43    }
44}
45
46/// Key into the database.
47///
48/// Used to identify contract storage cells for read and write operations.
49#[derive(Default, From, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
50#[repr(transparent)]
51pub struct Key(Vec<u8>);
52
53impl Key {
54    /// Creates a new `Key` from the given raw bytes.
55    #[allow(dead_code)]
56    pub fn from_bytes(bytes: &[u8]) -> Self {
57        Self(bytes.to_vec())
58    }
59}
60
61/// Errors encountered upon interacting with accounts.
62#[derive(Clone, Debug, From, PartialEq, Eq)]
63pub enum AccountError {
64    Decoding(scale::Error),
65    #[from(ignore)]
66    UnexpectedUserAccount,
67    #[from(ignore)]
68    NoAccountForId(Vec<u8>),
69}