Add Freeze/Thaw events and tests (#13779)

* Add Freeze/Thaw events and tests

* Remove duplicate docstring

* Correct spelling error

* Cargo fmt

* Use proper punctuation in docstring

Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>

---------

Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
Co-authored-by: parity-processbot <>
This commit is contained in:
Harald Heckmann
2023-04-21 12:06:26 +02:00
committed by GitHub
parent bc1a599284
commit 4411e8cec2
2 changed files with 61 additions and 0 deletions
+15
View File
@@ -337,6 +337,10 @@ pub mod pallet {
Locked { who: T::AccountId, amount: T::Balance },
/// Some balance was unlocked.
Unlocked { who: T::AccountId, amount: T::Balance },
/// Some balance was frozen.
Frozen { who: T::AccountId, amount: T::Balance },
/// Some balance was thawed.
Thawed { who: T::AccountId, amount: T::Balance },
}
#[pallet::error]
@@ -1084,7 +1088,10 @@ pub mod pallet {
who: &T::AccountId,
freezes: BoundedSlice<IdAmount<T::FreezeIdentifier, T::Balance>, T::MaxFreezes>,
) -> DispatchResult {
let mut prev_frozen = Zero::zero();
let mut after_frozen = Zero::zero();
let (_, maybe_dust) = Self::mutate_account(who, |b| {
prev_frozen = b.frozen;
b.frozen = Zero::zero();
for l in Locks::<T, I>::get(who).iter() {
b.frozen = b.frozen.max(l.amount);
@@ -1092,6 +1099,7 @@ pub mod pallet {
for l in freezes.iter() {
b.frozen = b.frozen.max(l.amount);
}
after_frozen = b.frozen;
})?;
debug_assert!(maybe_dust.is_none(), "Not altering main balance; qed");
if freezes.is_empty() {
@@ -1099,6 +1107,13 @@ pub mod pallet {
} else {
Freezes::<T, I>::insert(who, freezes);
}
if prev_frozen > after_frozen {
let amount = prev_frozen.saturating_sub(after_frozen);
Self::deposit_event(Event::Thawed { who: who.clone(), amount });
} else if after_frozen > prev_frozen {
let amount = after_frozen.saturating_sub(prev_frozen);
Self::deposit_event(Event::Frozen { who: who.clone(), amount });
}
Ok(())
}