-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pallet-assets): define and implement sufficients traits for pallet-assets
#2872
Closed
pandres95
wants to merge
6
commits into
paritytech:master
from
pandres95:pandres95--assets-traits-sufficients
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
278cc1a
feat(pallet-assets): define and implement sufficients traits for `pal…
pandres95 b38e9a3
change(pallet-assets): improve sufficiency traits and enhance documen…
pandres95 141c011
change(pallet-assets): sufficients -> sufficiency
pandres95 d3386ff
change(pallet-assets): improve documentation
pandres95 392837e
change(pallet-assets): adjust tests to include make_insufficient
pandres95 34ef3a7
implement requested changes
pandres95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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::{ | ||
pandres95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
traits::sufficiency::{IsSufficient, SetSufficiency}, | ||
Asset, Config, Pallet, | ||
}; | ||
|
||
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> 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) | ||
} | ||
|
||
fn make_insufficient(asset_id: <T as Config<I>>::AssetId) -> sp_runtime::DispatchResult { | ||
Pallet::<T, I>::do_set_sufficiency(asset_id, false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub mod sufficiency { | ||
use sp_runtime::DispatchResult; | ||
|
||
/// Trait for providing the sufficiency of an asset. | ||
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 SetSufficiency<AssetId> { | ||
/// Makes the asset sufficient. | ||
fn make_sufficient(asset_id: AssetId) -> DispatchResult; | ||
|
||
/// Makes the asset insufficient. | ||
fn make_insufficient(asset_id: AssetId) -> DispatchResult; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
traits
andimpls
? otherwise the list of files will grow here pretty quick.I also have only strong opinion on keeping our folders/files/modules style consistent, since there is no yet agreement on it, I would just try to keep it close to what we have now, and now we tend to have less files than many.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this mean also moving
impl_fungibles
andimpl_stored_map
onto animpls
file/folder? I see the point on making the file structure lighter, but seeing that other impls are not that light (i.e.impl_fungibles
is 311 lines) a bit of not-flatness might be good for the sake of readibility from time to time.My suggestion: