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 9519f63 commit a4e0a53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -18,6 +19,7 @@ pub enum PaymentError {
},
}

#[derive(Debug, CandidType, Deserialize, Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum PaymentType {
AttachedCycles,
Expand Down
3 changes: 2 additions & 1 deletion src/example/paid_service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ async fn cost_1b(payment: PaymentType) -> Result<String, PaymentError> {
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())
}
Expand Down

0 comments on commit a4e0a53

Please sign in to comment.