Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
bitdivine committed Sep 9, 2024
1 parent b1247e9 commit d294bad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions src/example/paid_service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use example_paid_service_api::InitArgs;
use ic_cdk::init;
use ic_cdk_macros::{export_candid, update};
use ic_papi_api::{Account, PaymentError};
use ic_papi_guard::guards::attached_cycles::AttachedCyclesPayment;
use ic_papi_guard::guards::icrc2_from_caller::Icrc2FromCaller;
use ic_papi_guard::guards::PaymentGuard;
use ic_papi_guard::guards::{
attached_cycles::AttachedCyclesPayment, icrc2_cycles::Icrc2CyclesPaymentGuard,
};
use state::{own_canister_id, payment_ledger, set_init_args};

#[init]
Expand All @@ -31,16 +33,10 @@ async fn cost_1000_attached_cycles() -> Result<String, PaymentError> {
/// An API method that requires 1 billion cycles using an ICRC-2 approve with default parameters.
#[update()]
async fn cost_1b_icrc2_from_caller() -> Result<String, PaymentError> {
let guard = Icrc2FromCaller {
own_canister_id: own_canister_id(),
payer: Account {
owner: ic_cdk::caller(),
subaccount: None,
},
ledger_canister_id: payment_ledger(),
};
let mut guard = Icrc2CyclesPaymentGuard::new(own_canister_id());
guard.ledger_canister_id = payment_ledger();
guard.deduct(1_000_000_000).await?;
Ok("Yes, you paid 1000 cycles!".to_string())
Ok("Yes, you paid 1 billion cycles!".to_string())
}

export_candid!();
2 changes: 1 addition & 1 deletion src/example/paid_service/tests/it/icrc2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn icrc2_payment_works() {
} else {
assert_eq!(
response,
Ok("Yes, you paid 1000 cycles!".to_string()),
Ok("Yes, you paid 1 billion cycles!".to_string()),
"Should have succeeded with {} cycles attached",
payment
);
Expand Down

0 comments on commit d294bad

Please sign in to comment.