mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
Pallets: Assets destroy_accounts releases the deposit (#14443)
* assset accounts destroy releases the deposit * enumerate * Update frame/assets/src/functions.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * import defensive from frame_support --------- Co-authored-by: Gavin Wood <gavin@parity.io> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
//! Functions for the Assets pallet.
|
||||
|
||||
use super::*;
|
||||
use frame_support::{traits::Get, BoundedVec};
|
||||
use frame_support::{defensive, traits::Get, BoundedVec};
|
||||
|
||||
#[must_use]
|
||||
pub(super) enum DeadConsequence {
|
||||
@@ -760,11 +760,22 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
let mut details = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
|
||||
// Should only destroy accounts while the asset is in a destroying state
|
||||
ensure!(details.status == AssetStatus::Destroying, Error::<T, I>::IncorrectStatus);
|
||||
|
||||
for (who, v) in Account::<T, I>::drain_prefix(&id) {
|
||||
let _ = Self::dead_account(&who, &mut details, &v.reason, true);
|
||||
dead_accounts.push(who);
|
||||
if dead_accounts.len() >= (max_items as usize) {
|
||||
for (i, (who, mut v)) in Account::<T, I>::iter_prefix(&id).enumerate() {
|
||||
// unreserve the existence deposit if any
|
||||
if let Some((depositor, deposit)) = v.reason.take_deposit_from() {
|
||||
T::Currency::unreserve(&depositor, deposit);
|
||||
} else if let Some(deposit) = v.reason.take_deposit() {
|
||||
T::Currency::unreserve(&who, deposit);
|
||||
}
|
||||
if let Remove = Self::dead_account(&who, &mut details, &v.reason, false) {
|
||||
Account::<T, I>::remove(&id, &who);
|
||||
dead_accounts.push(who);
|
||||
} else {
|
||||
// deposit may have been released, need to update `Account`
|
||||
Account::<T, I>::insert(&id, &who, v);
|
||||
defensive!("destroy did not result in dead account?!");
|
||||
}
|
||||
if i + 1 >= (max_items as usize) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user