From 4abb6025e37f397c5c0c1c45f4d0bf27ff8d5d86 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 22 Jun 2023 19:07:23 +0700 Subject: [PATCH] inspect role for nonfungibles_v2 (#14341) * inspect role * Update frame/nfts/src/impl_nonfungibles.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> * Update frame/support/src/traits/tokens/nonfungibles_v2.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> * Update as suggested * Update frame/nfts/src/impl_nonfungibles.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> * Update frame/nfts/src/impl_nonfungibles.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> * Update frame/nfts/src/impl_nonfungibles.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> --------- Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> --- substrate/frame/nfts/src/impl_nonfungibles.rs | 12 ++++++++++++ .../support/src/traits/tokens/nonfungibles_v2.rs | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/substrate/frame/nfts/src/impl_nonfungibles.rs b/substrate/frame/nfts/src/impl_nonfungibles.rs index a2bb49a947..b9e3951422 100644 --- a/substrate/frame/nfts/src/impl_nonfungibles.rs +++ b/substrate/frame/nfts/src/impl_nonfungibles.rs @@ -135,6 +135,18 @@ impl, I: 'static> Inspect<::AccountId> for Palle } } +impl, I: 'static> InspectRole<::AccountId> for Pallet { + fn is_issuer(collection: &Self::CollectionId, who: &::AccountId) -> bool { + Self::has_role(collection, who, CollectionRole::Issuer) + } + fn is_admin(collection: &Self::CollectionId, who: &::AccountId) -> bool { + Self::has_role(collection, who, CollectionRole::Admin) + } + fn is_freezer(collection: &Self::CollectionId, who: &::AccountId) -> bool { + Self::has_role(collection, who, CollectionRole::Freezer) + } +} + impl, I: 'static> Create<::AccountId, CollectionConfigFor> for Pallet { diff --git a/substrate/frame/support/src/traits/tokens/nonfungibles_v2.rs b/substrate/frame/support/src/traits/tokens/nonfungibles_v2.rs index f4c3c22ea9..6f428c297e 100644 --- a/substrate/frame/support/src/traits/tokens/nonfungibles_v2.rs +++ b/substrate/frame/support/src/traits/tokens/nonfungibles_v2.rs @@ -180,6 +180,16 @@ pub trait InspectEnumerable: Inspect { ) -> Self::OwnedInCollectionIterator; } +/// Trait for providing an interface to check the account's role within the collection. +pub trait InspectRole: Inspect { + /// Returns `true` if `who` is the issuer of the `collection`. + fn is_issuer(collection: &Self::CollectionId, who: &AccountId) -> bool; + /// Returns `true` if `who` is the admin of the `collection`. + fn is_admin(collection: &Self::CollectionId, who: &AccountId) -> bool; + /// Returns `true` if `who` is the freezer of the `collection`. + fn is_freezer(collection: &Self::CollectionId, who: &AccountId) -> bool; +} + /// Trait for providing the ability to create collections of nonfungible items. pub trait Create: Inspect { /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`.