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

Commit

Permalink
Simple Trait to Inspect Metadata (#9893)
Browse files Browse the repository at this point in the history
* simple trait to inspect metadata

* import vec
  • Loading branch information
shawntabrizi authored Sep 30, 2021
1 parent 3302199 commit bf9683e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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

0 comments on commit bf9683e

Please sign in to comment.