use candid::CandidType;
use serde::{Deserialize, Serialize};
use crate::{
canister::{call::call_canister, fetch_tuple0, 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
.map(fetch_tuple0)
}
#[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
.map(fetch_tuple0)
}
#[allow(unused)]
pub async fn icrc1_symbol(canister_id: CanisterId) -> CanisterCallResult<String> {
call_canister::<_, (String,)>(canister_id, "icrc1_symbol", ())
.await
.map(fetch_tuple0)
}
#[allow(unused)]
pub async fn icrc1_decimals(canister_id: CanisterId) -> CanisterCallResult<u8> {
call_canister::<_, (u8,)>(canister_id, "icrc1_decimals", ())
.await
.map(fetch_tuple0)
}
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
.map(fetch_tuple0)
}
pub type Icrc1Subaccount = Subaccount;
#[derive(CandidType, Serialize, 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,
) -> CanisterCallResult<Icrc1Balance> {
call_canister::<_, (Icrc1Balance,)>(canister_id, "icrc1_balance_of", (account,))
.await
.map(fetch_tuple0)
}
#[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
.map(fetch_tuple0)
}
pub type Icrc1Memo = Vec<u8>;
#[derive(CandidType, Deserialize, Debug, Clone)]
pub struct Icrc1TransferArgs {
pub from_subaccount: Option<Icrc1Subaccount>,
pub to: Icrc1Account,
pub amount: candid::Nat,
pub fee: Option<candid::Nat>,
pub memo: Option<Icrc1Memo>,
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,
) -> CanisterCallResult<Icrc1TransferResult> {
call_canister::<_, (Icrc1TransferResult,)>(canister_id, "icrc1_transfer", (args,))
.await
.map(fetch_tuple0)
}
#[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: Icrc1Account { owner, subaccount },
amount,
fee: None,
memo: None,
created_at_time: None,
},
)
.await
}