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()) }