diff --git a/substrate/frame/assets/src/functions.rs b/substrate/frame/assets/src/functions.rs index 8791aaa736b35..648c6bf71fc5b 100644 --- a/substrate/frame/assets/src/functions.rs +++ b/substrate/frame/assets/src/functions.rs @@ -998,6 +998,18 @@ impl, I: 'static> Pallet { }) } + /// Do set sufficiency + pub(super) fn do_set_sufficiency(asset_id: T::AssetId, is_sufficient: bool) -> DispatchResult { + Asset::::try_mutate(asset_id, |maybe_asset| { + if let Some(asset) = maybe_asset { + asset.is_sufficient = is_sufficient; + Ok(()) + } else { + Err(Error::::Unknown)? + } + }) + } + /// Calculate the metadata deposit for the provided data. pub(super) fn calc_metadata_deposit(name: &[u8], symbol: &[u8]) -> DepositBalanceOf { T::MetadataDepositPerByte::get() diff --git a/substrate/frame/assets/src/impl_sufficients.rs b/substrate/frame/assets/src/impl_sufficients.rs index 14086fdbe677f..77a3d0981d844 100644 --- a/substrate/frame/assets/src/impl_sufficients.rs +++ b/substrate/frame/assets/src/impl_sufficients.rs @@ -10,17 +10,11 @@ impl, I: 'static> Inspect<>::AssetId> for Pallet, I: 'static> Mutate<>::AssetId> for Pallet { - fn set_sufficient( - asset_id: >::AssetId, - is_sufficient: bool, - ) -> sp_runtime::DispatchResult { - Asset::::try_mutate(asset_id, |maybe_asset| { - if let Some(asset) = maybe_asset { - asset.is_sufficient = is_sufficient; - Ok(()) - } else { - Err(Error::::Unknown)? - } - }) + fn make_sufficient(asset_id: >::AssetId) -> sp_runtime::DispatchResult { + Pallet::::do_set_sufficiency(asset_id, true) + } + + fn make_insufficient(asset_id: >::AssetId) -> sp_runtime::DispatchResult { + Pallet::::do_set_sufficiency(asset_id, false) } } diff --git a/substrate/frame/assets/src/tests.rs b/substrate/frame/assets/src/tests.rs index 6624e9e939ed2..da09b8def1105 100644 --- a/substrate/frame/assets/src/tests.rs +++ b/substrate/frame/assets/src/tests.rs @@ -107,7 +107,7 @@ fn insufficient_assets_can_turn_into_sufficient() { new_test_ext().execute_with(|| { assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, false, 1)); assert_eq!(Assets::is_sufficient(0), false); - assert_ok!(Assets::set_sufficient(0, true)); + assert_ok!(Assets::make_sufficient(0)); assert_eq!(Assets::is_sufficient(0), true); }); } diff --git a/substrate/frame/assets/src/traits.rs b/substrate/frame/assets/src/traits.rs index 0eca7d3ede4f1..56e58eb4387f8 100644 --- a/substrate/frame/assets/src/traits.rs +++ b/substrate/frame/assets/src/traits.rs @@ -3,17 +3,24 @@ pub mod sufficients { /// Trait for providing the sufficient state of an asset. pub trait Inspect { - /// Returns whether an asset is sufficient or not + /// Returns whether an asset is sufficient or not. fn is_sufficient(asset_id: AssetId) -> bool; } /// Trait for mutating the sufficient state of an asset pub trait Mutate { - /// Sets the `is_sufficient` value of an asset. + /// Makes the asset to be sufficient. /// /// ### Errors /// /// - [`Unknown`][crate::Error::Unknown] when the asset ID is unknown. - fn set_sufficient(asset_id: AssetId, is_sufficient: bool) -> DispatchResult; + fn make_sufficient(asset_id: AssetId) -> DispatchResult; + + /// Makes the asset to be insufficient. + /// + /// ### Errors + /// + /// - [`Unknown`][crate::Error::Unknown] when the asset ID is unknown. + fn make_insufficient(asset_id: AssetId) -> DispatchResult; } }