Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
bitdivine committed Sep 17, 2024
1 parent d8f207d commit e06f69d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/example/paid_service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,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 mut guard = Icrc2CyclesPaymentGuard::default();
guard.ledger_canister_id = payment_ledger();
let guard = Icrc2CyclesPaymentGuard {
ledger_canister_id: payment_ledger(),
..Icrc2CyclesPaymentGuard::default()
};
guard.deduct(1_000_000_000).await?;
Ok("Yes, you paid 1 billion cycles!".to_string())
}
Expand All @@ -47,15 +49,22 @@ async fn cost_1b(payment: PaymentType) -> Result<String, PaymentError> {
AttachedCyclesPayment::default().deduct(fee).await?;
}
PaymentType::CallerIcrc2Cycles => {
let mut guard = Icrc2CyclesPaymentGuard::default();
guard.ledger_canister_id = payment_ledger();
let guard = Icrc2CyclesPaymentGuard {
ledger_canister_id: payment_ledger(),
..Icrc2CyclesPaymentGuard::default()
};
guard.deduct(fee).await?;
}
PaymentType::PatronIcrc2Cycles(patron) => {
let mut guard = Icrc2CyclesPaymentGuard::default();
guard.ledger_canister_id = payment_ledger();
guard.payer_account.owner = patron;
guard.spender_subaccount = Some(principal2account(&ic_cdk::caller()));
let guard = Icrc2CyclesPaymentGuard {
ledger_canister_id: payment_ledger(),
payer_account: ic_papi_api::Account {
owner: patron,
subaccount: None,
},
spender_subaccount: Some(principal2account(&ic_cdk::caller())),
..Icrc2CyclesPaymentGuard::default()
};
guard.deduct(fee).await?;
}
_ => return Err(PaymentError::UnsupportedPaymentType),
Expand Down

0 comments on commit e06f69d

Please sign in to comment.