use anyhow::Result; use serde::{Deserialize, Serialize}; /// Use integer incase we switch to i128 or otherwise. pub type Integer = i64; /// Non negative integer including 0 pub type Natural = u64; /// Suggestive of a positive integer. Note that this is not enforced at a type level. pub type Positive = u64; /// A natural representing and `amount of currency` pub type Amount = Natural; /// A natural representing an index of, say, a cheque or utxo. pub type Index = Natural; /// A time length in milliseconds pub type Milliseconds = Integer; /// Milliseconds since Epoch pub type Timestamp = Natural; // Alias for bytes pub type Blake2b256Hash = [u8; 32]; pub type Blake2b224Hash = [u8; 28]; pub type KeyHash = Blake2b224Hash; pub type ScriptHash = Blake2b224Hash; pub type TransactionId = Blake2b256Hash; pub type AssetName = Vec; pub type VerificationKey = [u8; 32]; pub type Signature = [u8; 64]; pub type ChannelId = [u8; 28]; pub type Currency = (ScriptHash, AssetName); /// To keep types consistent we denote the script hash of ada as `[0;28]`. pub fn ada_currency() -> Currency { ([0; 28], [0_u8; 0].to_vec()) } pub type Markdown = String; pub type Text = String; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Signed { body: T, #[serde(with = "serde_arrays")] signature: [u8; 64], } pub const E3: Natural = 1000 as Natural; pub const E6: Natural = E3 * E3; pub const E9: Natural = E6 * E3; pub const E12: Natural = E9 * E3; pub const SECOND: Milliseconds = 1000; pub const MINUTE: Milliseconds = 60 * SECOND; pub const HOUR: Milliseconds = 60 * MINUTE; pub const DAY: Milliseconds = 24 * HOUR; pub fn time_add(a: Timestamp, b: Milliseconds) -> Result { let x = Timestamp::try_from(a as i64 + b)?; Ok(x) }