use candid::{CandidType, Deserialize};
use crate::identity::{CanisterId, UserId};
use super::CallError;
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct ICRC1SupportedStandard {
name: String, url: String, }
pub type ICRC1SupportedStandards = Vec<ICRC1SupportedStandard>;
#[allow(unused)]
pub async fn icrc1_supported_standards(canister_id: CanisterId) -> ICRC1SupportedStandards {
let _call_result: Result<(ICRC1SupportedStandards,), CallError> =
ic_cdk::call(canister_id, "icrc1_supported_standards", ()).await;
_call_result.unwrap().0
}
#[allow(unused)]
pub async fn icrc1_supported_standards_by(canister_id: CanisterId) -> Vec<String> {
icrc1_supported_standards(canister_id)
.await
.iter()
.map(|s| s.name.clone())
.collect()
}
#[allow(unused)]
pub async fn icrc1_name(canister_id: CanisterId) -> String {
let _call_result: Result<(String,), CallError> =
ic_cdk::call(canister_id, "icrc1_name", ()).await;
_call_result.unwrap().0
}
#[allow(unused)]
pub async fn icrc1_symbol(canister_id: CanisterId) -> String {
let _call_result: Result<(String,), CallError> =
ic_cdk::call(canister_id, "icrc1_symbol", ()).await;
_call_result.unwrap().0
}
#[allow(unused)]
pub async fn icrc1_decimals(canister_id: CanisterId) -> u8 {
let _call_result: Result<(u8,), CallError> =
ic_cdk::call(canister_id, "icrc1_decimals", ()).await;
_call_result.unwrap().0
}
pub type ICRC1TotalSupply = candid::Nat;
#[allow(unused)]
pub async fn icrc1_total_supply(canister_id: CanisterId) -> ICRC1TotalSupply {
let _call_result: Result<(ICRC1TotalSupply,), CallError> =
ic_cdk::call(canister_id, "icrc1_total_supply", ()).await;
_call_result.unwrap().0
}
pub type ICRC1Subaccount = Vec<u8>;
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct ICRC1Account {
owner: UserId,
subaccount: Option<ICRC1Subaccount>,
}
pub type ICRC1Balance = candid::Nat;
#[allow(unused)]
pub async fn icrc1_balance_of(canister_id: CanisterId, account: ICRC1Account) -> ICRC1Balance {
let _call_result: Result<(ICRC1Balance,), CallError> =
ic_cdk::call(canister_id, "icrc1_balance_of", ()).await;
_call_result.unwrap().0
}
#[allow(unused)]
pub async fn icrc1_balance_of_by(
canister_id: CanisterId,
owner: UserId,
subaccount: Option<ICRC1Subaccount>,
) -> ICRC1Balance {
icrc1_balance_of(canister_id, ICRC1Account { owner, subaccount }).await
}
pub type ICRC1Fee = candid::Nat;
#[allow(unused)]
pub async fn icrc1_fee(canister_id: CanisterId) -> ICRC1Fee {
let _call_result: Result<(ICRC1Fee,), CallError> =
ic_cdk::call(canister_id, "icrc1_fee", ()).await;
_call_result.unwrap().0
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct ICRC1TransferArgs {
pub from_subaccount: Option<ICRC1Subaccount>,
pub amount: candid::Nat,
pub to: ICRC1Account,
pub fee: Option<candid::Nat>,
pub memo: Option<Vec<u8>>,
pub created_at_time: Option<u64>,
}
#[derive(CandidType, Deserialize, Debug, Clone)]
pub enum ICRC1TransferError {
GenericError {
error_code: candid::Nat,
message: String,
},
TemporarilyUnavailable, BadBurn {
min_burn_amount: candid::Nat,
},
Duplicate {
duplicate_of: candid::Nat,
},
BadFee {
expected_fee: candid::Nat,
},
CreatedInFuture {
ledger_time: u64,
},
TooOld,
InsufficientFunds {
balance: candid::Nat,
},
}
pub type ICRC1TransferResult = Result<candid::Nat, ICRC1TransferError>;
#[allow(unused)]
pub async fn icrc1_transfer(
canister_id: CanisterId,
args: ICRC1TransferArgs,
) -> ICRC1TransferResult {
let _call_result: Result<(ICRC1TransferResult,), CallError> =
ic_cdk::call(canister_id, "icrc1_transfer", (args,)).await;
_call_result.unwrap().0
}
#[allow(unused)]
pub async fn icrc1_transfer_by(
canister_id: CanisterId,
amount: candid::Nat,
owner: UserId,
subaccount: Option<ICRC1Subaccount>,
) -> ICRC1TransferResult {
icrc1_transfer(
canister_id,
ICRC1TransferArgs {
from_subaccount: None,
amount,
to: ICRC1Account { owner, subaccount },
fee: None,
memo: None,
created_at_time: None,
},
)
.await
}