From a4e0a53d7a0bd9bfe10f444fc7a75c1a16f6dd5f Mon Sep 17 00:00:00 2001 From: Max Murphy Date: Mon, 9 Sep 2024 17:26:22 +0200 Subject: [PATCH] ++ --- src/api/src/lib.rs | 2 ++ src/example/paid_service/src/lib.rs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/api/src/lib.rs b/src/api/src/lib.rs index 5a9b2d9..1b807ec 100644 --- a/src/api/src/lib.rs +++ b/src/api/src/lib.rs @@ -5,6 +5,7 @@ use cycles_ledger_client::WithdrawFromError; #[derive(Debug, CandidType, Deserialize, Clone, Eq, PartialEq)] #[non_exhaustive] pub enum PaymentError { + UnsupportedPaymentType, LedgerUnreachable { ledger: Principal, }, @@ -18,6 +19,7 @@ pub enum PaymentError { }, } +#[derive(Debug, CandidType, Deserialize, Clone, Eq, PartialEq)] #[non_exhaustive] pub enum PaymentType { AttachedCycles, diff --git a/src/example/paid_service/src/lib.rs b/src/example/paid_service/src/lib.rs index d2041ef..d9d3424 100644 --- a/src/example/paid_service/src/lib.rs +++ b/src/example/paid_service/src/lib.rs @@ -46,11 +46,12 @@ async fn cost_1b(payment: PaymentType) -> Result { PaymentType::AttachedCycles => { AttachedCyclesPayment::default().deduct(fee).await?; } - PaymentType::Icrc2 => { + PaymentType::Icrc2Cycles(_payer) => { let mut guard = Icrc2CyclesPaymentGuard::new(own_canister_id()); guard.ledger_canister_id = payment_ledger(); guard.deduct(fee).await?; } + _ => return Err(PaymentError::UnsupportedPaymentType), }; Ok("Yes, you paid 1 billion cycles!".to_string()) }