Skip to content

Commit

Permalink
fix(market-pallets): use lock_funds
Browse files Browse the repository at this point in the history
  • Loading branch information
jmg-duarte committed Jul 3, 2024
1 parent f9ff954 commit 2a51319
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,19 +683,8 @@ pub mod pallet {
.try_into()
.map_err(|_| Error::<T>::UnexpectedValidationError)?;

BalanceTable::<T>::try_mutate(&deal.client, |balance| -> DispatchResult {
// PRE-COND: always succeeds, validated by `validate_deals`
balance.free = balance
.free
.checked_sub(&client_fee)
.ok_or(ArithmeticError::Underflow)?;
balance.locked = balance
.locked
.checked_add(&client_fee)
.ok_or(ArithmeticError::Overflow)?;

Ok(())
})?;
// PRE-COND: always succeeds, validated by `validate_deals`
lock_funds::<T>(&deal.client, client_fee)?;

deal.state = DealState::Published;
let deal_id = Self::generate_deal_id();
Expand All @@ -710,17 +699,7 @@ pub mod pallet {

// Lock up funds for the Storage Provider
// PRE-COND: always succeeds, validated by `validate_deals`
BalanceTable::<T>::try_mutate(&provider, |balance| -> DispatchResult {
balance.free = balance
.free
.checked_sub(&total_provider_lockup)
.ok_or(ArithmeticError::Underflow)?;
balance.locked = balance
.locked
.checked_add(&total_provider_lockup)
.ok_or(ArithmeticError::Overflow)?;
Ok(())
})?;
lock_funds::<T>(&provider, total_provider_lockup)?;

Ok(())
}
Expand Down

0 comments on commit 2a51319

Please sign in to comment.