#![feature(min_specialization)]
extern crate tea_codec as tea_sdk;
use error::Result;
use primitive_types::{H160, U256};
use serde::{Deserialize, Serialize};
use std::{
fmt::{Debug, Display, Formatter},
sync::Arc,
};
use tea_sdk::serde::TypeId;
pub mod cml;
pub mod entity;
pub mod error;
pub mod event;
pub mod fluencer;
pub mod machine;
pub mod ra;
pub mod seat;
pub mod statement;
pub mod sys;
pub mod tapp;
pub mod version;
pub type Hash = [u8; 32];
pub type Ts = u128;
pub type ReplicaId = [u8; 32];
pub type BlockNumber = u64;
pub type Account = H160;
pub type Balance = U256;
pub const CENTS: Balance = U256([10_000_000_000_000_000, 0, 0, 0]);
pub const DOLLARS: Balance = U256([1_000_000_000_000_000_000, 0, 0, 0]);
pub type TimestampShort = i64;
pub type AuthKey = u128;
pub const GOD_MODE_AUTH_KEY: AuthKey = u128::MAX;
#[derive(Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub struct TokenId(pub H160);
#[derive(Debug, Clone, Serialize, Deserialize, TypeId, PartialEq, Eq, Hash)]
pub enum AccountId {
User(H160),
App(H160),
Other(Arc<[u8]>),
}
impl Display for AccountId {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
Debug::fmt(&self, f)
}
}
impl From<[u8; 20]> for TokenId {
fn from(v: [u8; 20]) -> Self {
TokenId(H160(v))
}
}
impl From<H160> for TokenId {
fn from(v: H160) -> Self {
TokenId(v)
}
}
impl Debug for TokenId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "0x{}", hex::encode(self.0))
}
}
impl TokenId {
pub fn to_hex(&self) -> String {
format!("{:?}", self.0)
}
pub fn from_hex<T: AsRef<str>>(s: T) -> Result<Self> {
let inner: H160 = s
.as_ref()
.parse()
.map_err(|_| crate::error::Errors::ParseAddressError)?;
Ok(inner.into())
}
}