Skip to main content

canic_core/api/ic/
ledger.rs

1use crate::{
2    cdk::types::{Account, Principal},
3    dto::error::Error,
4    workflow::ic::ledger::LedgerWorkflow,
5};
6
7///
8/// LedgerApi
9///
10
11pub struct LedgerApi;
12
13impl LedgerApi {
14    /// Transfer tokens using an existing ICRC-2 allowance.
15    ///
16    /// This is the approved endpoint-facing API.
17    pub async fn transfer_from(
18        ledger_id: Principal,
19        payer: Principal,
20        spender: Account,
21        to: Account,
22        amount: u64,
23        memo: Option<Vec<u8>>,
24    ) -> Result<u64, Error> {
25        LedgerWorkflow::transfer_with_allowance_check(ledger_id, payer, spender, to, amount, memo)
26            .await
27            .map_err(Error::from)
28    }
29}