From 2a51319169438aa9e4d5566ea5a0b2a929b33513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Duarte?= Date: Wed, 3 Jul 2024 14:26:16 +0100 Subject: [PATCH] fix(market-pallets): use lock_funds --- pallets/market/src/lib.rs | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/pallets/market/src/lib.rs b/pallets/market/src/lib.rs index 25b617904..fce1531ef 100644 --- a/pallets/market/src/lib.rs +++ b/pallets/market/src/lib.rs @@ -683,19 +683,8 @@ pub mod pallet { .try_into() .map_err(|_| Error::::UnexpectedValidationError)?; - BalanceTable::::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::(&deal.client, client_fee)?; deal.state = DealState::Published; let deal_id = Self::generate_deal_id(); @@ -710,17 +699,7 @@ pub mod pallet { // Lock up funds for the Storage Provider // PRE-COND: always succeeds, validated by `validate_deals` - BalanceTable::::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::(&provider, total_provider_lockup)?; Ok(()) }