From 1e4e783d24b76f70d820243ee59181048672d0ea Mon Sep 17 00:00:00 2001 From: Erick Casanova Date: Mon, 7 Nov 2022 12:00:02 -0600 Subject: [PATCH] add storage map to have NFTs verified --- pallets/fruniques/src/lib.rs | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/pallets/fruniques/src/lib.rs b/pallets/fruniques/src/lib.rs index 96991fbd..35f073a9 100644 --- a/pallets/fruniques/src/lib.rs +++ b/pallets/fruniques/src/lib.rs @@ -48,6 +48,8 @@ pub mod pallet { FruniqueCreated(T::AccountId, T::AccountId, T::CollectionId, T::ItemId), // A frunique/unique was successfully divided! FruniqueDivided(T::AccountId, T::AccountId, T::CollectionId, T::ItemId), + // A frunique has been verified. + FruniqueVerified(T::AccountId, CollectionId, ItemId), // Counter should work? NextFrunique(u32), } @@ -82,6 +84,8 @@ pub mod pallet { CollectionAlreadyExists, // Frunique already exists FruniqueAlreadyExists, + // Frunique already verified + FruniqueAlreadyVerified } #[pallet::storage] @@ -122,6 +126,19 @@ pub mod pallet { ValueQuery, >; + #[pallet::storage] + #[pallet::getter(fn frunique_verified)] + /// Keeps track of verified fruniques. + pub(super) type FruniqueVerified = StorageDoubleMap< + _, + Blake2_128Concat, + CollectionId, + Blake2_128Concat, + ItemId, + bool, + ValueQuery, + >; + #[pallet::storage] #[pallet::getter(fn frunique_child)] /// Keeps track of hierarchical information for a frunique. @@ -280,6 +297,28 @@ pub mod pallet { Ok(()) } + /// ## Verification of the NFT + /// ### Parameters: + /// - `origin` must be signed by the owner of the frunique. + /// - `class_id` must be a valid class of the asset class. + /// - `instance_id` must be a valid instance of the asset class. + #[pallet::weight(10_000 + T::DbWeight::get().writes(1))] + pub fn verify( + origin: OriginFor, + class_id: CollectionId, + instance_id: ItemId, + ) -> DispatchResult { + ensure!(Self::item_exists(&class_id, &instance_id), >::FruniqueNotFound); + + let owner: T::AccountId = ensure_signed(origin.clone())?; + + >::insert(class_id, instance_id, true); + + Self::deposit_event(Event::FruniqueVerified(owner, class_id, instance_id)); + + Ok(()) + } + /// ## Force set counter /// ### Parameters: /// `origin` must be signed by the Root origin.