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

Commit bf9683e

Browse files
authored
Simple Trait to Inspect Metadata (#9893)
* simple trait to inspect metadata * import vec
1 parent 3302199 commit bf9683e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

frame/assets/src/impl_fungibles.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ impl<T: Config<I>, I: 'static> fungibles::Inspect<<T as SystemConfig>::AccountId
6060
}
6161
}
6262

63+
impl<T: Config<I>, I: 'static> fungibles::InspectMetadata<<T as SystemConfig>::AccountId>
64+
for Pallet<T, I>
65+
{
66+
/// Return the name of an asset.
67+
fn name(asset: &Self::AssetId) -> Vec<u8> {
68+
Metadata::<T, I>::get(asset).name.to_vec()
69+
}
70+
71+
/// Return the symbol of an asset.
72+
fn symbol(asset: &Self::AssetId) -> Vec<u8> {
73+
Metadata::<T, I>::get(asset).symbol.to_vec()
74+
}
75+
76+
/// Return the decimals of an asset.
77+
fn decimals(asset: &Self::AssetId) -> u8 {
78+
Metadata::<T, I>::get(asset).decimals
79+
}
80+
}
81+
6382
impl<T: Config<I>, I: 'static> fungibles::Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> {
6483
fn mint_into(
6584
asset: Self::AssetId,

frame/support/src/traits/tokens/fungibles.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use super::{
2323
};
2424
use crate::dispatch::{DispatchError, DispatchResult};
2525
use sp_runtime::traits::Saturating;
26+
use sp_std::vec::Vec;
2627

2728
mod balanced;
2829
pub use balanced::{Balanced, Unbalanced};
@@ -65,6 +66,18 @@ pub trait Inspect<AccountId> {
6566
) -> WithdrawConsequence<Self::Balance>;
6667
}
6768

69+
/// Trait for reading metadata from a fungible asset.
70+
pub trait InspectMetadata<AccountId>: Inspect<AccountId> {
71+
/// Return the name of an asset.
72+
fn name(asset: &Self::AssetId) -> Vec<u8>;
73+
74+
/// Return the symbol of an asset.
75+
fn symbol(asset: &Self::AssetId) -> Vec<u8>;
76+
77+
/// Return the decimals of an asset.
78+
fn decimals(asset: &Self::AssetId) -> u8;
79+
}
80+
6881
/// Trait for providing a set of named fungible assets which can be created and destroyed.
6982
pub trait Mutate<AccountId>: Inspect<AccountId> {
7083
/// Attempt to increase the `asset` balance of `who` by `amount`.

0 commit comments

Comments
 (0)