From 44208f405eb1aee2b5e3c0cbea56eab846cb4353 Mon Sep 17 00:00:00 2001 From: Damilare Date: Sat, 26 Nov 2022 11:22:52 +0100 Subject: [PATCH 1/2] check if an asset exists via loose coupling --- frame/assets/src/impl_fungibles.rs | 4 ++++ frame/support/src/traits/tokens/fungibles.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/frame/assets/src/impl_fungibles.rs b/frame/assets/src/impl_fungibles.rs index 6e0a9ac08ebb1..b10b8c6b10755 100644 --- a/frame/assets/src/impl_fungibles.rs +++ b/frame/assets/src/impl_fungibles.rs @@ -59,6 +59,10 @@ impl, I: 'static> fungibles::Inspect<::AccountId ) -> WithdrawConsequence { Pallet::::can_decrease(asset, who, amount, false) } + + fn asset_exists(asset: Self::AssetId) -> bool { + Asset::::contains_key(asset) + } } impl, I: 'static> fungibles::InspectMetadata<::AccountId> diff --git a/frame/support/src/traits/tokens/fungibles.rs b/frame/support/src/traits/tokens/fungibles.rs index 8c370e9a0d8b5..92693618f600e 100644 --- a/frame/support/src/traits/tokens/fungibles.rs +++ b/frame/support/src/traits/tokens/fungibles.rs @@ -75,6 +75,9 @@ pub trait Inspect { who: &AccountId, amount: Self::Balance, ) -> WithdrawConsequence; + + /// Determines if an `asset` exists + fn asset_exists(asset: Self::AssetId) -> bool; } /// Trait for reading metadata from a fungible asset. From 8974d8f680cd8fafa82a0f24eab757ecfe03d692 Mon Sep 17 00:00:00 2001 From: dharjeezy Date: Sun, 27 Nov 2022 01:01:32 +0100 Subject: [PATCH 2/2] Update frame/support/src/traits/tokens/fungibles.rs Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- frame/support/src/traits/tokens/fungibles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/traits/tokens/fungibles.rs b/frame/support/src/traits/tokens/fungibles.rs index 92693618f600e..eb6d95547a98a 100644 --- a/frame/support/src/traits/tokens/fungibles.rs +++ b/frame/support/src/traits/tokens/fungibles.rs @@ -76,7 +76,7 @@ pub trait Inspect { amount: Self::Balance, ) -> WithdrawConsequence; - /// Determines if an `asset` exists + /// Returns `true` if an `asset` exists. fn asset_exists(asset: Self::AssetId) -> bool; }