use candid::{CandidType, Nat, Principal};
use ex3_ic_stable_structures::{storable::Bound, Storable};
use number::Ex3Uint;
use serde::{Deserialize, Serialize};
use serde_bytes::ByteBuf;
pub use version::Version;
pub mod asset;
pub mod balance_changed;
pub mod block;
pub mod chain;
pub mod market;
pub mod number;
pub mod package;
pub mod secret;
pub mod settings;
pub mod transaction;
pub mod vault;
mod version;
pub mod wallet_identifier;
pub type PublicKey = ByteBuf;
pub type WalletRegisterId = Ex3Uint;
pub type SpotMarketId = Ex3Uint;
pub type OrderId = Ex3Uint;
pub type AssetId = Ex3Uint;
pub type PackageId = Ex3Uint;
pub type AssetAmount = Ex3Uint;
pub type Nonce = Ex3Uint;
pub type BlockHeight = Ex3Uint;
pub type MerkleRoot = [u8; 32];
pub type MerkleNode = [u8; 32];
pub type BlockHash = [u8; 32];
pub type TransactionHash = [u8; 32];
pub type VaultSeqId = u64;
pub type WalletRegistrySeqId = VaultSeqId;
pub type BalanceVaultSeqId = VaultSeqId;
pub type SecretVaultSeqId = VaultSeqId;
pub type DepositId = Ex3Uint;
pub type CandidWalletRegisterId = Nat;
pub type CandidSpotMarketId = Nat;
pub type CandidOrderId = Nat;
pub type CandidPackageId = Nat;
pub type CandidAssetId = Nat;
pub type CandidAssetAmount = Nat;
pub type CandidNonce = Nat;
pub type CandidBlockHeight = Nat;
pub type CandidDepositId = Nat;
new_type_principal!(NodeProvider);
new_type_principal!(CanisterId);
#[macro_export(local_inner_macros)]
macro_rules! impl_from_uint_for {
($to_type:ty, $($t:ty),*) => {
$(
impl From<$t> for $to_type {
fn from(value: $t) -> Self {
<$to_type>::from(BigUint::from(value))
}
}
)*
};
}
#[macro_export]
macro_rules! new_type_principal {
($name:ident) => {
#[derive(
CandidType, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize,
)]
#[serde(transparent)]
pub struct $name(Principal);
impl From<Principal> for $name {
fn from(principal: Principal) -> Self {
Self(principal)
}
}
impl $name {
pub fn new(principal: Principal) -> Self {
Self(principal)
}
pub fn as_slice(&self) -> &[u8] {
self.0.as_slice()
}
pub fn as_ref(&self) -> &Principal {
&self.0
}
}
impl Storable for $name {
fn to_bytes(&self) -> std::borrow::Cow<[u8]> {
self.0.as_ref().into()
}
fn from_bytes(bytes: std::borrow::Cow<[u8]>) -> Self {
Self(Principal::from_slice(bytes.as_ref()))
}
const BOUND: Bound = Bound::Bounded {
max_size: 29,
is_fixed_size: false,
};
}
};
}