Skip to content

Commit

Permalink
implement requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pandres95 committed Jan 16, 2024
1 parent f5f1878 commit 0bdaf95
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
25 changes: 22 additions & 3 deletions substrate/frame/assets/src/impl_sufficiency.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Assets pallet's `StoredMap` implementation.

use crate::{
traits::sufficiency::{Inspect, Mutate},
traits::sufficiency::{IsSufficient, SetSufficiency},
Asset, Config, Pallet,
};

impl<T: Config<I>, I: 'static> Inspect<<T as Config<I>>::AssetId> for Pallet<T, I> {
impl<T: Config<I>, I: 'static> IsSufficient<<T as Config<I>>::AssetId> for Pallet<T, I> {
fn is_sufficient(asset_id: <T as Config<I>>::AssetId) -> bool {
Asset::<T, I>::get(asset_id).map(|asset| asset.is_sufficient).unwrap_or(false)
}
}

impl<T: Config<I>, I: 'static> Mutate<<T as Config<I>>::AssetId> for Pallet<T, I> {
impl<T: Config<I>, I: 'static> SetSufficiency<<T as Config<I>>::AssetId> for Pallet<T, I> {
fn make_sufficient(asset_id: <T as Config<I>>::AssetId) -> sp_runtime::DispatchResult {
Pallet::<T, I>::do_set_sufficiency(asset_id, true)
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn basic_minting_should_work() {

#[test]
fn insufficient_assets_can_turn_into_sufficient() {
use sufficiency::{Inspect, Mutate};
use sufficiency::{IsSufficient, SetSufficiency};

new_test_ext().execute_with(|| {
assert_ok!(Assets::force_create(RuntimeOrigin::root(), 0, 1, false, 1));
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/assets/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ pub mod sufficiency {
use sp_runtime::DispatchResult;

/// Trait for providing the sufficiency of an asset.
pub trait Inspect<AssetId> {
pub trait IsSufficient<AssetId> {
/// Returns whether an asset is sufficient or not.
fn is_sufficient(asset_id: AssetId) -> bool;
}

/// Trait for mutating the sufficiency of an asset
pub trait Mutate<AssetId> {
pub trait SetSufficiency<AssetId> {
/// Makes the asset sufficient.
fn make_sufficient(asset_id: AssetId) -> DispatchResult;

Expand Down

0 comments on commit 0bdaf95

Please sign in to comment.