From d294badf99046c439c88eef7ff28bf42fbf96c60 Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 9 Sep 2024 17:13:38 +0200 Subject: [PATCH] ++ --- src/example/paid_service/src/lib.rs | 16 ++++++---------- src/example/paid_service/tests/it/icrc2.rs | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/example/paid_service/src/lib.rs b/src/example/paid_service/src/lib.rs index 7fdf866..82ca9c3 100644 --- a/src/example/paid_service/src/lib.rs +++ b/src/example/paid_service/src/lib.rs @@ -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] @@ -31,16 +33,10 @@ async fn cost_1000_attached_cycles() -> Result { /// 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 { - 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!(); diff --git a/src/example/paid_service/tests/it/icrc2.rs b/src/example/paid_service/tests/it/icrc2.rs index 54688e9..bb67ec2 100644 --- a/src/example/paid_service/tests/it/icrc2.rs +++ b/src/example/paid_service/tests/it/icrc2.rs @@ -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 );