1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
// Copyright 2018-2021 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use derive_more::From;
/// This is just a temporary solution for the MVP!
/// As a temporary solution we choose the same type as the default
/// `env` `Balance` type.
///
/// In the long-term this type should be `Vec<u8>` as well, as to not
/// be dependent on the specific off-chain environment type, so that
/// the `engine` crate can be used with an arbitrary `Environment` configuration.
pub type Balance = u128;
/// The Account Id type used by this crate.
#[derive(Debug, From, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct AccountId(Vec<u8>);
impl AccountId {
/// Creates a new `AccountId` from the given raw bytes.
pub fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
/// Returns the `AccountId` as bytes.
pub fn as_bytes(&self) -> &[u8] {
&self.0[..]
}
}
/// Key into the database.
///
/// Used to identify contract storage cells for read and write operations.
#[derive(Default, From, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct Key(Vec<u8>);
impl Key {
/// Creates a new `Key` from the given raw bytes.
pub fn from_bytes(bytes: &[u8]) -> Self {
Self(bytes.to_vec())
}
}
/// Errors encountered upon interacting with accounts.
#[derive(Clone, Debug, From, PartialEq, Eq)]
pub enum AccountError {
Decoding(scale::Error),
#[from(ignore)]
UnexpectedUserAccount,
#[from(ignore)]
NoAccountForId(Vec<u8>),
}