-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(guards): Separate cycle and token payment paths (#21)
# Motivation The cycle payment path withdraws cycles to the canister. This path is suitable where the purpose of the payment is to fund the canister's own running costs. This path uses `withdraw_from` which is available from the cycles ledger but is not in the ICRC-2 standard. # Changes - Separate code and tests for cycle and token payment # Tests Pocket-ic tests are included for every path.
- Loading branch information
Showing
22 changed files
with
1,201 additions
and
655 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
use candid::Principal; | ||
|
||
/// The cycles ledger canister ID on mainnet. | ||
const MAINNET_CYCLES_LEDGER_CANISTER_ID: &str = "um5iw-rqaaa-aaaaq-qaaba-cai"; | ||
|
||
/// The cycles ledger canister ID. | ||
/// | ||
/// - If a `cycles_ledger` canister is listed in `dfx.json`, the `dfx build` command will set the | ||
/// environment variable `CANISTER_ID_CYCLES_LEDGER` and we use this to obtain the canister ID. | ||
/// - Otherwise, the mainnet cycles ledger canister ID is used. | ||
const CYCLES_LEDGER_CANISTER_ID: &str = if let Some(id) = option_env!("CANISTER_ID_CYCLES_LEDGER") { | ||
id | ||
} else { | ||
MAINNET_CYCLES_LEDGER_CANISTER_ID | ||
}; | ||
/// Note: This canister ID should also be used in test environments. The dfx.json | ||
/// can implement this with: | ||
/// ``` | ||
/// { "canisters": { | ||
/// "cycles_ledger": { | ||
/// ... | ||
/// "specified_id": "um5iw-rqaaa-aaaaq-qaaba-cai", | ||
/// "remote": { | ||
/// "id": { | ||
/// "ic": "um5iw-rqaaa-aaaaq-qaaba-cai" | ||
/// } | ||
/// } | ||
/// }, | ||
/// ... | ||
/// } | ||
/// ``` | ||
pub const MAINNET_CYCLES_LEDGER_CANISTER_ID: &str = "um5iw-rqaaa-aaaaq-qaaba-cai"; | ||
|
||
/// The `CYCLES_LEDGER_CANISTER_ID` as a `Principal`. | ||
/// The `MAINNET_CYCLES_LEDGER_CANISTER_ID` as a `Principal`. | ||
/// | ||
/// # Panics | ||
/// - If the `CYCLES_LEDGER_CANISTER_ID` is not a valid `Principal`. | ||
/// - If the `MAINNET_CYCLES_LEDGER_CANISTER_ID` is not a valid `Principal`. | ||
#[must_use] | ||
pub fn cycles_ledger_canister_id() -> Principal { | ||
Principal::from_text(CYCLES_LEDGER_CANISTER_ID) | ||
Principal::from_text(MAINNET_CYCLES_LEDGER_CANISTER_ID) | ||
.expect("Invalid cycles ledger canister ID provided at compile time.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.