Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions packages/icrc-ledger-types/src/icrc3/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub const TRANSACTION_BURN: &str = "burn";
pub const TRANSACTION_MINT: &str = "mint";
pub const TRANSACTION_TRANSFER: &str = "transfer";
pub const TRANSACTION_FEE_COLLECTOR: &str = "107feecol";
pub const TRANSACTION_124_PAUSE: &str = "124pause";
pub const TRANSACTION_124_UNPAUSE: &str = "124unpause";
pub const TRANSACTION_124_DEACTIVATE: &str = "124deactivate";

pub type GenericTransaction = Value;

Expand Down Expand Up @@ -73,6 +76,14 @@ pub struct FeeCollector {
pub mthd: Option<String>,
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct ManagementAction {
pub caller: Option<Principal>,
pub reason: Option<String>,
pub ts: Option<u64>,
pub mthd: Option<String>,
}

// Representation of a Transaction which supports the Icrc1 Standard functionalities
#[derive(CandidType, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct Transaction {
Expand All @@ -82,6 +93,9 @@ pub struct Transaction {
pub transfer: Option<Transfer>,
pub approve: Option<Approve>,
pub fee_collector: Option<FeeCollector>,
pub pause: Option<ManagementAction>,
pub unpause: Option<ManagementAction>,
pub deactivate: Option<ManagementAction>,
pub timestamp: u64,
}

Expand All @@ -95,6 +109,9 @@ impl Transaction {
transfer: None,
approve: None,
fee_collector: None,
pause: None,
unpause: None,
deactivate: None,
}
}

Expand All @@ -107,6 +124,9 @@ impl Transaction {
transfer: None,
approve: None,
fee_collector: None,
pause: None,
unpause: None,
deactivate: None,
}
}

Expand All @@ -119,6 +139,9 @@ impl Transaction {
transfer: Some(transfer),
approve: None,
fee_collector: None,
pause: None,
unpause: None,
deactivate: None,
}
}

Expand All @@ -131,6 +154,9 @@ impl Transaction {
transfer: None,
approve: Some(approve),
fee_collector: None,
pause: None,
unpause: None,
deactivate: None,
}
}

Expand All @@ -143,6 +169,54 @@ impl Transaction {
transfer: None,
approve: None,
fee_collector: Some(fee_collector),
pause: None,
unpause: None,
deactivate: None,
}
}

pub fn pause(pause: ManagementAction, timestamp: u64) -> Self {
Self {
kind: TRANSACTION_124_PAUSE.into(),
timestamp,
mint: None,
burn: None,
transfer: None,
approve: None,
fee_collector: None,
pause: Some(pause),
unpause: None,
deactivate: None,
}
}

pub fn unpause(unpause: ManagementAction, timestamp: u64) -> Self {
Self {
kind: TRANSACTION_124_UNPAUSE.into(),
timestamp,
mint: None,
burn: None,
transfer: None,
approve: None,
fee_collector: None,
pause: None,
unpause: Some(unpause),
deactivate: None,
}
}

pub fn deactivate(deactivate: ManagementAction, timestamp: u64) -> Self {
Self {
kind: TRANSACTION_124_DEACTIVATE.into(),
timestamp,
mint: None,
burn: None,
transfer: None,
approve: None,
fee_collector: None,
pause: None,
unpause: None,
deactivate: Some(deactivate),
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions rs/ledger_suite/icrc1/archive/archive.did
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ type Transaction = record {
mint : opt Mint;
approve : opt Approve;
fee_collector : opt FeeCollector;
pause : opt ManagementAction;
unpause : opt ManagementAction;
deactivate : opt ManagementAction;
timestamp : nat64;
transfer : opt Transfer
};
Expand All @@ -29,6 +32,13 @@ type FeeCollector = record {
mthd : opt text
};

type ManagementAction = record {
caller : opt principal;
reason : opt text;
ts : opt nat64;
mthd : opt text
};

type Burn = record {
from : Account;
memo : opt vec nat8;
Expand Down
10 changes: 10 additions & 0 deletions rs/ledger_suite/icrc1/index-ng/index-ng.did
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type Transaction = record {
mint : opt Mint;
approve : opt Approve;
fee_collector : opt FeeCollector;
pause : opt ManagementAction;
unpause : opt ManagementAction;
deactivate : opt ManagementAction;
timestamp : nat64;
transfer : opt Transfer
};
Expand All @@ -84,6 +87,13 @@ type FeeCollector = record {
mthd : opt text
};

type ManagementAction = record {
caller : opt principal;
reason : opt text;
ts : opt nat64;
mthd : opt text
};

type Approve = record {
fee : opt Tokens;
from : Account;
Expand Down
10 changes: 8 additions & 2 deletions rs/ledger_suite/icrc1/index-ng/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,10 @@ fn process_balance_changes(block_index: BlockIndex64, block: &Block<Tokens>) {
fee_collector: _,
caller: _,
mthd: _,
} => {
}
| Operation::Pause { .. }
| Operation::Unpause { .. }
| Operation::Deactivate { .. } => {
// Does not affect the balance
}
},
Expand Down Expand Up @@ -1155,7 +1158,10 @@ fn get_accounts(block: &Block<Tokens>) -> Vec<Account> {
}
}
Operation::Approve { from, .. } => vec![from],
Operation::FeeCollector { .. } => vec![],
Operation::FeeCollector { .. }
| Operation::Pause { .. }
| Operation::Unpause { .. }
| Operation::Deactivate { .. } => vec![],
}
}

