git.delta.rocks / unique-network / refs/commits / 1139244e666b

difftreelog

chore(app-promo) fix typos

PraetorP2023-05-19parent: #0564b0f.patch.diff
in: master

1 file changed

modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
288288
289 if !block_pending.is_empty() {289 if !block_pending.is_empty() {
290 block_pending.into_iter().for_each(|(staker, amount)| {290 block_pending.into_iter().for_each(|(staker, amount)| {
291 Self::get_freezed_balance(&staker).map(|b| {291 Self::get_frozen_balance(&staker).map(|b| {
292 let new_state = b.checked_sub(&amount).unwrap_or_default();292 let new_state = b.checked_sub(&amount).unwrap_or_default();
293 Self::set_freeze_unchecked(&staker, new_state);293 Self::set_freeze_unchecked(&staker, new_state);
294 });294 });
395395
396 // let pre_state: BTreeMap<T::AccountId, BalanceOf<T>> =396 // let pre_state: BTreeMap<T::AccountId, BalanceOf<T>> =
397 // Decode::decode(&mut &pre_state[..]).map_err(|_| "failed to decode pre_state")?;397 // Decode::decode(&mut &pre_state[..]).map_err(|_| "failed to decode pre_state")?;
398 // for (staker, freezed_by_promo) in pre_state.into_iter() {398 // for (staker, frozen_by_promo) in pre_state.into_iter() {
399 // let storage_freeze_state = <<T as Config>::Currency as InspectFreeze<399 // let storage_freeze_state = <<T as Config>::Currency as InspectFreeze<
400 // T::AccountId,400 // T::AccountId,
401 // >>::balance_frozen(401 // >>::balance_frozen(
402 // &<T as Config>::FreezeIdentifier::get(), staker402 // &<T as Config>::FreezeIdentifier::get(), staker
403 // );403 // );
404 // if storage_freeze_state != freezed_by_promo {404 // if storage_freeze_state != frozen_by_promo {
405 // is_ok = false;405 // is_ok = false;
406 // log::error!(406 // log::error!(
407 // "Incorrect freezed balance for {:?}. New balance: {:?}. Before runtime upgrade: locked by promo - {:?}",407 // "Incorrect frozen balance for {:?}. New balance: {:?}. Before runtime upgrade: locked by promo - {:?}",
408 // staker, storage_freeze_state, freezed_by_promo408 // staker, storage_freeze_state, frozen_by_promo
409 // );409 // );
410 // }410 // }
411411
481 // checks that we can freeze `amount` on the `staker` account.481 // checks that we can freeze `amount` on the `staker` account.
482 ensure!(482 ensure!(
483 amount483 amount
484 <= match Self::get_freezed_balance(&staker_id) {484 <= match Self::get_frozen_balance(&staker_id) {
485 Some(freezed_by_pallet) => balance485 Some(frozen_by_pallet) => balance
486 .checked_sub(&freezed_by_pallet)486 .checked_sub(&frozen_by_pallet)
487 .ok_or(ArithmeticError::Underflow)?,487 .ok_or(ArithmeticError::Underflow)?,
488 None => balance,488 None => balance,
489 },489 },
836 stakers.into_iter().try_for_each(|s| -> Result<_, DispatchError> {836 stakers.into_iter().try_for_each(|s| -> Result<_, DispatchError> {
837 if let Some(lock) = Self::get_locked_balance(&s) {837 if let Some(lock) = Self::get_locked_balance(&s) {
838 838
839 if let Some(_) = Self::get_freezed_balance(&s) {839 if let Some(_) = Self::get_frozen_balance(&s) {
840 return Err(Error::<T>::InconsistencyState.into())840 return Err(Error::<T>::InconsistencyState.into())
841 }841 }
842 842
972 // .ok_or(ArithmeticError::Overflow.into())972 // .ok_or(ArithmeticError::Overflow.into())
973 // }973 // }
974974
975 /// Adds the balance to freezed by the pallet.975 /// Adds the balance to frozen by the pallet.
976 ///976 ///
977 /// - `staker`: staker account.977 /// - `staker`: staker account.
978 /// - `amount`: amount of added freezed funds.978 /// - `amount`: amount of added frozen funds.
979 fn add_freeze_balance(staker: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {979 fn add_freeze_balance(staker: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
980 Self::get_freezed_balance(staker)980 Self::get_frozen_balance(staker)
981 .unwrap_or_default()981 .unwrap_or_default()
982 .checked_add(&amount)982 .checked_add(&amount)
983 .map(|freeze| Self::set_freeze_unchecked(staker, freeze))983 .map(|freeze| Self::set_freeze_unchecked(staker, freeze))
1004 // }1004 // }
1005 // }1005 // }
10061006
1007 /// Sets the new state of a balance freezed by the pallet.1007 /// Sets the new state of a balance frozen by the pallet.
1008 ///1008 ///
1009 /// - `staker`: staker account.1009 /// - `staker`: staker account.
1010 /// - `amount`: amount of freezed funds.1010 /// - `amount`: amount of frozen funds.
1011 fn set_freeze_unchecked(staker: &T::AccountId, amount: BalanceOf<T>) {1011 fn set_freeze_unchecked(staker: &T::AccountId, amount: BalanceOf<T>) {
1012 if amount.is_zero() {1012 if amount.is_zero() {
1013 <<T as Config>::Currency as MutateFreeze<T::AccountId>>::thaw(1013 <<T as Config>::Currency as MutateFreeze<T::AccountId>>::thaw(
1034 .find(|l| l.id == LOCK_IDENTIFIER)1034 .find(|l| l.id == LOCK_IDENTIFIER)
1035 }1035 }
10361036
1037 /// Returns the balance freezed by the pallet for the staker.1037 /// Returns the balance frozen by the pallet for the staker.
1038 ///1038 ///
1039 /// - `staker`: staker account.1039 /// - `staker`: staker account.
1040 pub fn get_freezed_balance(staker: &T::AccountId) -> Option<BalanceOf<T>> {1040 pub fn get_frozen_balance(staker: &T::AccountId) -> Option<BalanceOf<T>> {
1041 let res = <<T as Config>::Currency as InspectFreeze<T::AccountId>>::balance_frozen(1041 let res = <<T as Config>::Currency as InspectFreeze<T::AccountId>>::balance_frozen(
1042 &T::FreezeIdentifier::get(),1042 &T::FreezeIdentifier::get(),
1043 staker,1043 staker,