Skip to content

Commit

Permalink
use mutate
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Jan 30, 2025
1 parent 137c56b commit 4a53460
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions polkadot/runtime/parachains/src/on_demand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ where
},
PaymentType::Credits => {
// Charge the sending account the spot price in credits.
let credits = Credits::<T>::get(&sender);
ensure!(spot_price <= credits, Error::<T>::InsufficientCredits);
Credits::<T>::insert(&sender, credits.saturating_sub(spot_price));
Credits::<T>::try_mutate(&sender, |credits| -> DispatchResult {
ensure!(spot_price <= *credits, Error::<T>::InsufficientCredits);
*credits = credits.saturating_sub(spot_price);
Ok(())
})?;
},
}

Expand Down

0 comments on commit 4a53460

Please sign in to comment.