dip721_rs/
canister.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use candid::{CandidType, Deserialize, Nat, Principal};
use serde::Serialize;
use thiserror::Error;

/// Metadata for a DIP721 canister
#[derive(CandidType, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Metadata {
    pub created_at: u64,
    pub custodians: Vec<Principal>,
    pub logo: Option<String>,
    pub name: Option<String>,
    pub symbol: Option<String>,
    pub upgraded_at: u64,
}

/// Canister stats
#[derive(CandidType, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Stats {
    pub cycles: Nat,
    pub total_supply: Nat,
    pub total_transactions: Nat,
    pub total_unique_holders: Nat,
}

/// Supported interfaces for a DIP721 canister
#[derive(CandidType, Serialize, PartialEq, Eq, Debug, Deserialize, Clone, Copy)]
pub enum SupportedInterface {
    Approval,
    Burn,
    Mint,
    TransactionHistory,
}

/// Represent an NFT error to return via API
#[derive(CandidType, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Error)]
pub enum NftError {
    #[error("self transfer is not allowed")]
    SelfTransfer,
    #[error("token not found")]
    TokenNotFound,
    #[error("transaction not found")]
    TxNotFound,
    #[error("not approved")]
    SelfApprove,
    #[error("operator not found")]
    OperatorNotFound,
    #[error("unauthorized owner")]
    UnauthorizedOwner,
    #[error("unauthorized operator")]
    UnauthorizedOperator,
    #[error("NFT existed")]
    ExistedNFT,
    #[error("owner not found")]
    OwnerNotFound,
    #[error("{0}")]
    Other(String),
}