diff --git a/zrml/asset-router/src/lib.rs b/zrml/asset-router/src/lib.rs index bb9051aeb..efe40d23f 100644 --- a/zrml/asset-router/src/lib.rs +++ b/zrml/asset-router/src/lib.rs @@ -185,8 +185,7 @@ pub mod pallet { /// Keeps track of assets that have to be destroyed. #[pallet::storage] - pub(super) type DestroyAssets = - StorageValue<_, BoundedVec, ConstU32<8192>>, ValueQuery>; + pub(super) type DestroyAssets = StorageValue<_, DestroyAssetsT, ValueQuery>; /// Keeps track of assets that can't be destroyed. #[pallet::storage] diff --git a/zrml/asset-router/src/pallet_impl/managed_destroy.rs b/zrml/asset-router/src/pallet_impl/managed_destroy.rs index 357961171..98bb81ee8 100644 --- a/zrml/asset-router/src/pallet_impl/managed_destroy.rs +++ b/zrml/asset-router/src/pallet_impl/managed_destroy.rs @@ -17,13 +17,13 @@ use crate::pallet::*; -impl ManagedDestroy for Pallet { - fn managed_destroy( - asset: Self::AssetId, +impl Pallet { + fn add_asset_to_managed_destruction( + destroy_assets: &mut DestroyAssetsT, + asset: T::AssetType, maybe_check_owner: Option, ) -> DispatchResult { Self::asset_exists(asset).then_some(()).ok_or(Error::::UnknownAsset)?; - let mut destroy_assets = DestroyAssets::::get(); frame_support::ensure!(!destroy_assets.is_full(), Error::::TooManyManagedDestroys); let asset_to_insert = AssetInDestruction::new(asset); @@ -43,8 +43,18 @@ impl ManagedDestroy for Pallet { .map_err(|_| Error::::TooManyManagedDestroys)?; Self::start_destroy(asset, maybe_check_owner)?; - DestroyAssets::::put(destroy_assets); + Ok(()) + } +} +impl ManagedDestroy for Pallet { + fn managed_destroy( + asset: Self::AssetId, + maybe_check_owner: Option, + ) -> DispatchResult { + let mut destroy_assets = DestroyAssets::::get(); + Self::add_asset_to_managed_destruction(&mut destroy_assets, asset, maybe_check_owner)?; + DestroyAssets::::put(destroy_assets); Ok(()) } @@ -55,26 +65,7 @@ impl ManagedDestroy for Pallet { let mut destroy_assets = DestroyAssets::::get(); for (asset, maybe_check_owner) in assets { - Self::asset_exists(asset).then_some(()).ok_or(Error::::UnknownAsset)?; - frame_support::ensure!(!destroy_assets.is_full(), Error::::TooManyManagedDestroys); - let asset_to_insert = AssetInDestruction::new(asset); - - let idx = match destroy_assets.binary_search(&asset_to_insert) { - Ok(_) => return Err(Error::::DestructionInProgress.into()), - Err(idx) => { - if IndestructibleAssets::::get().binary_search(&asset).is_ok() { - return Err(Error::::DestructionInProgress.into()); - } - - idx - } - }; - - destroy_assets - .try_insert(idx, asset_to_insert) - .map_err(|_| Error::::TooManyManagedDestroys)?; - - Self::start_destroy(asset, maybe_check_owner)?; + Self::add_asset_to_managed_destruction(&mut destroy_assets, asset, maybe_check_owner)?; } DestroyAssets::::put(destroy_assets); diff --git a/zrml/asset-router/src/types.rs b/zrml/asset-router/src/types.rs index 8425a9c20..8f3acc2cc 100644 --- a/zrml/asset-router/src/types.rs +++ b/zrml/asset-router/src/types.rs @@ -15,10 +15,14 @@ // You should have received a copy of the GNU General Public License // along with Zeitgeist. If not, see . +use crate::{BoundedVec, Config, ConstU32}; use core::cmp::Ordering; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; +pub(crate) type DestroyAssetsT = + BoundedVec::AssetType>, ConstU32<8192>>; + #[derive(Clone, Copy, Debug, Eq, PartialEq, Decode, Encode, MaxEncodedLen, TypeInfo)] pub(crate) enum DestructionState { Accounts,