Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Simple Trait to Inspect Metadata #9893

Merged
2 commits merged into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ impl<T: Config<I>, I: 'static> fungibles::Inspect<<T as SystemConfig>::AccountId
}
}

impl<T: Config<I>, I: 'static> fungibles::InspectMetadata<<T as SystemConfig>::AccountId>
for Pallet<T, I>
{
/// Return the name of an asset.
fn name(asset: &Self::AssetId) -> Vec<u8> {
Metadata::<T, I>::get(asset).name.to_vec()
}

/// Return the symbol of an asset.
fn symbol(asset: &Self::AssetId) -> Vec<u8> {
Metadata::<T, I>::get(asset).symbol.to_vec()
}

/// Return the decimals of an asset.
fn decimals(asset: &Self::AssetId) -> u8 {
Metadata::<T, I>::get(asset).decimals
}
}

impl<T: Config<I>, I: 'static> fungibles::Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> {
fn mint_into(
asset: Self::AssetId,
Expand Down
13 changes: 13 additions & 0 deletions frame/support/src/traits/tokens/fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use super::{
};
use crate::dispatch::{DispatchError, DispatchResult};
use sp_runtime::traits::Saturating;
use sp_std::vec::Vec;

mod balanced;
pub use balanced::{Balanced, Unbalanced};
Expand Down Expand Up @@ -65,6 +66,18 @@ pub trait Inspect<AccountId> {
) -> WithdrawConsequence<Self::Balance>;
}

/// Trait for reading metadata from a fungible asset.
pub trait InspectMetadata<AccountId>: Inspect<AccountId> {
/// Return the name of an asset.
fn name(asset: &Self::AssetId) -> Vec<u8>;

/// Return the symbol of an asset.
fn symbol(asset: &Self::AssetId) -> Vec<u8>;

/// Return the decimals of an asset.
fn decimals(asset: &Self::AssetId) -> u8;
}

/// Trait for providing a set of named fungible assets which can be created and destroyed.
pub trait Mutate<AccountId>: Inspect<AccountId> {
/// Attempt to increase the `asset` balance of `who` by `amount`.
Expand Down