Skip to content

Commit

Permalink
refactor(cycles ledger client): Add ic prefix to cycles ledger client (
Browse files Browse the repository at this point in the history
…#43)

# Motivation
The cycles ledger client should have the `ic-` prefix.

# Changes
- Add the `ic-` prefix.

# Tests
Existing tests should suffice.
  • Loading branch information
bitdivine authored Oct 14, 2024
1 parent 43c42fa commit 5b2f3ea
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 38 deletions.
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ic-papi-api = { path = "src/api" }
ic-papi-guard = { path = "src/guard" }
ic-stable-structures = "0.6.5"
ic-ledger-types = "0.13.0"
cycles-ledger-client = { path = "src/declarations/cycles_ledger" }
ic-cycles-ledger-client = { path = "src/declarations/cycles_ledger" }
example-paid-service-api = { path = "src/example/paid_service_api" }
lazy_static = { version = "1.5.0" }
hex = { version = "0.4.3" }
Expand Down
2 changes: 1 addition & 1 deletion src/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2021"

[dependencies]
candid = { workspace = true }
cycles-ledger-client = { workspace = true }
hex = { workspace = true }
ic-cycles-ledger-client = { workspace = true }
ic-ledger-types = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
2 changes: 1 addition & 1 deletion src/api/src/caller.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Types used primarily by the caller of the payment API.
use candid::{CandidType, Deserialize, Principal};
pub use cycles_ledger_client::Account;
pub use ic_cycles_ledger_client::Account;

/// How a caller states that they will pay.
#[derive(Debug, CandidType, Deserialize, Clone, Eq, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions src/api/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Payment API error types.
use candid::{CandidType, Deserialize, Principal};
pub use cycles_ledger_client::Account;
use cycles_ledger_client::{TransferFromError, WithdrawFromError};
pub use ic_cycles_ledger_client::Account;
use ic_cycles_ledger_client::{TransferFromError, WithdrawFromError};

use crate::caller::TokenAmount;

Expand Down
2 changes: 1 addition & 1 deletion src/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use candid::Principal;
pub use cycles_ledger_client::Account;
pub use ic_cycles_ledger_client::Account;
use ic_ledger_types::Subaccount;
use serde_bytes::ByteBuf;

Expand Down
2 changes: 1 addition & 1 deletion src/api/src/vendor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Types used primartily by the vendor of the payment API.
use candid::{CandidType, Deserialize, Principal};
pub use cycles_ledger_client::Account;
pub use ic_cycles_ledger_client::Account;

use crate::caller::TokenAmount;

Expand Down
2 changes: 1 addition & 1 deletion src/declarations/cycles_ledger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cycles-ledger-client"
name = "ic-cycles-ledger-client"
version = "0.1.0"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion src/example/paid_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ serde = { workspace = true }
serde_bytes = { workspace = true }

[dev-dependencies]
cycles-ledger-client = { workspace = true }
ic-cycles-ledger-client = { workspace = true }
pocket-ic = { workspace = true }
6 changes: 3 additions & 3 deletions src/example/paid_service/tests/it/caller_pays_icrc2_cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn caller_pays_icrc2_cycles_works_with_large_enough_approval() {
response,
Err(PaymentError::LedgerWithdrawFromError {
ledger: setup.ledger.canister_id(),
error: cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
error: ic_cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
allowance: Nat::from(payment + LEDGER_FEE),
}
}),
Expand Down Expand Up @@ -218,7 +218,7 @@ fn caller_needs_to_approve() {
response,
Err(PaymentError::LedgerWithdrawFromError {
ledger: setup.ledger.canister_id(),
error: cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
error: ic_cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
allowance: Nat::default(),
}
}),
Expand Down Expand Up @@ -253,7 +253,7 @@ fn payment_cannot_be_used_by_another_caller() {
response,
Err(PaymentError::LedgerWithdrawFromError {
ledger: setup.ledger.canister_id(),
error: cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
error: ic_cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
allowance: Nat::default(),
}
}),
Expand Down
6 changes: 3 additions & 3 deletions src/example/paid_service/tests/it/patron_pays_icrc2_cycles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn user_pays_tokens_for_user2() {
response,
Err(PaymentError::LedgerWithdrawFromError {
ledger: setup.ledger.canister_id(),
error: cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
error: ic_cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
allowance: Nat::from(0u32),
}
}),
Expand Down Expand Up @@ -150,7 +150,7 @@ fn user_pays_cycles_for_other_users() {
response,
Err(PaymentError::LedgerWithdrawFromError {
ledger: setup.ledger.canister_id(),
error: cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
error: ic_cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
allowance: Nat::from(0u32),
}
}),
Expand Down Expand Up @@ -204,7 +204,7 @@ fn user_pays_cycles_for_other_users() {
response,
Err(PaymentError::LedgerWithdrawFromError {
ledger: setup.ledger.canister_id(),
error: cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
error: ic_cycles_ledger_client::WithdrawFromError::InsufficientAllowance {
allowance: Nat::from(0u32),
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn user_pays_tokens_for_user2() {
response,
Err(PaymentError::LedgerTransferFromError {
ledger: setup.ledger.canister_id(),
error: cycles_ledger_client::TransferFromError::InsufficientAllowance {
error: ic_cycles_ledger_client::TransferFromError::InsufficientAllowance {
allowance: Nat::from(0u32),
}
}),
Expand Down
2 changes: 1 addition & 1 deletion src/guard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2021"

[dependencies]
candid = { workspace = true }
cycles-ledger-client = { workspace = true }
ic-cdk = "0.16.0"
ic-cycles-ledger-client = { workspace = true }
ic-papi-api = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
4 changes: 2 additions & 2 deletions src/guard/src/guards/caller_pays_icrc2_cycles.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code to receive cycles as payment, credited to the canister, using ICRC-2 and a cycles-ledger specific withdrawal method.
use super::{PaymentError, PaymentGuardTrait};
use candid::Nat;
use cycles_ledger_client::WithdrawFromArgs;
use ic_cycles_ledger_client::WithdrawFromArgs;
use ic_papi_api::{caller::TokenAmount, cycles::cycles_ledger_canister_id, Account};

/// Accepts cycles using an ICRC-2 approve followed by withdrawing the cycles to the current canister. Withdrawing
Expand All @@ -23,7 +23,7 @@ impl PaymentGuardTrait for CallerPaysIcrc2CyclesPaymentGuard {
}
// The cycles ledger has a special `withdraw_from` method, similar to `transfer_from`,
// but that adds the cycles to the canister rather than putting it into a ledger account.
cycles_ledger_client::Service(cycles_ledger_canister_id())
ic_cycles_ledger_client::Service(cycles_ledger_canister_id())
.withdraw_from(&WithdrawFromArgs {
to: own_canister_id,
amount: Nat::from(fee),
Expand Down
4 changes: 2 additions & 2 deletions src/guard/src/guards/caller_pays_icrc2_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use super::{PaymentError, PaymentGuardTrait};
use candid::{Nat, Principal};
use cycles_ledger_client::TransferFromArgs;
use ic_cycles_ledger_client::TransferFromArgs;
use ic_papi_api::{caller::TokenAmount, Account};

pub struct CallerPaysIcrc2TokensPaymentGuard {
Expand All @@ -16,7 +16,7 @@ pub struct CallerPaysIcrc2TokensPaymentGuard {
impl PaymentGuardTrait for CallerPaysIcrc2TokensPaymentGuard {
async fn deduct(&self, cost: TokenAmount) -> Result<(), PaymentError> {
let caller = ic_cdk::api::caller();
cycles_ledger_client::Service(self.ledger)
ic_cycles_ledger_client::Service(self.ledger)
.icrc_2_transfer_from(&TransferFromArgs {
from: Account {
owner: caller,
Expand Down
4 changes: 2 additions & 2 deletions src/guard/src/guards/patron_pays_icrc2_cycles.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code to receive cycles as payment, credited to the canister, using ICRC-2 and a cycles-ledger specific withdrawal method.
use super::{PaymentError, PaymentGuardTrait};
use candid::Nat;
use cycles_ledger_client::WithdrawFromArgs;
use ic_cycles_ledger_client::WithdrawFromArgs;
use ic_papi_api::{
caller::TokenAmount, cycles::cycles_ledger_canister_id, principal2account, Account,
};
Expand All @@ -24,7 +24,7 @@ impl PaymentGuardTrait for PatronPaysIcrc2CyclesPaymentGuard {
}
// The cycles ledger has a special `withdraw_from` method, similar to `transfer_from`,
// but that adds the cycles to the canister rather than putting it into a ledger account.
cycles_ledger_client::Service(cycles_ledger_canister_id())
ic_cycles_ledger_client::Service(cycles_ledger_canister_id())
.withdraw_from(&WithdrawFromArgs {
to: own_canister_id,
amount: Nat::from(fee),
Expand Down
4 changes: 2 additions & 2 deletions src/guard/src/guards/patron_pays_icrc2_tokens.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Code to receive cycles as payment, credited to the canister, using ICRC-2 and a cycles-ledger specific withdrawal method.
use super::{PaymentError, PaymentGuardTrait};
use candid::{Nat, Principal};
use cycles_ledger_client::TransferFromArgs;
use ic_cycles_ledger_client::TransferFromArgs;
use ic_papi_api::{caller::TokenAmount, principal2account, Account};

/// Accepts cycles using an ICRC-2 approve followed by withdrawing the cycles to the current canister. Withdrawing
Expand All @@ -23,7 +23,7 @@ impl PaymentGuardTrait for PatronPaysIcrc2TokensPaymentGuard {
return Err(PaymentError::InvalidPatron);
}
// Note: The cycles ledger client is ICRC-2 compatible so can be used here.
cycles_ledger_client::Service(self.ledger)
ic_cycles_ledger_client::Service(self.ledger)
.icrc_2_transfer_from(&TransferFromArgs {
from: self.patron.clone(),
to: Account {
Expand Down

0 comments on commit 5b2f3ea

Please sign in to comment.