1use candid::{CandidType, Deserialize, Nat, Principal};
2use ex3_common_error_info::ErrorInfo;
3use serde::Serialize;
4
5pub type BlockHeight = Nat;
6pub type TokenHolder = AccountIdentifier;
7pub type TokenReceiver = AccountIdentifier;
8pub type TransactionId = String;
9pub type BlockHash = [u8; 32];
10
11#[derive(
14 CandidType, Serialize, Deserialize, Clone, Copy, Hash, Debug, PartialEq, Eq, PartialOrd, Ord,
15)]
16pub struct AccountIdentifier {
17 hash: [u8; 28],
18}
19
20#[derive(CandidType, Serialize, Deserialize, Clone, Copy, Hash, Debug, PartialEq, Eq)]
24pub struct Subaccount(pub [u8; 32]);
25
26#[derive(CandidType, Deserialize, Debug, Clone)]
27pub enum OperationResult {
28 Ok {
29 #[serde(rename = "txId")]
30 tx_id: TransactionId,
31 #[serde(rename = "blockHeight")]
32 block_height: Nat,
33 },
34 Err(ErrorInfo),
35}
36
37#[derive(CandidType, Deserialize, Debug, Clone)]
38pub struct ArchivedBlocksRange {
39 pub start: Nat,
40 pub length: u64,
41 #[serde(rename = "storageCanisterId")]
42 pub storage_canister_id: Principal,
43}
44
45#[derive(CandidType, Deserialize, Debug, Clone)]
46pub struct QueryBlocksResult {
47 #[serde(rename = "chainLength")]
48 pub chain_length: Nat,
49 pub certificate: Option<serde_bytes::ByteBuf>,
50 pub blocks: Vec<Block>,
51 #[serde(rename = "firstBlockIndex")]
52 pub first_block_index: Nat,
53 #[serde(rename = "archivedBlocks")]
54 pub archived_blocks: Vec<ArchivedBlocksRange>,
55}
56
57#[derive(CandidType, Deserialize, Debug, Clone)]
58pub enum Operation {
59 Approve {
60 caller: Principal,
61 owner: TokenHolder,
62 spender: TokenHolder,
63 value: Nat,
64 fee: Nat,
65 },
66 Transfer {
67 caller: TokenHolder,
68 from: TokenHolder,
69 to: TokenReceiver,
70 value: Nat,
71 fee: Nat,
72 },
73 FeeModify {
74 caller: Principal,
75 #[serde(rename = "newFee")]
76 new_fee: TokenFee,
77 },
78 OwnerModify {
79 caller: Principal,
80 #[serde(rename = "newOwner")]
81 new_owner: Principal,
82 },
83 FeeToModify {
84 caller: Principal,
85 #[serde(rename = "newFeeTo")]
86 new_fee_to: TokenHolder,
87 },
88 AddMinter {
89 caller: Principal,
90 minter: Principal,
91 },
92 RemoveMinter {
93 caller: Principal,
94 minter: Principal,
95 },
96}
97
98#[derive(CandidType, Deserialize, Debug, Clone)]
99pub struct TokenFee {
100 pub minimum: Nat,
101 pub rate: u32,
102 #[serde(rename = "rateDecimals")]
103 pub rate_decimals: u8,
104}
105
106#[derive(CandidType, Deserialize, Debug, Clone)]
107pub struct Transaction {
108 pub operation: Operation,
109 #[serde(rename = "createdAt")]
111 pub created_at: u64,
112}
113
114#[derive(CandidType, Deserialize, Debug, Clone)]
115pub struct Block {
116 #[serde(rename = "parentHash")]
117 pub parent_hash: BlockHash,
118 pub transaction: Transaction,
119 pub timestamp: u64,
120}
121
122#[derive(CandidType, Deserialize, Debug, Clone)]
123pub enum BlockResult {
124 Ok(Block),
126 Forward(Principal),
128 Err(ErrorInfo),
130}