Expand Down
3 changes: 3 additions & 0 deletions rs/ledger_suite/icrc1/index-ng/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,9 @@ fn test_get_account_transactions_pagination() {
approve: None,
timestamp: 0,
fee_collector: None,
pause: None,
unpause: None,
deactivate: None,
},
transaction,
);
Expand Down
10 changes: 10 additions & 0 deletions rs/ledger_suite/icrc1/ledger/ledger.did
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ type Transaction = record {
mint : opt Mint;
approve : opt Approve;
fee_collector : opt FeeCollector;
pause : opt ManagementAction;
unpause : opt ManagementAction;
deactivate : opt ManagementAction;
timestamp : Timestamp;
transfer : opt Transfer
};
Expand All @@ -236,6 +239,13 @@ type FeeCollector = record {
mthd : opt text
};

type ManagementAction = record {
caller : opt principal;
reason : opt text;
ts : opt nat64;
mthd : opt text
};

type Burn = record {
from : Account;
memo : opt blob;
Expand Down
45 changes: 44 additions & 1 deletion rs/ledger_suite/icrc1/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use icrc_ledger_types::icrc1::transfer::TransferError;
use icrc_ledger_types::icrc2::approve::ApproveError;
use icrc_ledger_types::icrc2::transfer_from::TransferFromError;
use icrc_ledger_types::icrc3::transactions::{
Approve, Burn, FeeCollector, Mint, TRANSACTION_APPROVE, TRANSACTION_BURN,
Approve, Burn, FeeCollector, ManagementAction, Mint, TRANSACTION_124_DEACTIVATE,
TRANSACTION_124_PAUSE, TRANSACTION_124_UNPAUSE, TRANSACTION_APPROVE, TRANSACTION_BURN,
TRANSACTION_FEE_COLLECTOR, TRANSACTION_MINT, TRANSACTION_TRANSFER, Transaction, Transfer,
};
use serde::Deserialize;
Expand Down Expand Up @@ -163,6 +164,9 @@ impl<Tokens: TokensType> From<Block<Tokens>> for Transaction {
transfer: None,
approve: None,
fee_collector: None,
pause: None,
unpause: None,
deactivate: None,
timestamp: b.timestamp,
};
let created_at_time = b.transaction.created_at_time;
Expand Down Expand Up @@ -248,6 +252,45 @@ impl<Tokens: TokensType> From<Block<Tokens>> for Transaction {
mthd,
});
}
Operation::Pause {
caller,
mthd,
reason,
} => {
tx.kind = TRANSACTION_124_PAUSE.to_string();
tx.pause = Some(ManagementAction {
caller,
reason,
ts: created_at_time,
mthd,
});
}
Operation::Unpause {
caller,
mthd,
reason,
} => {
tx.kind = TRANSACTION_124_UNPAUSE.to_string();
tx.unpause = Some(ManagementAction {
caller,
reason,
ts: created_at_time,
mthd,
});
}
Operation::Deactivate {
caller,
mthd,
reason,
} => {
tx.kind = TRANSACTION_124_DEACTIVATE.to_string();
tx.deactivate = Some(ManagementAction {
caller,
reason,
ts: created_at_time,
mthd,
});
}
}

tx
Expand Down
Loading
Loading