-
Notifications
You must be signed in to change notification settings - Fork 9
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
spike foreign fungibles v2 #474
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,12 @@ | |
//! goal is to provide a simplified, consistent API that adheres to standards in the smart contract | ||
//! space. | ||
|
||
use frame_support::traits::fungibles::{metadata::Inspect as MetadataInspect, Inspect}; | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use frame_support::{ | ||
__private::RuntimeDebug, | ||
pallet_prelude::TypeInfo, | ||
traits::fungibles::{metadata::Inspect as MetadataInspect, Inspect}, | ||
}; | ||
pub use pallet::*; | ||
use pallet_assets::WeightInfo as AssetsWeightInfoTrait; | ||
use weights::WeightInfo; | ||
|
@@ -13,16 +18,49 @@ | |
mod tests; | ||
pub mod weights; | ||
|
||
type AccountIdOf<T> = <T as frame_system::Config>::AccountId; | ||
type TokenIdOf<T> = <AssetsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::AssetId; | ||
type TokenIdParameterOf<T> = <T as pallet_assets::Config<AssetsInstanceOf<T>>>::AssetIdParameter; | ||
type AssetsOf<T> = pallet_assets::Pallet<T, AssetsInstanceOf<T>>; | ||
type AssetsErrorOf<T> = pallet_assets::Error<T, AssetsInstanceOf<T>>; | ||
type AssetsInstanceOf<T> = <T as Config>::AssetsInstance; | ||
type AssetsWeightInfoOf<T> = <T as pallet_assets::Config<AssetsInstanceOf<T>>>::WeightInfo; | ||
type BalanceOf<T> = <AssetsOf<T> as Inspect<<T as frame_system::Config>::AccountId>>::Balance; | ||
type TrustBackedTokenIdParameterOf<T> = | ||
<T as pallet_assets::Config<TrustBackedAssetsInstanceOf<T>>>::AssetIdParameter; | ||
type ForeignTokenIdParameterOf<T> = | ||
<T as pallet_assets::Config<ForeignAssetsInstanceOf<T>>>::AssetIdParameter; | ||
|
||
type TrustBackedAssetsOf<T> = pallet_assets::Pallet<T, TrustBackedAssetsInstanceOf<T>>; | ||
type ForeignAssetsOf<T> = pallet_assets::Pallet<T, ForeignAssetsInstanceOf<T>>; | ||
|
||
type TrustBackedAssetsErrorOf<T> = pallet_assets::Error<T, TrustBackedAssetsInstanceOf<T>>; | ||
type ForeignAssetsErrorOf<T> = pallet_assets::Error<T, ForeignAssetsInstanceOf<T>>; | ||
|
||
type TrustBackedAssetsInstanceOf<T> = <T as Config>::TrustBackedAssetsInstance; | ||
type ForeignAssetsInstanceOf<T> = <T as Config>::ForeignAssetsInstance; | ||
|
||
type TrustBackedAssetsWeightInfoOf<T> = | ||
<T as pallet_assets::Config<TrustBackedAssetsInstanceOf<T>>>::WeightInfo; | ||
type ForeignAssetsWeightInfoOf<T> = | ||
<T as pallet_assets::Config<ForeignAssetsInstanceOf<T>>>::WeightInfo; | ||
type WeightOf<T> = <T as Config>::WeightInfo; | ||
|
||
// Our unified asset identifier type. The variant determines which asset instance to call. | ||
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] | ||
pub enum MultiAssetId<TrustId, ForeignId> { | ||
TrustBacked(TrustId), | ||
Foreign(ForeignId), | ||
} | ||
|
||
/// Renamed to TokenIdOf for minimal changes. | ||
/// It wraps the asset ID from: | ||
/// - the trust‑backed instance (using `TrustBackedAssetsInstanceOf<T>`), and | ||
/// - the foreign instance (using `ForeignAssetsInstanceOf<T>`). | ||
type TokenIdOf<T> = MultiAssetId< | ||
<pallet_assets::Pallet<T, TrustBackedAssetsInstanceOf<T>> as Inspect< | ||
<T as frame_system::Config>::AccountId, | ||
>>::AssetId, | ||
<pallet_assets::Pallet<T, ForeignAssetsInstanceOf<T>> as Inspect< | ||
<T as frame_system::Config>::AccountId, | ||
>>::AssetId, | ||
>; | ||
|
||
type AccountIdOf<T> = <T as frame_system::Config>::AccountId; | ||
type BalanceOf<T> = <T as Config>::Balance; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use core::cmp::Ordering::*; | ||
|
@@ -42,13 +80,44 @@ | |
use super::*; | ||
|
||
/// Configure the pallet by specifying the parameters and types on which it depends. | ||
/// | ||
/// It now requires two asset instances: | ||
/// - `TrustBackedAssetsInstance`: used for trust‑backed assets (formerly the sole instance), | ||
/// - `ForeignAssetsInstance`: used for foreign assets. | ||
#[pallet::config] | ||
pub trait Config: frame_system::Config + pallet_assets::Config<Self::AssetsInstance> { | ||
pub trait Config: | ||
frame_system::Config | ||
+ pallet_assets::Config<Self::TrustBackedAssetsInstance> | ||
+ pallet_assets::Config<Self::ForeignAssetsInstance> | ||
{ | ||
/// Because this pallet emits events, it depends on the runtime's definition of an event. | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
/// The instance of pallet-assets. | ||
type AssetsInstance; | ||
/// Weight information for dispatchables in this pallet. | ||
/// The asset instance for trust‑backed assets (renamed from the old AssetsInstance). | ||
type TrustBackedAssetsInstance; | ||
/// The asset instance for foreign assets. | ||
type ForeignAssetsInstance; | ||
type Balance: Parameter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complex Balance type unfortunately |
||
+ MaybeSerializeDeserialize | ||
+ Default | ||
+ Copy | ||
+ Into< | ||
<pallet_assets::Pallet<Self, Self::TrustBackedAssetsInstance> as Inspect< | ||
<Self as frame_system::Config>::AccountId, | ||
>>::Balance, | ||
> + From< | ||
<pallet_assets::Pallet<Self, Self::TrustBackedAssetsInstance> as Inspect< | ||
<Self as frame_system::Config>::AccountId, | ||
>>::Balance, | ||
> + Into< | ||
<pallet_assets::Pallet<Self, Self::ForeignAssetsInstance> as Inspect< | ||
<Self as frame_system::Config>::AccountId, | ||
>>::Balance, | ||
> + From< | ||
<pallet_assets::Pallet<Self, Self::ForeignAssetsInstance> as Inspect< | ||
<Self as frame_system::Config>::AccountId, | ||
>>::Balance, | ||
>; | ||
/// Weight information for dispatchable functions in this pallet. | ||
type WeightInfo: WeightInfo; | ||
} | ||
|
||
|
@@ -94,6 +163,14 @@ | |
}, | ||
} | ||
|
||
// A helper function to compute the weight parameter based on the token variant. | ||
fn weight_param<T: Config>(token: &TokenIdOf<T>) -> u32 { | ||
match token { | ||
MultiAssetId::TrustBacked(_) => 0, | ||
MultiAssetId::Foreign(_) => 1, | ||
} | ||
} | ||
|
||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
/// Transfers `value` amount of tokens from the caller's account to account `to`. | ||
|
@@ -103,20 +180,38 @@ | |
/// - `to` - The recipient account. | ||
/// - `value` - The number of tokens to transfer. | ||
#[pallet::call_index(3)] | ||
#[pallet::weight(AssetsWeightInfoOf::<T>::transfer_keep_alive())] | ||
#[pallet::weight( | ||
if weight_param::<T> (& token) == 0 { | ||
TrustBackedAssetsWeightInfoOf::<T>::transfer_keep_alive() | ||
} else { | ||
ForeignAssetsWeightInfoOf::<T>::transfer_keep_alive() | ||
} | ||
)] | ||
pub fn transfer( | ||
origin: OriginFor<T>, | ||
token: TokenIdOf<T>, | ||
to: AccountIdOf<T>, | ||
value: BalanceOf<T>, | ||
) -> DispatchResult { | ||
let from = ensure_signed(origin.clone())?; | ||
AssetsOf::<T>::transfer_keep_alive( | ||
origin, | ||
token.clone().into(), | ||
T::Lookup::unlookup(to.clone()), | ||
value, | ||
)?; | ||
match token.clone() { | ||
MultiAssetId::TrustBacked(id) => { | ||
TrustBackedAssetsOf::<T>::transfer_keep_alive( | ||
origin, | ||
id.into(), | ||
T::Lookup::unlookup(to.clone()), | ||
value.into(), | ||
)?; | ||
}, | ||
MultiAssetId::Foreign(id) => { | ||
ForeignAssetsOf::<T>::transfer_keep_alive( | ||
origin, | ||
id.into(), | ||
T::Lookup::unlookup(to.clone()), | ||
value.into(), | ||
)?; | ||
}, | ||
} | ||
Self::deposit_event(Event::Transfer { token, from: Some(from), to: Some(to), value }); | ||
Ok(()) | ||
} | ||
|
@@ -130,7 +225,7 @@ | |
/// - `to` - The recipient account. | ||
/// - `value` - The number of tokens to transfer. | ||
#[pallet::call_index(4)] | ||
#[pallet::weight(AssetsWeightInfoOf::<T>::transfer_approved())] | ||
Check failure on line 228 in pallets/api/src/fungibles/mod.rs
|
||
pub fn transfer_from( | ||
origin: OriginFor<T>, | ||
token: TokenIdOf<T>, | ||
|
@@ -138,7 +233,7 @@ | |
to: AccountIdOf<T>, | ||
value: BalanceOf<T>, | ||
) -> DispatchResult { | ||
AssetsOf::<T>::transfer_approved( | ||
Check failure on line 236 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
token.clone().into(), | ||
T::Lookup::unlookup(from.clone()), | ||
|
@@ -165,19 +260,19 @@ | |
) -> DispatchResultWithPostInfo { | ||
let owner = ensure_signed(origin.clone()) | ||
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 0)))?; | ||
let current_allowance = AssetsOf::<T>::allowance(token.clone(), &owner, &spender); | ||
Check failure on line 263 in pallets/api/src/fungibles/mod.rs
|
||
|
||
let weight = match value.cmp(¤t_allowance) { | ||
Check failure on line 265 in pallets/api/src/fungibles/mod.rs
|
||
// If the new value is equal to the current allowance, do nothing. | ||
Equal => WeightOf::<T>::approve(0, 0), | ||
// If the new value is greater than the current allowance, approve the difference | ||
// because `approve_transfer` works additively (see `pallet-assets`). | ||
Greater => { | ||
AssetsOf::<T>::approve_transfer( | ||
Check failure on line 271 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
token.clone().into(), | ||
T::Lookup::unlookup(spender.clone()), | ||
value.saturating_sub(current_allowance), | ||
Check failure on line 275 in pallets/api/src/fungibles/mod.rs
|
||
) | ||
.map_err(|e| e.with_weight(WeightOf::<T>::approve(1, 0)))?; | ||
WeightOf::<T>::approve(1, 0) | ||
|
@@ -185,18 +280,18 @@ | |
// If the new value is less than the current allowance, cancel the approval and | ||
// set the new value. | ||
Less => { | ||
let token_param: TokenIdParameterOf<T> = token.clone().into(); | ||
Check failure on line 283 in pallets/api/src/fungibles/mod.rs
|
||
let spender_source = T::Lookup::unlookup(spender.clone()); | ||
AssetsOf::<T>::cancel_approval( | ||
Check failure on line 285 in pallets/api/src/fungibles/mod.rs
|
||
origin.clone(), | ||
token_param.clone(), | ||
spender_source.clone(), | ||
) | ||
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 1)))?; | ||
if value.is_zero() { | ||
Check failure on line 291 in pallets/api/src/fungibles/mod.rs
|
||
WeightOf::<T>::approve(0, 1) | ||
} else { | ||
AssetsOf::<T>::approve_transfer( | ||
Check failure on line 294 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
token_param, | ||
spender_source, | ||
|
@@ -226,14 +321,14 @@ | |
) -> DispatchResultWithPostInfo { | ||
let owner = ensure_signed(origin.clone()) | ||
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 0)))?; | ||
AssetsOf::<T>::approve_transfer( | ||
Check failure on line 324 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
token.clone().into(), | ||
T::Lookup::unlookup(spender.clone()), | ||
value, | ||
) | ||
.map_err(|e| e.with_weight(AssetsWeightInfoOf::<T>::approve_transfer()))?; | ||
Check failure on line 330 in pallets/api/src/fungibles/mod.rs
|
||
let value = AssetsOf::<T>::allowance(token.clone(), &owner, &spender); | ||
Check failure on line 331 in pallets/api/src/fungibles/mod.rs
|
||
Self::deposit_event(Event::Approval { token, owner, spender, value }); | ||
Ok(().into()) | ||
} | ||
|
@@ -254,17 +349,17 @@ | |
) -> DispatchResultWithPostInfo { | ||
let owner = ensure_signed(origin.clone()) | ||
.map_err(|e| e.with_weight(WeightOf::<T>::approve(0, 0)))?; | ||
if value.is_zero() { | ||
Check failure on line 352 in pallets/api/src/fungibles/mod.rs
|
||
return Ok(Some(WeightOf::<T>::approve(0, 0)).into()); | ||
} | ||
let current_allowance = AssetsOf::<T>::allowance(token.clone(), &owner, &spender); | ||
Check failure on line 355 in pallets/api/src/fungibles/mod.rs
|
||
let spender_source = T::Lookup::unlookup(spender.clone()); | ||
let token_param: TokenIdParameterOf<T> = token.clone().into(); | ||
Check failure on line 357 in pallets/api/src/fungibles/mod.rs
|
||
|
||
// Cancel the approval and approve `new_allowance` if difference is more than zero. | ||
let new_allowance = | ||
current_allowance.checked_sub(&value).ok_or(AssetsErrorOf::<T>::Unapproved)?; | ||
Check failure on line 361 in pallets/api/src/fungibles/mod.rs
|
||
AssetsOf::<T>::cancel_approval( | ||
Check failure on line 362 in pallets/api/src/fungibles/mod.rs
|
||
origin.clone(), | ||
token_param.clone(), | ||
spender_source.clone(), | ||
|
@@ -273,7 +368,7 @@ | |
let weight = if new_allowance.is_zero() { | ||
WeightOf::<T>::approve(0, 1) | ||
} else { | ||
AssetsOf::<T>::approve_transfer( | ||
Check failure on line 371 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
token_param, | ||
spender_source, | ||
|
@@ -292,7 +387,7 @@ | |
/// - `admin` - The account that will administer the token. | ||
/// - `min_balance` - The minimum balance required for accounts holding this token. | ||
#[pallet::call_index(11)] | ||
#[pallet::weight(AssetsWeightInfoOf::<T>::create())] | ||
Check failure on line 390 in pallets/api/src/fungibles/mod.rs
|
||
pub fn create( | ||
origin: OriginFor<T>, | ||
id: TokenIdOf<T>, | ||
|
@@ -300,7 +395,7 @@ | |
min_balance: BalanceOf<T>, | ||
) -> DispatchResult { | ||
let creator = ensure_signed(origin.clone())?; | ||
AssetsOf::<T>::create( | ||
Check failure on line 398 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
id.clone().into(), | ||
T::Lookup::unlookup(admin.clone()), | ||
|
@@ -319,9 +414,9 @@ | |
// - `destroy_approvals` | ||
// - `finish_destroy` | ||
#[pallet::call_index(12)] | ||
#[pallet::weight(AssetsWeightInfoOf::<T>::start_destroy())] | ||
Check failure on line 417 in pallets/api/src/fungibles/mod.rs
|
||
pub fn start_destroy(origin: OriginFor<T>, token: TokenIdOf<T>) -> DispatchResult { | ||
AssetsOf::<T>::start_destroy(origin, token.into()) | ||
Check failure on line 419 in pallets/api/src/fungibles/mod.rs
|
||
} | ||
|
||
/// Set the metadata for a token. | ||
|
@@ -332,7 +427,7 @@ | |
/// - `symbol`: The exchange symbol for this token. | ||
/// - `decimals`: The number of decimals this token uses to represent one unit. | ||
#[pallet::call_index(16)] | ||
#[pallet::weight(AssetsWeightInfoOf::<T>::set_metadata(name.len() as u32, symbol.len() as u32))] | ||
Check failure on line 430 in pallets/api/src/fungibles/mod.rs
|
||
pub fn set_metadata( | ||
origin: OriginFor<T>, | ||
token: TokenIdOf<T>, | ||
|
@@ -340,7 +435,7 @@ | |
symbol: Vec<u8>, | ||
decimals: u8, | ||
) -> DispatchResult { | ||
AssetsOf::<T>::set_metadata(origin, token.into(), name, symbol, decimals) | ||
Check failure on line 438 in pallets/api/src/fungibles/mod.rs
|
||
} | ||
|
||
/// Clear the metadata for a token. | ||
|
@@ -348,9 +443,9 @@ | |
/// # Parameters | ||
/// - `token` - The token to update. | ||
#[pallet::call_index(17)] | ||
#[pallet::weight(AssetsWeightInfoOf::<T>::clear_metadata())] | ||
Check failure on line 446 in pallets/api/src/fungibles/mod.rs
|
||
pub fn clear_metadata(origin: OriginFor<T>, token: TokenIdOf<T>) -> DispatchResult { | ||
AssetsOf::<T>::clear_metadata(origin, token.into()) | ||
Check failure on line 448 in pallets/api/src/fungibles/mod.rs
|
||
} | ||
|
||
/// Creates `value` amount of tokens and assigns them to `account`, increasing the total | ||
|
@@ -361,14 +456,14 @@ | |
/// - `account` - The account to be credited with the created tokens. | ||
/// - `value` - The number of tokens to mint. | ||
#[pallet::call_index(19)] | ||
#[pallet::weight(AssetsWeightInfoOf::<T>::mint())] | ||
Check failure on line 459 in pallets/api/src/fungibles/mod.rs
|
||
pub fn mint( | ||
origin: OriginFor<T>, | ||
token: TokenIdOf<T>, | ||
account: AccountIdOf<T>, | ||
value: BalanceOf<T>, | ||
) -> DispatchResult { | ||
AssetsOf::<T>::mint( | ||
Check failure on line 466 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
token.clone().into(), | ||
T::Lookup::unlookup(account.clone()), | ||
|
@@ -385,19 +480,19 @@ | |
/// - `account` - The account from which the tokens will be destroyed. | ||
/// - `value` - The number of tokens to destroy. | ||
#[pallet::call_index(20)] | ||
#[pallet::weight(<T as Config>::WeightInfo::balance_of() + AssetsWeightInfoOf::<T>::burn())] | ||
Check failure on line 483 in pallets/api/src/fungibles/mod.rs
|
||
pub fn burn( | ||
origin: OriginFor<T>, | ||
token: TokenIdOf<T>, | ||
account: AccountIdOf<T>, | ||
value: BalanceOf<T>, | ||
) -> DispatchResultWithPostInfo { | ||
let current_balance = AssetsOf::<T>::balance(token.clone(), &account); | ||
Check failure on line 490 in pallets/api/src/fungibles/mod.rs
|
||
if current_balance < value { | ||
return Err(AssetsErrorOf::<T>::BalanceLow | ||
Check failure on line 492 in pallets/api/src/fungibles/mod.rs
|
||
.with_weight(<T as Config>::WeightInfo::balance_of())); | ||
} | ||
AssetsOf::<T>::burn( | ||
Check failure on line 495 in pallets/api/src/fungibles/mod.rs
|
||
origin, | ||
token.clone().into(), | ||
T::Lookup::unlookup(account.clone()), | ||
|
@@ -499,7 +594,7 @@ | |
fn weight(request: &Self::Read) -> Weight { | ||
use Read::*; | ||
match request { | ||
TotalSupply(_) => <T as Config>::WeightInfo::total_supply(), | ||
TotalSupply(id) => <T as Config>::WeightInfo::total_supply(weight_param(id)), | ||
Check failure on line 597 in pallets/api/src/fungibles/mod.rs
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hasn't been tested but applied to show how the weight can be handled for the read functions. |
||
BalanceOf { .. } => <T as Config>::WeightInfo::balance_of(), | ||
Allowance { .. } => <T as Config>::WeightInfo::allowance(), | ||
TokenName(_) => <T as Config>::WeightInfo::token_name(), | ||
|
@@ -516,23 +611,110 @@ | |
fn read(request: Self::Read) -> Self::Result { | ||
use Read::*; | ||
match request { | ||
TotalSupply(token) => ReadResult::TotalSupply(AssetsOf::<T>::total_supply(token)), | ||
BalanceOf { token, owner } => | ||
ReadResult::BalanceOf(AssetsOf::<T>::balance(token, owner)), | ||
Allowance { token, owner, spender } => | ||
ReadResult::Allowance(AssetsOf::<T>::allowance(token, &owner, &spender)), | ||
TokenName(token) => ReadResult::TokenName( | ||
Some(<AssetsOf<T> as MetadataInspect<AccountIdOf<T>>>::name(token)) | ||
TotalSupply(token) => { | ||
let total = match token { | ||
MultiAssetId::TrustBacked(id) => | ||
TrustBackedAssetsOf::<T>::total_supply(id).into(), | ||
MultiAssetId::Foreign(id) => ForeignAssetsOf::<T>::total_supply(id).into(), | ||
}; | ||
ReadResult::TotalSupply(total) | ||
}, | ||
BalanceOf { token, owner } => { | ||
let bal = match token { | ||
MultiAssetId::TrustBacked(id) => pallet_assets::Pallet::< | ||
T, | ||
TrustBackedAssetsInstanceOf<T>, | ||
>::balance(id, &owner) | ||
.into(), | ||
MultiAssetId::Foreign(id) => pallet_assets::Pallet::< | ||
T, | ||
ForeignAssetsInstanceOf<T>, | ||
>::balance(id, &owner) | ||
.into(), | ||
}; | ||
ReadResult::BalanceOf(bal) | ||
}, | ||
Allowance { token, owner, spender } => { | ||
let allow = match token { | ||
MultiAssetId::TrustBacked(id) => pallet_assets::Pallet::< | ||
T, | ||
TrustBackedAssetsInstanceOf<T>, | ||
>::allowance(id, &owner, &spender) | ||
.into(), | ||
MultiAssetId::Foreign(id) => pallet_assets::Pallet::< | ||
T, | ||
ForeignAssetsInstanceOf<T>, | ||
>::allowance(id, &owner, &spender) | ||
.into(), | ||
}; | ||
ReadResult::Allowance(allow) | ||
}, | ||
TokenName(token) => { | ||
let name = match token { | ||
MultiAssetId::TrustBacked(id) => Some(<pallet_assets::Pallet< | ||
T, | ||
TrustBackedAssetsInstanceOf<T>, | ||
> as MetadataInspect<AccountIdOf<T>>>::name( | ||
id | ||
)) | ||
.filter(|v| !v.is_empty()), | ||
MultiAssetId::Foreign(id) => Some(<pallet_assets::Pallet< | ||
T, | ||
ForeignAssetsInstanceOf<T>, | ||
> as MetadataInspect<AccountIdOf<T>>>::name( | ||
id | ||
)) | ||
.filter(|v| !v.is_empty()), | ||
}; | ||
ReadResult::TokenName(name) | ||
}, | ||
TokenSymbol(token) => { | ||
let symbol = match token { | ||
MultiAssetId::TrustBacked(id) => Some(<pallet_assets::Pallet< | ||
T, | ||
TrustBackedAssetsInstanceOf<T>, | ||
> as MetadataInspect<AccountIdOf<T>>>::symbol( | ||
id | ||
)) | ||
.filter(|v| !v.is_empty()), | ||
), | ||
TokenSymbol(token) => ReadResult::TokenSymbol( | ||
Some(<AssetsOf<T> as MetadataInspect<AccountIdOf<T>>>::symbol(token)) | ||
MultiAssetId::Foreign(id) => Some(<pallet_assets::Pallet< | ||
T, | ||
ForeignAssetsInstanceOf<T>, | ||
> as MetadataInspect<AccountIdOf<T>>>::symbol( | ||
id | ||
)) | ||
.filter(|v| !v.is_empty()), | ||
), | ||
TokenDecimals(token) => ReadResult::TokenDecimals( | ||
<AssetsOf<T> as MetadataInspect<AccountIdOf<T>>>::decimals(token), | ||
), | ||
TokenExists(token) => ReadResult::TokenExists(AssetsOf::<T>::asset_exists(token)), | ||
}; | ||
ReadResult::TokenSymbol(symbol) | ||
}, | ||
TokenDecimals(token) => { | ||
let decimals = match token { | ||
MultiAssetId::TrustBacked(id) => <pallet_assets::Pallet< | ||
T, | ||
TrustBackedAssetsInstanceOf<T>, | ||
> as MetadataInspect<AccountIdOf<T>>>::decimals( | ||
id | ||
), | ||
MultiAssetId::Foreign(id) => <pallet_assets::Pallet< | ||
T, | ||
ForeignAssetsInstanceOf<T>, | ||
> as MetadataInspect<AccountIdOf<T>>>::decimals( | ||
id | ||
), | ||
}; | ||
ReadResult::TokenDecimals(decimals) | ||
}, | ||
TokenExists(token) => { | ||
let exists = match token { | ||
MultiAssetId::TrustBacked(id) => pallet_assets::Pallet::< | ||
T, | ||
TrustBackedAssetsInstanceOf<T>, | ||
>::asset_exists(id), | ||
MultiAssetId::Foreign(id) => | ||
pallet_assets::Pallet::<T, ForeignAssetsInstanceOf<T>>::asset_exists(id), | ||
}; | ||
ReadResult::TokenExists(exists) | ||
}, | ||
} | ||
} | ||
} | ||
|
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.
Not tested but I was thinking to implement it this way if we went this route.