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
33use misc::*;33use misc::*;
34pub use property::*;34pub use property::*;
35
36use RmrkProperty::*;
3537
36#[frame_support::pallet]38#[frame_support::pallet]
37pub mod pallet {39pub mod pallet {
136138
137 let collection_id = collection_id_res?;139 let collection_id = collection_id_res?;
138
139 let collection = Self::get_nft_collection(collection_id)?.into_inner();
140140
141 <PalletCommon<T>>::set_scoped_collection_properties(141 <PalletCommon<T>>::set_scoped_collection_properties(
142 &collection,142 collection_id,
143 PropertyScope::Rmrk,143 PropertyScope::Rmrk,
144 [144 [
145 rmrk_property!(Config=T, Metadata: metadata)?,145 Self::rmrk_property(Metadata, &metadata)?,
146 rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,146 Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,
147 ].into_iter()147 ].into_iter()
148 )?;148 )?;
149149
168168
169 let unique_collection_id = collection_id.into();169 let unique_collection_id = collection_id.into();
170170
171 let collection = Self::get_typed_nft_collection(unique_collection_id, CollectionType::Regular)?;171 let collection = Self::get_typed_nft_collection(unique_collection_id, misc::CollectionType::Regular)?;
172172
173 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);173 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
174174
193193
194 Self::change_collection_owner(194 Self::change_collection_owner(
195 collection_id.into(),195 collection_id.into(),
196 CollectionType::Regular,196 misc::CollectionType::Regular,
197 sender.clone(),197 sender.clone(),
198 new_issuer.clone()198 new_issuer.clone()
199 )?;199 )?;
218218
219 let collection = Self::get_typed_nft_collection(219 let collection = Self::get_typed_nft_collection(
220 collection_id.into(),220 collection_id.into(),
221 CollectionType::Regular221 misc::CollectionType::Regular
222 )?;222 )?;
223223
224 Self::check_collection_owner(&collection, &cross_sender)?;224 Self::check_collection_owner(&collection, &cross_sender)?;
253 amount253 amount
254 });254 });
255
256 let collection = Self::get_typed_nft_collection(
257 collection_id.into(),
258 misc::CollectionType::Regular,
259 )?;
255260
256 let nft_id = Self::create_nft(261 let nft_id = Self::create_nft(
257 &sender,262 &sender,
258 &cross_owner,263 &cross_owner,
259 collection_id.into(),
260 CollectionType::Regular,264 &collection,
261 NftType::Regular,265 NftType::Regular,
262 [266 [
263 rmrk_property!(Config=T, RoyaltyInfo: royalty_info)?,267 Self::rmrk_property(RoyaltyInfo, &royalty_info)?,
264 rmrk_property!(Config=T, Metadata: metadata)?,268 Self::rmrk_property(Metadata, &metadata)?,
265 rmrk_property!(Config=T, Equipped: false)?,269 Self::rmrk_property(Equipped, &false)?,
266 rmrk_property!(Config=T, ResourceCollection: None::<CollectionId>)?,270 Self::rmrk_property(ResourceCollection, &None::<CollectionId>)?,
267 rmrk_property!(Config=T, ResourcePriorities: <Vec<u8>>::new())?,271 Self::rmrk_property(ResourcePriorities, &<Vec<u8>>::new())?,
268 ].into_iter()272 ].into_iter()
269 )?;273 ).map_err(|err| match err {
274 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailableNftId.into(),
275 err => Self::map_common_err_to_proxy(err)
276 })?;
270277
271 Self::deposit_event(Event::NftMinted {278 Self::deposit_event(Event::NftMinted {
272 owner,279 owner,
290 Self::destroy_nft(297 Self::destroy_nft(
291 cross_sender,298 cross_sender,
292 collection_id.into(),299 collection_id.into(),
293 CollectionType::Regular,300 misc::CollectionType::Regular,
294 nft_id.into()301 nft_id.into()
295 )?;302 )?;
296303
302}309}
303310
304impl<T: Config> Pallet<T> {311impl<T: Config> Pallet<T> {
312 pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result<PropertyKey, DispatchError> {
313 let key = rmrk_key.to_key::<T>()?;
314
315 let scoped_key = PropertyScope::Rmrk.apply(key)
316 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)?;
317
318 Ok(scoped_key)
319 }
320
321 pub fn rmrk_property<E: Encode>(rmrk_key: RmrkProperty, value: &E) -> Result<Property, DispatchError> {
322 let key = rmrk_key.to_key::<T>()?;
323
324 let value = value.encode()
325 .try_into()
326 .map_err(|_| <Error<T>>::RmrkPropertyValueIsTooLong)?;
327
328 let property = Property {
329 key,
330 value,
331 };
332
333 Ok(property)
334 }
335
305 pub fn create_nft(336 pub fn create_nft(
306 sender: &T::CrossAccountId,337 sender: &T::CrossAccountId,
307 owner: &T::CrossAccountId,338 owner: &T::CrossAccountId,
308 collection_id: CollectionId,339 collection: &NonfungibleHandle<T>,
309 collection_type: CollectionType,
310 nft_type: NftType,340 nft_type: NftType,
311 properties: impl Iterator<Item=Property>341 properties: impl Iterator<Item=Property>
312 ) -> Result<TokenId, DispatchError> {342 ) -> Result<TokenId, DispatchError> {
313 let collection = Self::get_typed_nft_collection(
314 collection_id,
315 collection_type
316 )?;
317
318 let data = CreateNftExData {343 let data = CreateNftExData {
319 const_data: nft_type.encode()344 const_data: nft_type.encode()
326 let budget = budget::Value::new(2);351 let budget = budget::Value::new(2);
327352
328 <PalletNft<T>>::create_item(353 <PalletNft<T>>::create_item(
329 &collection,354 collection,
330 sender,355 sender,
331 data,356 data,
332 &budget,357 &budget,
333 ).map_err(Self::map_common_err_to_proxy)?;358 )?;
334359
335 let nft_id = <PalletNft<T>>::current_token_id(&collection);360 let nft_id = <PalletNft<T>>::current_token_id(collection.id);
336361
337 <PalletNft<T>>::set_scoped_token_properties(362 <PalletNft<T>>::set_scoped_token_properties(
338 &collection,363 collection.id,
339 nft_id,364 nft_id,
340 PropertyScope::Rmrk,365 PropertyScope::Rmrk,
341 properties366 properties
347 fn destroy_nft(372 fn destroy_nft(
348 sender: T::CrossAccountId,373 sender: T::CrossAccountId,
349 collection_id: CollectionId,374 collection_id: CollectionId,
350 collection_type: CollectionType,375 collection_type: misc::CollectionType,
351 token_id: TokenId376 token_id: TokenId
352 ) -> DispatchResult {377 ) -> DispatchResult {
353 let collection = Self::get_typed_nft_collection(378 let collection = Self::get_typed_nft_collection(
363388
364 fn change_collection_owner(389 fn change_collection_owner(
365 collection_id: CollectionId,390 collection_id: CollectionId,
366 collection_type: CollectionType,391 collection_type: misc::CollectionType,
367 sender: T::AccountId,392 sender: T::AccountId,
368 new_owner: T::AccountId,393 new_owner: T::AccountId,
369 ) -> DispatchResult {394 ) -> DispatchResult {
391 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {416 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {
392 let collection = <CollectionHandle<T>>::try_get(collection_id)417 let collection = <CollectionHandle<T>>::try_get(collection_id)
393 .map_err(|_| <Error<T>>::CollectionUnknown)?418 .map_err(|_| <Error<T>>::CollectionUnknown)?;
394 .into_nft_collection()?;419
395420 match collection.mode {
396 Ok(collection)421 CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)),
422 _ => Err(<Error<T>>::CollectionUnknown.into())
423 }
397 }424 }
398425
399 // should this even be here, might displace it to common/nonfungible -- but they did not need it, only rmrk does426 // should this even be here, might displace it to common/nonfungible -- but they did not need it, only rmrk does
407434
408 pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {435 pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {
409 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)436 let collection_property = <PalletCommon<T>>::collection_properties(collection_id)
410 .get(&rmrk_property!(Config=T, key)?)437 .get(&Self::rmrk_property_key(key)?)
411 .ok_or(<Error<T>>::CollectionUnknown)?438 .ok_or(<Error<T>>::CollectionUnknown)?
412 .clone();439 .clone();
413440
414 Ok(collection_property)441 Ok(collection_property)
415 }442 }
416443
417 pub fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {444 pub fn get_collection_type(collection_id: CollectionId) -> Result<misc::CollectionType, DispatchError> {
418 let value = Self::get_collection_property(collection_id, RmrkProperty::CollectionType)?;445 let value = Self::get_collection_property(collection_id, CollectionType)?;
446
419 let collection_type: CollectionType = (&value)447 let mut value = value.as_slice();
420 .try_into()448
449 misc::CollectionType::decode(&mut value)
421 .map_err(<Error<T>>::from)?;450 .map_err(|_| <Error<T>>::CorruptedCollectionType.into())
422
423 Ok(collection_type)
424 }451 }
425452
426 pub fn ensure_collection_type(collection_id: CollectionId, collection_type: CollectionType) -> DispatchResult {453 pub fn ensure_collection_type(collection_id: CollectionId, collection_type: misc::CollectionType) -> DispatchResult {
427 let actual_type = Self::get_collection_type(collection_id)?;454 let actual_type = Self::get_collection_type(collection_id)?;
428 ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);455 ensure!(actual_type == collection_type, <CommonError<T>>::NoPermission);
429456
432459
433 pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {460 pub fn get_nft_property(collection_id: CollectionId, nft_id: TokenId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {
434 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))461 let nft_property = <PalletNft<T>>::token_properties((collection_id, nft_id))
435 .get(&rmrk_property!(Config=T, key)?)462 .get(&Self::rmrk_property_key(key)?)
436 .ok_or(<Error<T>>::NoAvailableNftId)?463 .ok_or(<Error<T>>::NoAvailableNftId)?
437 .clone();464 .clone();
438465
439 Ok(nft_property)466 Ok(nft_property)
440 }467 }
441468
442 pub fn get_nft_type(collection_id: CollectionId, token_id: TokenId) -> Result<NftType, DispatchError> {469 pub fn get_nft_type(collection_id: CollectionId, token_id: TokenId) -> Result<NftType, DispatchError> {
470 let token_data = <TokenData<T>>::get((collection_id, token_id))
471 .ok_or(<Error<T>>::NoAvailableNftId)?;
472
473 let mut const_data = token_data.const_data.as_slice();
474
443 <TokenData<T>>::get((collection_id, token_id))475 NftType::decode(&mut const_data).map_err(|_| <Error<T>>::NoAvailableNftId.into())
444 .unwrap()
445 .rmrk_nft_type()
446 .ok_or_else(|| <Error<T>>::NoAvailableNftId.into())
447 }476 }
448477
449 pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult {478 pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult {
466 let value = Self::get_nft_property(495 let value = Self::get_nft_property(
467 collection_id,496 collection_id,
468 token_id,497 token_id,
469 RmrkProperty::ThemeProperty(&key)498 ThemeProperty(&key)
470 ).ok()?.decode_or_default();499 ).ok()?.decode_or_default();
471500
472 let property = RmrkThemeProperty {501 let property = RmrkThemeProperty {
491 collection_id: CollectionId,520 collection_id: CollectionId,
492 token_id: TokenId521 token_id: TokenId
493 ) -> Result<impl Iterator<Item=RmrkThemeProperty>, DispatchError> {522 ) -> Result<impl Iterator<Item=RmrkThemeProperty>, DispatchError> {
494 let key_prefix = rmrk_property!(Config=T, key: ThemeProperty(&RmrkString::default()))?;523 let key_prefix = Self::rmrk_property_key(ThemeProperty(&RmrkString::default()))?;
495524
496 let properties = <PalletNft<T>>::token_properties((collection_id, token_id))525 let properties = <PalletNft<T>>::token_properties((collection_id, token_id))
497 .into_iter()526 .into_iter()
514543
515 pub fn get_typed_nft_collection(544 pub fn get_typed_nft_collection(
516 collection_id: CollectionId,545 collection_id: CollectionId,
517 collection_type: CollectionType546 collection_type: misc::CollectionType
518 ) -> Result<NonfungibleHandle<T>, DispatchError> {547 ) -> Result<NonfungibleHandle<T>, DispatchError> {
519 Self::ensure_collection_type(collection_id, collection_type)?;548 Self::ensure_collection_type(collection_id, collection_type)?;
520549
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
--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -20,9 +20,9 @@
 use frame_system::{pallet_prelude::*, ensure_signed};
 use sp_runtime::DispatchError;
 use up_data_structs::*;
-use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle};
-use pallet_rmrk_core::{Pallet as PalletCore, rmrk_property, misc::*};
-use pallet_nonfungible::{Pallet as PalletNft};
+use pallet_common::{Pallet as PalletCommon, Error as CommonError};
+use pallet_rmrk_core::{Pallet as PalletCore, misc::{self, *}, property::RmrkProperty::*};
+use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};
 use pallet_evm::account::CrossAccountId;
 
 pub use pallet::*;
@@ -48,6 +48,16 @@
         TokenId
     >;
 
+    #[pallet::storage]
+	#[pallet::getter(fn base_has_default_theme)]
+    pub type BaseHasDefaultTheme<T: Config> = StorageMap<
+        _,
+        Twox64Concat,
+        CollectionId,
+        bool,
+        ValueQuery
+    >;
+
     #[pallet::pallet]
 	#[pallet::generate_store(pub(super) trait Store)]
 	pub struct Pallet<T>(_);
@@ -63,7 +73,11 @@
 
     #[pallet::error]
 	pub enum Error<T> {
+        PermissionError,
         NoAvailableBaseId,
+        NoAvailablePartId,
+        BaseDoesntExist,
+        NeedsDefaultThemeFirst,
     }
 
     #[pallet::call]
@@ -95,17 +109,17 @@
 
             let collection_id = collection_id_res?;
 
-            let collection = <PalletCore<T>>::get_nft_collection(collection_id)?.into_inner();
-
             <PalletCommon<T>>::set_scoped_collection_properties(
-                &collection,
+                collection_id,
                 PropertyScope::Rmrk,
                 [
-                    rmrk_property!(Config=T, CollectionType: CollectionType::Base)?,
-                    rmrk_property!(Config=T, BaseType: base_type)?,
+                    <PalletCore<T>>::rmrk_property(CollectionType, &misc::CollectionType::Base)?,
+                    <PalletCore<T>>::rmrk_property(BaseType, &base_type)?,
                 ].into_iter()
             )?;
 
+            let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;
+
             for part in parts {
                 let part_id = part.id();
                 let part_token_id = Self::create_part(
@@ -117,10 +131,10 @@
                 <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);
 
                 <PalletNft<T>>::set_scoped_token_property(
-                    &collection,
+                    collection_id,
                     part_token_id,
                     PropertyScope::Rmrk,
-                    rmrk_property!(Config=T, ExternalPartId: part_id)?
+                    <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?
                 )?;
             }
 
@@ -128,13 +142,64 @@
 
             Ok(())
         }
+
+        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+        #[transactional]
+		pub fn theme_add(
+			origin: OriginFor<T>,
+			base_id: RmrkBaseId,
+			theme: RmrkTheme,
+		) -> DispatchResult {
+            let sender = ensure_signed(origin)?;
+
+            let sender = T::CrossAccountId::from_sub(sender);
+            let owner = &sender;
+
+            let collection_id: CollectionId = base_id.into();
+
+            let collection = <PalletCore<T>>::get_typed_nft_collection(
+                collection_id,
+                misc::CollectionType::Base
+            ).map_err(|_| <Error<T>>::BaseDoesntExist)?;
+
+            if theme.name.as_slice() == b"default" {
+                <BaseHasDefaultTheme<T>>::insert(collection_id, true);
+            } else if !Self::base_has_default_theme(collection_id) {
+                return Err(<Error<T>>::NeedsDefaultThemeFirst.into());
+            }
+
+            let token_id = <PalletCore<T>>::create_nft(
+                &sender,
+                owner,
+                &collection,
+                NftType::Theme,
+                [
+                    <PalletCore<T>>::rmrk_property(ThemeName, &theme.name)?,
+                    <PalletCore<T>>::rmrk_property(ThemeInherit, &theme.inherit)?
+                ].into_iter()
+            ).map_err(|_| <Error<T>>::PermissionError)?;
+
+            for property in theme.properties {
+                <PalletNft<T>>::set_scoped_token_property(
+                    collection_id,
+                    token_id,
+                    PropertyScope::Rmrk,
+                    <PalletCore<T>>::rmrk_property(
+                        ThemeProperty(&property.key),
+                        &property.value
+                    )?
+                )?;
+            }
+
+            Ok(())
+        }
     }
 }
 
 impl<T: Config> Pallet<T> {
     fn create_part(
         sender: &T::CrossAccountId,
-        collection: &CollectionHandle<T>,
+        collection: &NonfungibleHandle<T>,
         part: RmrkPartType
     ) -> Result<TokenId, DispatchError> {
         let owner = sender;
@@ -150,21 +215,23 @@
         let token_id = <PalletCore<T>>::create_nft(
             sender,
             owner,
-            collection.id,
-            CollectionType::Base,
+            collection,
             nft_type,
             [
-                rmrk_property!(Config=T, Src: src)?,
-                rmrk_property!(Config=T, ZIndex: z_index)?
+                <PalletCore<T>>::rmrk_property(Src, &src)?,
+                <PalletCore<T>>::rmrk_property(ZIndex, &z_index)?
             ].into_iter()
-        )?;
+        ).map_err(|err| match err {
+            DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),
+            err => err
+        })?;
 
         if let RmrkPartType::SlotPart(part) = part {
             <PalletNft<T>>::set_scoped_token_property(
-                collection,
+                collection.id,
                 token_id,
                 PropertyScope::Rmrk,
-                rmrk_property!(Config=T, EquippableList: part.equippable)?
+                <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?
             )?;
         }
 
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);