use candid::{CandidType, Deserialize, Nat, Principal};
use ex3_common_error_info::ErrorInfo;
use serde::Serialize;
pub type BlockHeight = Nat;
pub type TokenHolder = AccountIdentifier;
pub type TokenReceiver = AccountIdentifier;
pub type TransactionId = String;
pub type BlockHash = [u8; 32];
#[derive(
CandidType, Serialize, Deserialize, Clone, Copy, Hash, Debug, PartialEq, Eq, PartialOrd, Ord,
)]
pub struct AccountIdentifier {
hash: [u8; 28],
}
#[derive(CandidType, Serialize, Deserialize, Clone, Copy, Hash, Debug, PartialEq, Eq)]
pub struct Subaccount(pub [u8; 32]);
#[derive(CandidType, Deserialize, Debug, Clone)]
pub enum OperationResult {
Ok {
#[serde(rename = "txId")]
tx_id: TransactionId,
#[serde(rename = "blockHeight")]
block_height: Nat,
},
Err(ErrorInfo),
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct ArchivedBlocksRange {
pub start: Nat,
pub length: u64,
#[serde(rename = "storageCanisterId")]
pub storage_canister_id: Principal,
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct QueryBlocksResult {
#[serde(rename = "chainLength")]
pub chain_length: Nat,
pub certificate: Option<serde_bytes::ByteBuf>,
pub blocks: Vec<Block>,
#[serde(rename = "firstBlockIndex")]
pub first_block_index: Nat,
#[serde(rename = "archivedBlocks")]
pub archived_blocks: Vec<ArchivedBlocksRange>,
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub enum Operation {
Approve {
caller: Principal,
owner: TokenHolder,
spender: TokenHolder,
value: Nat,
fee: Nat,
},
Transfer {
caller: TokenHolder,
from: TokenHolder,
to: TokenReceiver,
value: Nat,
fee: Nat,
},
FeeModify {
caller: Principal,
#[serde(rename = "newFee")]
new_fee: TokenFee,
},
OwnerModify {
caller: Principal,
#[serde(rename = "newOwner")]
new_owner: Principal,
},
FeeToModify {
caller: Principal,
#[serde(rename = "newFeeTo")]
new_fee_to: TokenHolder,
},
AddMinter {
caller: Principal,
minter: Principal,
},
RemoveMinter {
caller: Principal,
minter: Principal,
},
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct TokenFee {
pub minimum: Nat,
pub rate: u32,
#[serde(rename = "rateDecimals")]
pub rate_decimals: u8,
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct Transaction {
pub operation: Operation,
#[serde(rename = "createdAt")]
pub created_at: u64,
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct Block {
#[serde(rename = "parentHash")]
pub parent_hash: BlockHash,
pub transaction: Transaction,
pub timestamp: u64,
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub enum BlockResult {
Ok(Block),
Forward(Principal),
Err(ErrorInfo),
}