substrate icon indicating copy to clipboard operation
substrate copied to clipboard

[pallet-assets] add asset_exists(id: AssetId) function

Open bernardoaraujor opened this issue 3 years ago • 5 comments

Is there an existing issue?

  • [X] I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • [X] This is not a support question.

Description of bug

While working on an implementation of an Asset Registry for https://github.com/paritytech/trappist/issues/51, we needed to check whether an Asset exists.

We are currently doing the following, which feels a bit like a hack:

fn asset_exists(asset_id: AssetIdOf<T>) -> bool {
			!T::Assets::minimum_balance(asset_id).is_zero()
}

Ideally, pallet-assets should provide a function that does this, because it is basic functionality that is missing from the pallet.

Steps to reproduce

No response

bernardoaraujor avatar Oct 07 '22 13:10 bernardoaraujor

@bernardoaraujor who should ideally have the privilege of calling this function/extrinsic?

Doordashcon avatar Oct 10 '22 05:10 Doordashcon

Can you explain the context in which you are unable to do this?

For example, within FRAME, you can just use Asset::<T, I>::contains_key(id) (example).

Asset is also a pub storage item, so any UI or tool using a library like Polkadot JS API should be able to read this and check if some key exists.

joepetrowski avatar Oct 10 '22 06:10 joepetrowski

This is coming from a pallet that has a loose-coupling with pallet-assets (via Inspect trait).

Correct me if I'm wrong, but as far as I could tell, I could only read Asset if I used tight coupling.

bernardoaraujor avatar Oct 10 '22 12:10 bernardoaraujor

I see, so you are looking for either a pub fn asset_class_exists(id) -> bool; function within Inspect, or

impl<T: Config<I>, I: 'static> Pallet<T, I> {
    pub fn asset_class_exists(id: T::AssetId) -> bool { }
}

within the Assets pallet? Seems like a good issue for @vieira-giulia to figure out. Also posting https://substrate.stackexchange.com/questions/922/pallet-loose-couplingtight-coupling-and-missing-traits for reference.

joepetrowski avatar Oct 12 '22 06:10 joepetrowski

yes... as long as it's accessible via loose coupling, it should be enough.

bernardoaraujor avatar Oct 12 '22 11:10 bernardoaraujor

I have gone ahead to open a PR for this @joepetrowski @bernardoaraujor since it has not been worked on for over a month

dharjeezy avatar Nov 26 '22 10:11 dharjeezy

This issue has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/polkadot-release-analysis-v0-9-36/1529/1

Polkadot-Forum avatar Dec 22 '22 09:12 Polkadot-Forum