use candid::CandidType;
use serde::{Deserialize, Serialize};
use crate::{
canister::{call::call_canister, types::CanisterCallResult},
identity::{CanisterId, Subaccount, UserId},
};
#[derive(CandidType, Serialize, 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) -> CanisterCallResult<Icrc1SupportedStandards> {
call_canister::<_, Icrc1SupportedStandards>(canister_id, "icrc1_supported_standards", ()).await
}
#[allow(unused)]
pub async fn icrc1_supported_standards_by(canister_id: CanisterId) -> CanisterCallResult<Vec<String>> {
icrc1_supported_standards(canister_id)
.await
.map(|r| r.into_iter().map(|i| i.name).collect())
}
#[allow(unused)]
pub async fn icrc1_name(canister_id: CanisterId) -> CanisterCallResult<String> {
call_canister::<_, String>(canister_id, "icrc1_name", ()).await
}
#[allow(unused)]
pub async fn icrc1_symbol(canister_id: CanisterId) -> CanisterCallResult<String> {
call_canister::<_, String>(canister_id, "icrc1_symbol", ()).await
}
#[allow(unused)]
pub async fn icrc1_decimals(canister_id: CanisterId) -> CanisterCallResult<u8> {
call_canister::<_, u8>(canister_id, "icrc1_decimals", ()).await
}
pub type Icrc1TotalSupply = candid::Nat;
#[allow(unused)]
pub async fn icrc1_total_supply(canister_id: CanisterId) -> CanisterCallResult<Icrc1TotalSupply> {
call_canister::<_, Icrc1TotalSupply>(canister_id, "icrc1_total_supply", ()).await
}
pub type Icrc1Subaccount = Subaccount;
#[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
pub struct Icrc1Account {
pub owner: UserId,
pub subaccount: Option<Icrc1Subaccount>,
}
pub type Icrc1Balance = candid::Nat;
#[allow(unused)]
pub async fn icrc1_balance_of(canister_id: CanisterId, account: Icrc1Account) -> CanisterCallResult<Icrc1Balance> {
call_canister::<_, Icrc1Balance>(canister_id, "icrc1_balance_of", (account,)).await
}
#[allow(unused)]
pub async fn icrc1_balance_of_by(
canister_id: CanisterId,
owner: UserId,
subaccount: Option<Icrc1Subaccount>,
) -> CanisterCallResult<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) -> CanisterCallResult<Icrc1Fee> {
call_canister::<_, Icrc1Fee>(canister_id, "icrc1_fee", ()).await
}
pub type Icrc1TransferArgs = icrc_ledger_types::icrc1::transfer::TransferArg;
pub type Icrc1TransferError = icrc_ledger_types::icrc1::transfer::TransferError;
pub type Icrc1TransferResult = Result<candid::Nat, icrc_ledger_types::icrc1::transfer::TransferError>;
#[allow(unused)]
pub async fn icrc1_transfer(
canister_id: CanisterId,
args: Icrc1TransferArgs,
) -> CanisterCallResult<Icrc1TransferResult> {
call_canister::<_, Icrc1TransferResult>(canister_id, "icrc1_transfer", (args,)).await
}
#[allow(unused)]
pub async fn icrc1_transfer_by(
canister_id: CanisterId,
amount: candid::Nat,
owner: UserId,
subaccount: Option<Icrc1Subaccount>,
) -> CanisterCallResult<Icrc1TransferResult> {
icrc1_transfer(
canister_id,
Icrc1TransferArgs {
from_subaccount: None,
to: icrc_ledger_types::icrc1::account::Account { owner, subaccount },
amount,
fee: None,
memo: None,
created_at_time: None,
},
)
.await
}