Skip to content

Commit a1f503d

Browse files
committed
Merge branch 'maciej-icrc2-types' into 'master'
feat(icrc2): add icrc2 types to the icrc-ledger-types library The types reflect the types in dfinity/ICRC-1#109 See merge request dfinity-lab/public/ic!12563
2 parents c49db18 + 4a41cc3 commit a1f503d

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use candid::{CandidType, Deserialize, Nat};
2+
3+
use super::super::icrc1::account::Account;
4+
5+
#[derive(CandidType, Deserialize, Clone, Debug, PartialEq, Eq)]
6+
pub struct AllowanceArgs {
7+
pub account: Account,
8+
pub spender: Account,
9+
}
10+
11+
#[derive(CandidType, Deserialize, Clone, Debug, PartialEq, Eq)]
12+
pub struct Allowance {
13+
pub allowance: Nat,
14+
#[serde(default)]
15+
pub expired_at: Option<u64>,
16+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use candid::{CandidType, Deserialize, Nat};
2+
3+
use super::super::icrc1::account::{Account, Subaccount};
4+
use super::super::icrc1::transfer::Memo;
5+
6+
#[derive(CandidType, Deserialize, Clone, Debug, PartialEq, Eq)]
7+
pub struct ApproveArgs {
8+
#[serde(default)]
9+
pub from_subaccount: Option<Subaccount>,
10+
pub spender: Account,
11+
pub amount: Nat,
12+
#[serde(default)]
13+
pub expected_allowance: Option<Nat>,
14+
#[serde(default)]
15+
pub expired_at: Option<u64>,
16+
#[serde(default)]
17+
pub fee: Option<Nat>,
18+
#[serde(default)]
19+
pub memo: Option<Memo>,
20+
#[serde(default)]
21+
pub created_at_time: Option<u64>,
22+
}
23+
24+
#[derive(CandidType, Deserialize, Clone, Debug, PartialEq, Eq)]
25+
pub enum ApproveError {
26+
BadFee { expected_fee: Nat },
27+
// The caller does not have enough funds to pay the approval fee.
28+
InsufficientFunds { balance: Nat },
29+
// The caller specified the [expected_allowance] field, and the current
30+
// allowance did not match the given value.
31+
AllowanceChanged { current_allowance: Nat },
32+
// The approval request expired before the ledger had a chance to apply it.
33+
Expired { ledger_time: u64 },
34+
TooOld,
35+
CreatedInFuture { ledger_time: u64 },
36+
Duplicate { duplicate_of: Nat },
37+
TemporarilyUnavailable,
38+
GenericError { error_code: Nat, message: String },
39+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod allowance;
2+
pub mod approve;
3+
pub mod transfer_from;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use candid::{CandidType, Deserialize, Nat};
2+
3+
use super::super::icrc1::account::{Account, Subaccount};
4+
use super::super::icrc1::transfer::Memo;
5+
6+
#[derive(CandidType, Deserialize, Clone, Debug, PartialEq, Eq)]
7+
pub struct TransferFromArgs {
8+
#[serde(default)]
9+
pub spender_subaccount: Option<Subaccount>,
10+
pub from: Account,
11+
pub to: Account,
12+
pub amount: Nat,
13+
#[serde(default)]
14+
pub fee: Option<Nat>,
15+
#[serde(default)]
16+
pub memo: Option<Memo>,
17+
#[serde(default)]
18+
pub created_at_time: Option<u64>,
19+
}
20+
21+
#[derive(CandidType, Deserialize, Clone, Debug, PartialEq, Eq)]
22+
pub enum TransferFromError {
23+
BadFee { expected_fee: Nat },
24+
BadBurn { min_burn_amount: Nat },
25+
// The [from] account does not hold enough funds for the transfer.
26+
InsufficientFunds { balance: Nat },
27+
// The caller exceeded its allowance.
28+
InsufficientAllowance { allowance: Nat },
29+
TooOld,
30+
CreatedInFuture { ledger_time: u64 },
31+
Duplicate { duplicate_of: Nat },
32+
TemporarilyUnavailable,
33+
GenericError { error_code: Nat, message: String },
34+
}

packages/icrc-ledger-types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod icrc;
22
pub mod icrc1;
3+
pub mod icrc2;
34
pub mod icrc3;

0 commit comments

Comments
 (0)