git.delta.rocks / unique-network / refs/commits / aab4f305c437

difftreelog

refactor rmrk proxy, add add_theme rmrk proxy

Daniel Shiposha2022-05-25parent: #4186437.patch.diff
in: master

8 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -30,7 +30,7 @@
 // RMRK
 use rmrk_rpc::RmrkApi as RmrkRuntimeApi;
 use up_data_structs::{
-	RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkPropertyKey,
+	RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName,
 	RmrkResourceId,
 };
 
@@ -248,7 +248,7 @@
 		fn collection_properties(
 			&self,
 			collection_id: RmrkCollectionId,
-			filter_keys: Option<Vec<RmrkPropertyKey>>, //String
+			filter_keys: Option<Vec<String>>,
 			at: Option<BlockHash>,
 		) -> Result<Vec<PropertyInfo>>;
 
@@ -258,7 +258,7 @@
 			&self,
 			collection_id: RmrkCollectionId,
 			nft_id: RmrkNftId,
-			filter_keys: Option<Vec<RmrkPropertyKey>>,
+			filter_keys: Option<Vec<String>>,
 			at: Option<BlockHash>,
 		) -> Result<Vec<PropertyInfo>>;
 
@@ -299,8 +299,8 @@
 		fn theme(
 			&self,
 			base_id: RmrkBaseId,
-			theme_name: RmrkThemeName, // String
-			filter_keys: Option<Vec<RmrkPropertyKey>>,
+			theme_name: String,
+			filter_keys: Option<Vec<String>>,
 			at: Option<BlockHash>,
 		) -> Result<Option<Theme>>;
 	}
@@ -523,11 +523,22 @@
 	pass_method!(account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Vec<RmrkNftId>, rmrk_api);
 	pass_method!(nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<RmrkNftChild>, rmrk_api);
 	pass_method!(
-		collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Vec<PropertyInfo>,
+		collection_properties(
+			collection_id: RmrkCollectionId,
+
+			#[map(|keys| string_keys_to_bytes_keys(keys))]
+			filter_keys: Option<Vec<String>>
+		) -> Vec<PropertyInfo>,
 		rmrk_api
 	);
 	pass_method!(
-		nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Vec<PropertyInfo>,
+		nft_properties(
+			collection_id: RmrkCollectionId,
+			nft_id: RmrkNftId,
+
+			#[map(|keys| string_keys_to_bytes_keys(keys))]
+			filter_keys: Option<Vec<String>>
+		) -> Vec<PropertyInfo>,
 		rmrk_api
 	);
 	pass_method!(nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<ResourceInfo>, rmrk_api);
@@ -535,7 +546,16 @@
 	pass_method!(base(base_id: RmrkBaseId) -> Option<BaseInfo>, rmrk_api);
 	pass_method!(base_parts(base_id: RmrkBaseId) -> Vec<PartType>, rmrk_api);
 	pass_method!(theme_names(base_id: RmrkBaseId) -> Vec<RmrkThemeName>, rmrk_api);
