git.delta.rocks / unique-network / refs/commits / 50176c630c6d

difftreelog

feat(rmrk) move internal rmrk id to property

Daniel Shiposha2022-06-10parent: #4f0a446.patch.diff
in: master

2 files changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -68,10 +68,6 @@
 	pub type UniqueCollectionId<T: Config> =
 		StorageMap<_, Twox64Concat, RmrkCollectionId, CollectionId, ValueQuery>;
 
-	#[pallet::storage]
-	pub type RmrkInernalCollectionId<T: Config> =
-		StorageMap<_, Twox64Concat, CollectionId, RmrkCollectionId, ValueQuery>;
-
 	#[pallet::pallet]
 	#[pallet::generate_store(pub(super) trait Store)]
 	pub struct Pallet<T>(_);
@@ -225,8 +221,13 @@
 			let rmrk_collection_id = <CollectionIndex<T>>::get();
 
 			<UniqueCollectionId<T>>::insert(rmrk_collection_id, unique_collection_id);
-			<RmrkInernalCollectionId<T>>::insert(unique_collection_id, rmrk_collection_id);
 
+			<PalletCommon<T>>::set_scoped_collection_property(
+				unique_collection_id,
+				PropertyScope::Rmrk,
+				Self::rmrk_property(RmrkInternalCollectionId, &rmrk_collection_id)?
+			)?;
+
 			<CollectionIndex<T>>::mutate(|n| *n += 1);
 
 			Self::deposit_event(Event::CollectionCreated {
@@ -1318,8 +1319,10 @@
 	pub fn rmrk_collection_id(
 		unique_collection_id: CollectionId,
 	) -> Result<RmrkCollectionId, DispatchError> {
-		<RmrkInernalCollectionId<T>>::try_get(unique_collection_id)
-			.map_err(|_| <Error<T>>::CollectionUnknown.into())
+		Self::get_collection_property_decoded(
+			unique_collection_id,
+			RmrkInternalCollectionId
+		)
 	}
 
 	pub fn get_nft_collection(
modifiedpallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth
before · pallets/proxy-rmrk-core/src/property.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use super::*;18use core::convert::AsRef;1920pub enum RmrkProperty<'r> {21	Metadata,22	CollectionType,23	TokenType,24	Transferable,25	RoyaltyInfo,26	Equipped,27	ResourceCollection,28	ResourcePriorities,29	ResourceType,30	PendingNftAccept,31	PendingResourceAccept,32	PendingResourceRemoval,33	Parts,34	Base,35	Src,36	Slot,37	License,38	Thumb,39	EquippedNft,40	BaseType,41	ExternalPartId,42	EquippableList,43	ZIndex,44	ThemeName,45	ThemeInherit,46	UserProperty(&'r [u8]),47}4849impl<'r> RmrkProperty<'r> {50	pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {51		fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {52			container.as_ref()53		}5455		macro_rules! key {56            ($($component:expr),+) => {57                PropertyKey::try_from([$(key!(@ &$component)),+].concat())58                    .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)59            };6061            (@ $key:expr) => {62                get_bytes($key)63            };64        }6566		match self {67			Self::Metadata => key!("metadata"),68			Self::CollectionType => key!("collection-type"),69			Self::TokenType => key!("token-type"),70			Self::Transferable => key!("transferable"),71			Self::RoyaltyInfo => key!("royalty-info"),72			Self::Equipped => key!("equipped"),73			Self::ResourceCollection => key!("resource-collection"),74			Self::ResourcePriorities => key!("resource-priorities"),75			Self::ResourceType => key!("resource-type"),76			Self::PendingNftAccept => key!("pending-nft-accept"),77			Self::PendingResourceAccept => key!("pending-resource-accept"),78			Self::PendingResourceRemoval => key!("pending-resource-removal"),79			Self::Parts => key!("parts"),80			Self::Base => key!("base"),81			Self::Src => key!("src"),82			Self::Slot => key!("slot"),83			Self::License => key!("license"),84			Self::Thumb => key!("thumb"),85			Self::EquippedNft => key!("equipped-nft"),86			Self::BaseType => key!("base-type"),87			Self::ExternalPartId => key!("ext-part-id"),88			Self::EquippableList => key!("equippable-list"),89			Self::ZIndex => key!("z-index"),90			Self::ThemeName => key!("theme-name"),91			Self::ThemeInherit => key!("theme-inherit"),92			Self::UserProperty(name) => key!("userprop-", name),93		}94	}95}
after · pallets/proxy-rmrk-core/src/property.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use super::*;18use core::convert::AsRef;1920pub enum RmrkProperty<'r> {21	Metadata,22	CollectionType,23	RmrkInternalCollectionId,24	TokenType,25	Transferable,26	RoyaltyInfo,27	Equipped,28	ResourceCollection,29	ResourcePriorities,30	ResourceType,31	PendingNftAccept,32	PendingResourceAccept,33	PendingResourceRemoval,34	Parts,35	Base,36	Src,37	Slot,38	License,39	Thumb,40	EquippedNft,41	BaseType,42	ExternalPartId,43	EquippableList,44	ZIndex,45	ThemeName,46	ThemeInherit,47	UserProperty(&'r [u8]),48}4950impl<'r> RmrkProperty<'r> {51	pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {52		fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {53			container.as_ref()54		}5556		macro_rules! key {57            ($($component:expr),+) => {58                PropertyKey::try_from([$(key!(@ &$component)),+].concat())59                    .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)60            };6162            (@ $key:expr) => {63                get_bytes($key)64            };65        }6667		match self {68			Self::Metadata => key!("metadata"),69			Self::CollectionType => key!("collection-type"),70			Self::RmrkInternalCollectionId => key!("internal-id"),71			Self::TokenType => key!("token-type"),72			Self::Transferable => key!("transferable"),73			Self::RoyaltyInfo => key!("royalty-info"),74			Self::Equipped => key!("equipped"),75			Self::ResourceCollection => key!("resource-collection"),76			Self::ResourcePriorities => key!("resource-priorities"),77			Self::ResourceType => key!("resource-type"),78			Self::PendingNftAccept => key!("pending-nft-accept"),79			Self::PendingResourceAccept => key!("pending-resource-accept"),80			Self::PendingResourceRemoval => key!("pending-resource-removal"),81			Self::Parts => key!("parts"),82			Self::Base => key!("base"),83			Self::Src => key!("src"),84			Self::Slot => key!("slot"),85			Self::License => key!("license"),86			Self::Thumb => key!("thumb"),87			Self::EquippedNft => key!("equipped-nft"),88			Self::BaseType => key!("base-type"),89			Self::ExternalPartId => key!("ext-part-id"),90			Self::EquippableList => key!("equippable-list"),91			Self::ZIndex => key!("z-index"),92			Self::ThemeName => key!("theme-name"),93			Self::ThemeInherit => key!("theme-inherit"),94			Self::UserProperty(name) => key!("userprop-", name),95		}96	}97}