ex3-dft-client 0.17.1

Dfinity fungible token standard canister client-rs/client-canister.
Documentation
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];

/// AccountIdentifier is a 32-byte array.
/// The first 4 bytes is big-endian encoding of a CRC32 checksum of the last 28 bytes.
#[derive(
    CandidType, Serialize, Deserialize, Clone, Copy, Hash, Debug, PartialEq, Eq, PartialOrd, Ord,
)]
pub struct AccountIdentifier {
    hash: [u8; 28],
}

/// Subaccount is an arbitrary 32-byte byte array.
/// Ledger uses subaccounts to compute account pub_key, which enables one
/// principal to control multiple ledger accounts.
#[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,
    /// The time this transaction was created.
    #[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 {
    // Return tx record if exist in the DFT cache txs
    Ok(Block),
    // If not storage in DFT cache txs, return the storage canister id
    Forward(Principal),
    // Such as out of tx index or tx id not exist
    Err(ErrorInfo),
}