-	pass_method!(theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Option<Theme>, rmrk_api);
+	pass_method!(
+		theme(
+			base_id: RmrkBaseId,
+
+			#[map(|n| n.into_bytes())]
+			theme_name: String,
+
+			#[map(|keys| string_keys_to_bytes_keys(keys))]
+			filter_keys: Option<Vec<String>>
+		) -> Option<Theme>, rmrk_api);
 }
 
 fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -795,11 +795,11 @@
 	}
 
 	pub fn set_scoped_collection_property(
-		collection: &CollectionHandle<T>,
+		collection_id: CollectionId,
 		scope: PropertyScope,
 		property: Property,
 	) -> DispatchResult {
-		CollectionProperties::<T>::try_mutate(collection.id, |properties| {
+		CollectionProperties::<T>::try_mutate(collection_id, |properties| {
 			properties.try_scoped_set(scope, property.key, property.value)
 		})
 		.map_err(<Error<T>>::from)?;
@@ -807,13 +807,12 @@
 		Ok(())
 	}
 
-	#[transactional]
 	pub fn set_scoped_collection_properties(
-		collection: &CollectionHandle<T>,
+		collection_id: CollectionId,
 		scope: PropertyScope,
 		properties: impl Iterator<Item = Property>,
 	) -> DispatchResult {
-		CollectionProperties::<T>::try_mutate(collection.id, |stored_properties| {
+		CollectionProperties::<T>::try_mutate(collection_id, |stored_properties| {
 			stored_properties.try_scoped_set_from_iter(scope, properties)
 		})
 		.map_err(<Error<T>>::from)?;
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -195,12 +195,12 @@
 	}
 
 	pub fn set_scoped_token_property(
-		collection: &CollectionHandle<T>,
+		collection_id: CollectionId,
 		token_id: TokenId,
 		scope: PropertyScope,
 		property: Property,
 	) -> DispatchResult {
-		TokenProperties::<T>::try_mutate((collection.id, token_id), |properties| {
+		TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {
 			properties.try_scoped_set(scope, property.key, property.value)
 		})
 		.map_err(<CommonError<T>>::from)?;
@@ -209,12 +209,12 @@
 	}
 
 	pub fn set_scoped_token_properties(
-		collection: &CollectionHandle<T>,
+		collection_id: CollectionId,
 		token_id: TokenId,
 		scope: PropertyScope,
 		properties: impl Iterator<Item=Property>,
 	) -> DispatchResult {
-		TokenProperties::<T>::try_mutate((collection.id, token_id), |stored_properties| {
+		TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {
 			stored_properties.try_scoped_set_from_iter(scope, properties)
 		})
 		.map_err(<CommonError<T>>::from)?;
@@ -222,8 +222,8 @@
 		Ok(())
 	}
 
-	pub fn current_token_id(collection: &CollectionHandle<T>) -> TokenId {
-		TokenId(<TokensMinted<T>>::get(collection.id))
+	pub fn current_token_id(collection_id: CollectionId) -> TokenId {
+		TokenId(<TokensMinted<T>>::get(collection_id))
 	}
 }
 
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -33,6 +33,8 @@
 use misc::*;
 pub use property::*;
 
+use RmrkProperty::*;
+
 #[frame_support::pallet]
 pub mod pallet {
     use super::*;
@@ -135,15 +137,13 @@
             }
 
             let collection_id = collection_id_res?;
-
-            let collection = Self::get_nft_collection(collection_id)?.into_inner();
 
             <PalletCommon<T>>::set_scoped_collection_properties(
-                &collection,
+                collection_id,
                 PropertyScope::Rmrk,
                 [
-                    rmrk_property!(Config=T, Metadata: metadata)?,
-                    rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,
+                    Self::rmrk_property(Metadata, &metadata)?,
+                    Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,
                 ].into_iter()
             )?;
 
@@ -168,7 +168,7 @@
 
             let unique_collection_id = collection_id.into();
 
-            let collection = Self::get_typed_nft_collection(unique_collection_id, CollectionType::Regular)?;
+            let collection = Self::get_typed_nft_collection(unique_collection_id, misc::CollectionType::Regular)?;
 
             ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
 
@@ -193,7 +193,7 @@
 
             Self::change_collection_owner(
                 collection_id.into(),
-                CollectionType::Regular,
+                misc::CollectionType::Regular,
                 sender.clone(),
                 new_issuer.clone()
             )?;
@@ -218,7 +218,7 @@
 
             let collection = Self::get_typed_nft_collection(
                 collection_id.into(),
-                CollectionType::Regular
+                misc::CollectionType::Regular
             )?;
 
             Self::check_collection_owner(&collection, &cross_sender)?;
@@ -253,20 +253,27 @@
                 amount
             });
 
+            let collection = Self::get_typed_nft_collection(
+                collection_id.into(),
+                misc::CollectionType::Regular,
+            )?;
+
             let nft_id = Self::create_nft(
                 &sender,
                 &cross_owner,
-                collection_id.into(),
-                CollectionType::Regular,
+                &collection,
                 NftType::Regular,
                 [
-                    rmrk_property!(Config=T, RoyaltyInfo: royalty_info)?,
-                    rmrk_property!(Config=T, Metadata: metadata)?,
-                    rmrk_property!(Config=T, Equipped: false)?,
-                    rmrk_property!(Config=T, ResourceCollection: None::<CollectionId>)?,
-                    rmrk_property!(Config=T, ResourcePriorities: <Vec<u8>>::new())?,
+                    Self::rmrk_property(RoyaltyInfo, &royalty_info)?,
+                    Self::rmrk_property(Metadata, &metadata)?,
+                    Self::rmrk_property(Equipped, &false)?,
+                    Self::rmrk_property(ResourceCollection, &None::<CollectionId>)?,
+                    Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,
                 ].into_iter()
-            )?;
+            ).map_err(|err| match err {
+                DispatchError::Arithmetic(_) => <Error<T>>::NoAvailableNftId.into(),
+                err => Self::map_common_err_to_proxy(err)
+            })?;
 
             Self::deposit_event(Event::NftMinted {
                 owner,
@@ -290,7 +297,7 @@
             Self::destroy_nft(
                 cross_sender,
                 collection_id.into(),
-                CollectionType::Regular,
+                misc::CollectionType::Regular,
                 nft_id.into()
             )?;
 
@@ -302,19 +309,37 @@
 }
 
 impl<T: Config> Pallet<T> {
+    pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result<PropertyKey, DispatchError> {
+        let key = rmrk_key.to_key::<T>()?;
+
+        let scoped_key = PropertyScope::Rmrk.apply(key)
+            .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)?;
+
+        Ok(scoped_key)
+    }
+
+    pub fn rmrk_property<E: Encode>(rmrk_key: RmrkProperty, value: &E) -> Result<Property, DispatchError> {
+        let key = rmrk_key.to_key::<T>()?;
+
+        let value = value.encode()
+            .try_into()
+            .map_err(|_| <Error<T>>::RmrkPropertyValueIsTooLong)?;
+
+        let property = Property {
+            key,
+            value,
+        };
+
+        Ok(property)
+    }
+
     pub fn create_nft(
         sender: &T::CrossAccountId,
         owner: &T::CrossAccountId,
-        collection_id: CollectionId,
-        collection_type: CollectionType,
+        collection: &NonfungibleHandle<T>,
         nft_type: NftType,
         properties: impl Iterator<Item=Property>
     ) -> Result<TokenId, DispatchError> {
-        let collection = Self::get_typed_nft_collection(
-            collection_id,
-            collection_type
-        )?;
-
         let data = CreateNftExData {
             const_data: nft_type.encode()
                 .try_into()
@@ -326,16 +351,16 @@
         let budget = budget::Value::new(2);
 
         <PalletNft<T>>::create_item(
-            &collection,
+            collection,
             sender,
             data,
             &budget,
-        ).map_err(Self::map_common_err_to_proxy)?;
+        )?;
 
-        let nft_id = <PalletNft<T>>::current_token_id(&collection);
+        let nft_id = <PalletNft<T>>::current_token_id(collection.id);
 
         <PalletNft<T>>::set_scoped_token_properties(
-            &collection,
+            collection.id,
             nft_id,
             PropertyScope::Rmrk,
             properties
@@ -347,7 +372,7 @@
     fn destroy_nft(
         sender: T::CrossAccountId,
         collection_id: CollectionId,
-        collection_type: CollectionType,
+        collection_type: misc::CollectionType,
         token_id: TokenId
     ) -> DispatchResult {
         let collection = Self::get_typed_nft_collection(
@@ -363,7 +388,7 @@
 
     fn change_collection_owner(
         collection_id: CollectionId,
-        collection_type: CollectionType,
+        collection_type: misc::CollectionType,
         sender: T::AccountId,
         new_owner: T::AccountId,
     ) -> DispatchResult {
@@ -390,10 +415,12 @@
 
     pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {
         let collection = <CollectionHandle<T>>::try_get(collection_id)
-            .map_err(|_| <Error<T>>::CollectionUnknown)?
-            .into_nft_collection()?;
+            .map_err(|_| <Error<T>>::CollectionUnknown)?;
 
-        Ok(collection)
+        match collection.mode {
+            CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)),
+            _ => Err(<Error<T>>::CollectionUnknown.into())
+        }
     }
 
     // should this even be here, might displace it to common/nonfungible -- but they did not need it, only rmrk does
@@ -407,23 +434,23 @@
 
     pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {
         let collection_property = <PalletCommon<T>>::collection_properties(collection_id)
-            .get(&rmrk_property!(Config=T, key)?)
+            .get(&Self::rmrk_property_key(key)?)
             .ok_or(<Error<T>>::CollectionUnknown)?
             .clone();
 
         Ok(collection_property)
     }
 
-    pub fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {
-        let value = Self::get_collection_property(collection_id, RmrkProperty::CollectionType)?;
-        let collection_type: CollectionType = (&value)
-            .try_into()
-            .map_err(<Error<T>>::from)?;
+    pub fn get_collection_type(collection_id: CollectionId) -> Result<misc::CollectionType, DispatchError> {
+        let value = Self::get_collection_property(collection_id, CollectionType)?;
+
+        let mut value = value.as_slice();
 
-        Ok(collection_type)
+        misc::CollectionType::decode(&mut value)
+            .map_err(|_| <Error<T>>::CorruptedCollectionType.into())
     }
 
-    pub fn ensure_collection_type(collection_id: CollectionId, collection_type: CollectionType) -> DispatchResult {
+    pub fn ensure_collection_type(collection_id: CollectionId, collection_type: misc::CollectionType) -> DispatchResult {
         let actual_type = Self::get_collection_type(collection_id)?;
         ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);
 
@@ -432,7 +459,7 @@
 
     pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {
         let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))
-            .get(&rmrk_property!(Config=T, key)?)
+            .get(&Self::rmrk_property_key(key)?)
             .ok_or(<Error<T>>::NoAvailableNftId)?
             .clone();
 
@@ -440,10 +467,12 @@
     }
 
     pub fn get_nft_type(collection_id: CollectionId, token_id: TokenId) -> Result<NftType, DispatchError> {
-        <TokenData<T>>::get((collection_id, token_id))
-            .unwrap()
-            .rmrk_nft_type()
-            .ok_or_else(|| <Error<T>>::NoAvailableNftId.into())
+        let token_data = <TokenData<T>>::get((collection_id, token_id))
+            .ok_or(<Error<T>>::NoAvailableNftId)?;
+
+        let mut const_data = token_data.const_data.as_slice();
+
+        NftType::decode(&mut const_data).map_err(|_| <Error<T>>::NoAvailableNftId.into())
     }
 
     pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult {
@@ -466,7 +495,7 @@
                     let value = Self::get_nft_property(
                         collection_id,
                         token_id,
-                        RmrkProperty::ThemeProperty(&key)
+                        ThemeProperty(&key)
                     ).ok()?.decode_or_default();
 
                     let property = RmrkThemeProperty {
@@ -491,7 +520,7 @@
         collection_id: CollectionId,
         token_id: TokenId
     ) -> Result<impl Iterator<Item=RmrkThemeProperty>, DispatchError> {
-        let key_prefix = rmrk_property!(Config=T, key: ThemeProperty(&RmrkString::default()))?;
+        let key_prefix = Self::rmrk_property_key(ThemeProperty(&RmrkString::default()))?;
 
         let properties = <PalletNft<T>>::token_properties((collection_id, token_id))
             .into_iter()
@@ -514,7 +543,7 @@
 
     pub fn get_typed_nft_collection(
         collection_id: CollectionId,
-        collection_type: CollectionType
+        collection_type: misc::CollectionType
     ) -> Result<NonfungibleHandle<T>, DispatchError> {
         Self::ensure_collection_type(collection_id, collection_type)?;
 
modifiedpallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -1,23 +1,6 @@
 use super::*;
 use codec::{Encode, Decode};
-use pallet_nonfungible::{NonfungibleHandle, ItemData};
-
-macro_rules! impl_rmrk_value {
-    ($enum_name:path, decode_error: $error:ident) => {
-        impl TryFrom<&PropertyValue> for $enum_name {
-            type Error = MiscError;
-
-            fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {
-                let mut value = value.as_slice();
 
-                <$enum_name>::decode(&mut value)
-                    .map_err(|_| MiscError::$error)
-            }
-        }
-
-    };
-}
-
 #[macro_export]
 macro_rules! map_common_err_to_proxy {
     (match $err:ident { $($common_err:ident => $proxy_err:ident),+ }) => {
@@ -29,59 +12,8 @@
             $err
         }
     };
-}
-
-pub enum MiscError {
-    RmrkPropertyValueIsTooLong,
-    CorruptedCollectionType,
-}
-
-impl<T: Config> From<MiscError> for Error<T> {
-    fn from(error: MiscError) -> Self {
-        match error {
-            MiscError::RmrkPropertyValueIsTooLong => Self::RmrkPropertyValueIsTooLong,
-            MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,
-        }
-    }
-}
-
-pub trait IntoNftCollection<T: Config> {
-    fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;
 }
 
-impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {
-    fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {
-        match self.mode {
-            CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),
-            _ => Err(<Error<T>>::CollectionUnknown)
-        }
-    }
-}
-
-pub trait IntoPropertyValue {
-    fn into_property_value(self) -> Result<PropertyValue, MiscError>;
-}
-
-impl<T: Encode> IntoPropertyValue for T {
-    fn into_property_value(self) -> Result<PropertyValue, MiscError> {
-        self.encode()
-            .try_into()
-            .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)
-    }
-}
-
-pub trait RmrkNft {
-    fn rmrk_nft_type(&self) -> Option<NftType>;
-}
-
-impl<CrossAccountId> RmrkNft for ItemData<CrossAccountId> {
-    fn rmrk_nft_type(&self) -> Option<NftType> {
-        let mut value = self.const_data.as_slice();
-
-        NftType::decode(&mut value).ok()
-    }
-}
-
 pub trait RmrkDecode<T: Decode + Default, S> {
     fn decode_or_default(&self) -> T;
 }
@@ -121,5 +53,3 @@
     SlotPart,
     Theme
 }
-
-impl_rmrk_value!(CollectionType, decode_error: CorruptedCollectionType);
modifiedpallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/property.rs
+++ b/pallets/proxy-rmrk-core/src/property.rs
@@ -71,31 +71,3 @@
         }
     }
 }
-
-#[macro_export]
-macro_rules! rmrk_property {
-    (Config=$cfg:ty, key: $key:ident $(($key_ext:expr))?) => {
-        rmrk_property!(Config=$cfg, $crate::RmrkProperty::$key $(($key_ext))?)
-    };
-
-    (Config=$cfg:ty, $key:ident $(($key_ext:expr))?: $value:expr) => {{
-        let key = rmrk_property!(@$cfg, $crate::RmrkProperty::$key $(($key_ext))?)?;
-
-        let value = $value.into_property_value()
-            .map_err(<$crate::Error<$cfg>>::from)?;
-
-        Ok::<_, $crate::Error<$cfg>>(Property {
-            key,
-            value,
-        })
-    }};
-
-    (@$cfg:ty, $key_enum:expr) => {
-        $key_enum.to_key::<$cfg>()
-    };
-
-    (Config=$cfg:ty, $key_enum:expr) => {
-        PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key_enum)?)
-            .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)
-    };
-}
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
before · pallets/proxy-rmrk-equip/src/lib.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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};20use frame_system::{pallet_prelude::*, ensure_signed};21use sp_runtime::DispatchError;22use up_data_structs::*;23use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle};24use pallet_rmrk_core::{Pallet as PalletCore, rmrk_property, misc::*};25use pallet_nonfungible::{Pallet as PalletNft};26use pallet_evm::account::CrossAccountId;2728pub use pallet::*;2930#[frame_support::pallet]31pub mod pallet {32    use super::*;3334	#[pallet::config]35	pub trait Config: frame_system::Config36                    + pallet_rmrk_core::Config {37		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;38	}3940    #[pallet::storage]41	#[pallet::getter(fn internal_part_id)]42	pub type InernalPartId<T: Config> = StorageDoubleMap<43        _,44        Twox64Concat,45        CollectionId,46        Twox64Concat,47        RmrkPartId,48        TokenId49    >;5051    #[pallet::pallet]52	#[pallet::generate_store(pub(super) trait Store)]53	pub struct Pallet<T>(_);5455	#[pallet::event]56	#[pallet::generate_deposit(pub(super) fn deposit_event)]57	pub enum Event<T: Config> {58        BaseCreated {59			issuer: T::AccountId,60			base_id: RmrkBaseId,61		},62    }6364    #[pallet::error]65	pub enum Error<T> {66        NoAvailableBaseId,67    }6869    #[pallet::call]70	impl<T: Config> Pallet<T> {71        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]72        #[transactional]73		pub fn create_base(74			origin: OriginFor<T>,75			base_type: RmrkString,76			symbol: RmrkString,77			parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,78		) -> DispatchResult {79            let sender = ensure_signed(origin)?;80            let cross_sender = T::CrossAccountId::from_sub(sender.clone());8182            let data = CreateCollectionData {83                limits: None,84                token_prefix: symbol.into_inner()85                    .try_into()86                    .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,87                ..Default::default()88            };8990            let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);9192            if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {93                return Err(<Error<T>>::NoAvailableBaseId.into());94            }9596            let collection_id = collection_id_res?;9798            let collection = <PalletCore<T>>::get_nft_collection(collection_id)?.into_inner();99100            <PalletCommon<T>>::set_scoped_collection_properties(101                &collection,102                PropertyScope::Rmrk,103                [104                    rmrk_property!(Config=T, CollectionType: CollectionType::Base)?,105                    rmrk_property!(Config=T, BaseType: base_type)?,106                ].into_iter()107            )?;108109            for part in parts {110                let part_id = part.id();111                let part_token_id = Self::create_part(112                    &cross_sender,113                    &collection,114                    part115                )?;116117                <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);118119                <PalletNft<T>>::set_scoped_token_property(120                    &collection,121                    part_token_id,122                    PropertyScope::Rmrk,123                    rmrk_property!(Config=T, ExternalPartId: part_id)?124                )?;125            }126127            Self::deposit_event(Event::BaseCreated { issuer: sender, base_id: collection_id.0 });128129            Ok(())130        }131    }132}133134impl<T: Config> Pallet<T> {135    fn create_part(136        sender: &T::CrossAccountId,137        collection: &CollectionHandle<T>,138        part: RmrkPartType139    ) -> Result<TokenId, DispatchError> {140        let owner = sender;141142        let src = part.src();143        let z_index = part.z_index();144145        let nft_type = match part {146            RmrkPartType::FixedPart(_) => NftType::FixedPart,147            RmrkPartType::SlotPart(_) => NftType::SlotPart,148        };149150        let token_id = <PalletCore<T>>::create_nft(151            sender,152            owner,153            collection.id,154            CollectionType::Base,155            nft_type,156            [157                rmrk_property!(Config=T, Src: src)?,158                rmrk_property!(Config=T, ZIndex: z_index)?159            ].into_iter()160        )?;161162        if let RmrkPartType::SlotPart(part) = part {163            <PalletNft<T>>::set_scoped_token_property(164                collection,165                token_id,166                PropertyScope::Rmrk,167                rmrk_property!(Config=T, EquippableList: part.equippable)?168            )?;169        }170171        Ok(token_id)172    }173}
after · pallets/proxy-rmrk-equip/src/lib.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/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};20use frame_system::{pallet_prelude::*, ensure_signed};21use sp_runtime::DispatchError;22use up_data_structs::*;23use pallet_common::{Pallet as PalletCommon, Error as CommonError};24use pallet_rmrk_core::{Pallet as PalletCore, misc::{self, *}, property::RmrkProperty::*};25use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};26use pallet_evm::account::CrossAccountId;2728pub use pallet::*;2930#[frame_support::pallet]31pub mod pallet {32    use super::*;3334	#[pallet::config]35	pub trait Config: frame_system::Config36                    + pallet_rmrk_core::Config {37		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;38	}3940    #[pallet::storage]41	#[pallet::getter(fn internal_part_id)]42	pub type InernalPartId<T: Config> = StorageDoubleMap<43        _,44        Twox64Concat,45        CollectionId,46        Twox64Concat,47        RmrkPartId,48        TokenId49    >;5051    #[pallet::storage]52	#[pallet::getter(fn base_has_default_theme)]53    pub type BaseHasDefaultTheme<T: Config> = StorageMap<54        _,55        Twox64Concat,56        CollectionId,57        bool,58        ValueQuery59    >;6061    #[pallet::pallet]62	#[pallet::generate_store(pub(super) trait Store)]63	pub struct Pallet<T>(_);6465	#[pallet::event]66	#[pallet::generate_deposit(pub(super) fn deposit_event)]67	pub enum Event<T: Config> {68        BaseCreated {69			issuer: T::AccountId,70			base_id: RmrkBaseId,71		},72    }7374    #[pallet::error]75	pub enum Error<T> {76        PermissionError,77        NoAvailableBaseId,78        NoAvailablePartId,79        BaseDoesntExist,80        NeedsDefaultThemeFirst,81    }8283    #[pallet::call]84	impl<T: Config> Pallet<T> {85        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]86        #[transactional]87		pub fn create_base(88			origin: OriginFor<T>,89			base_type: RmrkString,90			symbol: RmrkString,91			parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,92		) -> DispatchResult {93            let sender = ensure_signed(origin)?;94            let cross_sender = T::CrossAccountId::from_sub(sender.clone());9596            let data = CreateCollectionData {97                limits: None,98                token_prefix: symbol.into_inner()99                    .try_into()100                    .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,101                ..Default::default()102            };103104            let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);105106            if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {107                return Err(<Error<T>>::NoAvailableBaseId.into());108            }109110            let collection_id = collection_id_res?;111112            <PalletCommon<T>>::set_scoped_collection_properties(113                collection_id,114                PropertyScope::Rmrk,115                [116                    <PalletCore<T>>::rmrk_property(CollectionType, &misc::CollectionType::Base)?,117                    <PalletCore<T>>::rmrk_property(BaseType, &base_type)?,118                ].into_iter()119            )?;120121            let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;122123            for part in parts {124                let part_id = part.id();125                let part_token_id = Self::create_part(126                    &cross_sender,127                    &collection,128                    part129                )?;130131                <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);132133                <PalletNft<T>>::set_scoped_token_property(134                    collection_id,135                    part_token_id,136                    PropertyScope::Rmrk,137                    <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?138                )?;139            }140141            Self::deposit_event(Event::BaseCreated { issuer: sender, base_id: collection_id.0 });142143            Ok(())144        }145146        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]147        #[transactional]148		pub fn theme_add(149			origin: OriginFor<T>,150			base_id: RmrkBaseId,151			theme: RmrkTheme,152		) -> DispatchResult {153            let sender = ensure_signed(origin)?;154155            let sender = T::CrossAccountId::from_sub(sender);156            let owner = &sender;157158            let collection_id: CollectionId = base_id.into();159160            let collection = <PalletCore<T>>::get_typed_nft_collection(161                collection_id,162                misc::CollectionType::Base163            ).map_err(|_| <Error<T>>::BaseDoesntExist)?;164165            if theme.name.as_slice() == b"default" {166                <BaseHasDefaultTheme<T>>::insert(collection_id, true);167            } else if !Self::base_has_default_theme(collection_id) {168                return Err(<Error<T>>::NeedsDefaultThemeFirst.into());169            }170171            let token_id = <PalletCore<T>>::create_nft(172                &sender,173                owner,174                &collection,175                NftType::Theme,176                [177                    <PalletCore<T>>::rmrk_property(ThemeName, &theme.name)?,178                    <PalletCore<T>>::rmrk_property(ThemeInherit, &theme.inherit)?179                ].into_iter()180            ).map_err(|_| <Error<T>>::PermissionError)?;181182            for property in theme.properties {183                <PalletNft<T>>::set_scoped_token_property(184                    collection_id,185                    token_id,186                    PropertyScope::Rmrk,187                    <PalletCore<T>>::rmrk_property(188                        ThemeProperty(&property.key),189                        &property.value190                    )?191                )?;192            }193194            Ok(())195        }196    }197}198199impl<T: Config> Pallet<T> {200    fn create_part(201        sender: &T::CrossAccountId,202        collection: &NonfungibleHandle<T>,203        part: RmrkPartType204    ) -> Result<TokenId, DispatchError> {205        let owner = sender;206207        let src = part.src();208        let z_index = part.z_index();209210        let nft_type = match part {211            RmrkPartType::FixedPart(_) => NftType::FixedPart,212            RmrkPartType::SlotPart(_) => NftType::SlotPart,213        };214215        let token_id = <PalletCore<T>>::create_nft(216            sender,217            owner,218            collection,219            nft_type,220            [221                <PalletCore<T>>::rmrk_property(Src, &src)?,222                <PalletCore<T>>::rmrk_property(ZIndex, &z_index)?223            ].into_iter()224        ).map_err(|err| match err {225            DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),226            err => err227        })?;228229        if let RmrkPartType::SlotPart(part) = part {230            <PalletNft<T>>::set_scoped_token_property(231                collection.id,232                token_id,233                PropertyScope::Rmrk,234                <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?235            )?;236        }237238        Ok(token_id)239    }240}
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -347,7 +347,7 @@
 
                 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {
                     use frame_support::BoundedVec;
-                    use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkNft, RmrkDecode}};
+                    use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};
 
                     let collection_id = CollectionId(base_id);
                     if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() { return Ok(Vec::new()); }
@@ -379,7 +379,7 @@
 
                 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {
                     use frame_support::BoundedVec;
-                    use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkNft, RmrkDecode}};
+                    use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode}};
 
                     let collection_id = CollectionId(base_id);
                     if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() {
@@ -407,7 +407,7 @@
                     use frame_support::BoundedVec;
                     use pallet_proxy_rmrk_core::{
                         RmrkProperty,
-                        misc::{CollectionType, NftType, RmrkNft, RmrkDecode}
+                        misc::{CollectionType, NftType, RmrkDecode}
                     };
 
                     let collection_id = CollectionId(base_id);