Skip to content

Commit ac13956

Browse files
committed
change(pallet-assets): improve sufficiency traits and enhance documentation
1 parent b1e3ae1 commit ac13956

4 files changed

Lines changed: 29 additions & 16 deletions

File tree

substrate/frame/assets/src/functions.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,18 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
998998
})
999999
}
10001000

1001+
/// Do set sufficiency
1002+
pub(super) fn do_set_sufficiency(asset_id: T::AssetId, is_sufficient: bool) -> DispatchResult {
1003+
Asset::<T, I>::try_mutate(asset_id, |maybe_asset| {
1004+
if let Some(asset) = maybe_asset {
1005+
asset.is_sufficient = is_sufficient;
1006+
Ok(())
1007+
} else {
1008+
Err(Error::<T, I>::Unknown)?
1009+
}
1010+
})
1011+
}
1012+
10011013
/// Calculate the metadata deposit for the provided data.
10021014
pub(super) fn calc_metadata_deposit(name: &[u8], symbol: &[u8]) -> DepositBalanceOf<T, I> {
10031015
T::MetadataDepositPerByte::get()

substrate/frame/assets/src/impl_sufficients.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ impl<T: Config<I>, I: 'static> Inspect<<T as Config<I>>::AssetId> for Pallet<T,
1010
}
1111

1212
impl<T: Config<I>, I: 'static> Mutate<<T as Config<I>>::AssetId> for Pallet<T, I> {
13-
fn set_sufficient(
14-
asset_id: <T as Config<I>>::AssetId,
15-
is_sufficient: bool,
16-
) -> sp_runtime::DispatchResult {
17-
Asset::<T, I>::try_mutate(asset_id, |maybe_asset| {
18-
if let Some(asset) = maybe_asset {
19-
asset.is_sufficient = is_sufficient;
20-
Ok(())
21-
} else {
22-
Err(Error::<T, I>::Unknown)?
23-
}
24-
})
13+
fn make_sufficient(asset_id: <T as Config<I>>::AssetId) -> sp_runtime::DispatchResult {
14+
Pallet::<T, I>::do_set_sufficiency(asset_id, true)
15+
}
16+
17+
fn make_insufficient(asset_id: <T as Config<I>>::AssetId) -> sp_runtime::DispatchResult {
18+
Pallet::<T, I>::do_set_sufficiency(asset_id, false)
2519
}
2620
}

substrate/frame/assets/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn insufficient_assets_can_turn_into_sufficient() {
107107
new_test_ext().execute_with(|| {
108108
assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, false, 1));
109109
assert_eq!(Assets::is_sufficient(0), false);
110-
assert_ok!(Assets::set_sufficient(0, true));
110+
assert_ok!(Assets::make_sufficient(0));
111111
assert_eq!(Assets::is_sufficient(0), true);
112112
});
113113
}

substrate/frame/assets/src/traits.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ pub mod sufficients {
33

44
/// Trait for providing the sufficient state of an asset.
55
pub trait Inspect<AssetId> {
6-
/// Returns whether an asset is sufficient or not
6+
/// Returns whether an asset is sufficient or not.
77
fn is_sufficient(asset_id: AssetId) -> bool;
88
}
99

1010
/// Trait for mutating the sufficient state of an asset
1111
pub trait Mutate<AssetId> {
12-
/// Sets the `is_sufficient` value of an asset.
12+
/// Makes the asset to be sufficient.
1313
///
1414
/// ### Errors
1515
///
1616
/// - [`Unknown`][crate::Error::Unknown] when the asset ID is unknown.
17-
fn set_sufficient(asset_id: AssetId, is_sufficient: bool) -> DispatchResult;
17+
fn make_sufficient(asset_id: AssetId) -> DispatchResult;
18+
19+
/// Makes the asset to be insufficient.
20+
///
21+
/// ### Errors
22+
///
23+
/// - [`Unknown`][crate::Error::Unknown] when the asset ID is unknown.
24+
fn make_insufficient(asset_id: AssetId) -> DispatchResult;
1825
}
1926
}

0 commit comments

Comments
 (0)