-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[frame-support] Add fungible metadata and lifetime traits with ItemOf support #11432
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
499f0cf
fungible metadata
muharem c98f5c4
prdoc
muharem a241019
docs
muharem f2ef490
fix docs
muharem baa3369
Merge branch 'master' into muharem-fungible-metadata
muharem 6c81137
fmt
muharem f9d9702
add lifetime module
muharem 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 hidden or 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,19 @@ | ||
| title: '[frame-support] Add fungible metadata and lifetime traits with ItemOf support' | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: |- | ||
| Adds `fungible::metadata` and `fungible::lifetime` modules mirroring the corresponding | ||
| `fungibles` APIs: | ||
|
|
||
| - **metadata**: `Inspect` and `Mutate` traits for fungible token metadata (name, symbol, | ||
| decimals). | ||
| - **lifetime**: `Create` trait for creating a new fungible asset. | ||
|
|
||
| These modules initially exist to support functionality in the `ItemOf` adapter for `fungibles`. | ||
| When a `fungibles` implementation provides the corresponding traits | ||
| (`fungibles::metadata::Inspect`, `fungibles::metadata::Mutate`, `fungibles::lifetime::Create`), | ||
| the `ItemOf` wrapper implements the fungible equivalents, allowing a single asset from a | ||
| fungibles set to be used where fungible metadata or create is expected. | ||
| crates: | ||
| - name: frame-support | ||
| bump: minor |
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
35
substrate/frame/support/src/traits/tokens/fungible/lifetime.rs
This file contains hidden or 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,35 @@ | ||
| // 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. | ||
|
|
||
| //! Traits for creating fungible assets. | ||
| //! | ||
| //! This module initially exists to support lifetime functionality in the | ||
| //! [`crate::traits::tokens::fungible::ItemOf`] adapter for [`crate::traits::tokens::fungibles`]. | ||
|
|
||
| use super::Inspect; | ||
| use sp_runtime::DispatchResult; | ||
|
|
||
| /// Trait for providing the ability to create a new fungible asset. | ||
| pub trait Create<AccountId>: Inspect<AccountId> { | ||
| /// Create a new fungible asset. | ||
| /// | ||
| /// - `admin`: The account that will be set as the admin of the asset. | ||
| /// - `is_sufficient`: If `true`, the asset is sufficient and an account can exist with a zero | ||
| /// balance. If `false`, the asset is non-sufficient and accounts must have a minimum balance. | ||
| /// - `min_balance`: The minimum balance required for non-sufficient assets. | ||
| fn create(admin: AccountId, is_sufficient: bool, min_balance: Self::Balance) -> DispatchResult; | ||
| } |
45 changes: 45 additions & 0 deletions
45
substrate/frame/support/src/traits/tokens/fungible/metadata.rs
This file contains hidden or 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,45 @@ | ||
| // 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. | ||
|
|
||
| //! Inspect and Mutate traits for fungible metadata. | ||
| //! | ||
| //! This module initially exists to support metadata functionality in the | ||
| //! [`crate::traits::tokens::fungible::ItemOf`] adapter for [`crate::traits::tokens::fungibles`]. | ||
|
|
||
| use crate::dispatch::DispatchResult; | ||
| use alloc::vec::Vec; | ||
|
|
||
| /// Trait for inspecting fungible token metadata. | ||
| pub trait Inspect<AccountId>: super::Inspect<AccountId> { | ||
| /// Returns the name of the token. | ||
| fn name() -> Vec<u8>; | ||
| /// Returns the ticker symbol of the token. | ||
| fn symbol() -> Vec<u8>; | ||
| /// Returns the number of decimals this asset uses to represent one unit. | ||
| fn decimals() -> u8; | ||
| } | ||
|
|
||
| /// Trait for mutating fungible token metadata. | ||
| pub trait Mutate<AccountId>: Inspect<AccountId> { | ||
|
muharem marked this conversation as resolved.
|
||
| /// Set the name, symbol and decimals for the token. | ||
| /// | ||
| /// - `from`: The account of the asset's owner from which the updated deposit will be reserved. | ||
| /// - `name`: The new name. | ||
| /// - `symbol`: The new ticker symbol. | ||
| /// - `decimals`: The new number of decimals this asset uses to represent one unit. | ||
| fn set(from: &AccountId, name: Vec<u8>, symbol: Vec<u8>, decimals: u8) -> DispatchResult; | ||
| } | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.