git.delta.rocks / unique-network / refs/commits / 415353264b69

difftreelog

style reformat code

Yaroslav Bolyukin2022-05-30parent: #d048005.patch.diff
in: master

19 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -30,8 +30,7 @@
 // RMRK
 use rmrk_rpc::RmrkApi as RmrkRuntimeApi;
 use up_data_structs::{
-	RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName,
-	RmrkResourceId,
+	RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkResourceId,
 };
 
 pub use rmrk_unique_rpc::RmrkApi;
modifiednode/cli/src/service.rsdiffbeforeafterboth
--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -364,7 +364,8 @@
 			RmrkBaseInfo<AccountId>,
 			RmrkPartType,
 			RmrkTheme,
-		>*/ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+		>*/
+		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
 		+ sp_api::Metadata<Block>
 		+ sp_offchain::OffchainWorkerApi<Block>
 		+ cumulus_primitives_core::CollectCollationInfo<Block>,
@@ -656,7 +657,8 @@
 			RmrkBaseInfo<AccountId>,
 			RmrkPartType,
 			RmrkTheme,
-		>*/ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+		>*/
+		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
 		+ sp_api::Metadata<Block>
 		+ sp_offchain::OffchainWorkerApi<Block>
 		+ cumulus_primitives_core::CollectCollationInfo<Block>
@@ -800,7 +802,8 @@
 			RmrkBaseInfo<AccountId>,
 			RmrkPartType,
 			RmrkTheme,
-		>*/ + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
+		>*/
+		+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>
 		+ sp_api::Metadata<Block>
 		+ sp_offchain::OffchainWorkerApi<Block>
 		+ cumulus_primitives_core::CollectCollationInfo<Block>
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -501,7 +501,6 @@
 			PhantomType<(
 				TokenData<T::CrossAccountId>,
 				RpcCollection<T::AccountId>,
-
 				// RMRK
 				RmrkCollectionInfo<T::AccountId>,
 				RmrkInstanceInfo<T::AccountId>,
@@ -526,19 +525,34 @@
 					if !v.offchain_schema.is_empty() {
 						props.push(Property {
 							key: b"_old_offchainSchema".to_vec().try_into().unwrap(),
-							value: v.offchain_schema.clone().into_inner().try_into().expect("offchain schema too big"),
+							value: v
+								.offchain_schema
+								.clone()
+								.into_inner()
+								.try_into()
+								.expect("offchain schema too big"),
 						});
 					}
 					if !v.variable_on_chain_schema.is_empty() {
 						props.push(Property {
 							key: b"_old_variableOnChainSchema".to_vec().try_into().unwrap(),
-							value: v.variable_on_chain_schema.clone().into_inner().try_into().expect("offchain schema too big"),
+							value: v
+								.variable_on_chain_schema
+								.clone()
+								.into_inner()
+								.try_into()
+								.expect("offchain schema too big"),
 						});
 					}
 					if !v.const_on_chain_schema.is_empty() {
 						props.push(Property {
 							key: b"_old_constOnChainSchema".to_vec().try_into().unwrap(),
-							value: v.const_on_chain_schema.clone().into_inner().try_into().expect("offchain schema too big"),
+							value: v
+								.const_on_chain_schema
+								.clone()
+								.into_inner()
+								.try_into()
+								.expect("offchain schema too big"),
 						});
 					}
 					props.push(Property {
@@ -546,13 +560,17 @@
 						value: match v.schema_version {
 							SchemaVersion::ImageURL => b"ImageUrl".as_slice(),
 							SchemaVersion::Unique => b"Unique".as_slice(),
-						}.to_vec().try_into().unwrap(),
+						}
+						.to_vec()
+						.try_into()
+						.unwrap(),
 					});
 					Self::set_scoped_collection_properties(
 						id,
 						PropertyScope::None,
 						props.into_iter(),
-					).expect("existing data larger than properties");
+					)
+					.expect("existing data larger than properties");
 					let mut new = CollectionVersion2::from(v.clone());
 					new.permissions.access = Some(v.access);
 					new.permissions.mint_mode = Some(v.mint_mode);
@@ -644,18 +662,12 @@
 
 		let token_property_permissions = <CollectionPropertyPermissions<T>>::get(collection)
 			.into_iter()
-			.map(|(key, permission)| PropertyKeyPermission {
-				key,
-				permission,
-			})
+			.map(|(key, permission)| PropertyKeyPermission { key, permission })
 			.collect();
 
 		let properties = <CollectionProperties<T>>::get(collection)
 			.into_iter()
-			.map(|(key, value)| Property {
-				key,
-				value,
-			})
+			.map(|(key, value)| Property { key, value })
 			.collect();
 
 		let permissions = CollectionPermissions {
@@ -751,7 +763,9 @@
 				.unwrap_or_else(|| Ok(CollectionLimits::default()))?,
 			permissions: data
 				.permissions
-				.map(|permissions| Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions))
+				.map(|permissions| {
+					Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)
+				})
 				.unwrap_or_else(|| Ok(CollectionPermissions::default()))?,
 		};
 
@@ -1005,10 +1019,7 @@
 			.unwrap_or_else(|| {
 				properties
 					.into_iter()
-					.map(|(key, value)| Property {
-						key,
-						value,
-					})
+					.map(|(key, value)| Property { key, value })
 					.collect()
 			});
 
@@ -1037,10 +1048,7 @@
 			.unwrap_or_else(|| {
 				permissions
 					.into_iter()
-					.map(|(key, permission)| PropertyKeyPermission {
-						key,
-						permission,
-					})
+					.map(|(key, permission)| PropertyKeyPermission { key, permission })
 					.collect()
 			});
 
@@ -1276,17 +1284,9 @@
 		budget: &dyn Budget,
 	) -> DispatchResult;
 
-	fn nest(
-		&self,
-		under: TokenId,
-		to_nest: (CollectionId, TokenId)
-	);
+	fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId));
 
-	fn unnest(
-		&self,
-		under: TokenId,
-		to_nest: (CollectionId, TokenId)
-	);
+	fn unnest(&self, under: TokenId, to_nest: (CollectionId, TokenId));
 
 	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;
 	fn collection_tokens(&self) -> Vec<TokenId>;
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -298,17 +298,9 @@
 		fail!(<Error<T>>::FungibleDisallowsNesting)
 	}
 
-	fn nest(
-		&self,
-		_under: TokenId,
-		_to_nest: (CollectionId, TokenId)
-	) {}
+	fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}
 
-	fn unnest(
-		&self,
-		_under: TokenId,
-		_to_nest: (CollectionId, TokenId)
-	) {}
+	fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}
 
 	fn collection_tokens(&self) -> Vec<TokenId> {
 		vec![TokenId::default()]
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -184,11 +184,7 @@
 
 		if balance == 0 {
 			<Balance<T>>::remove((collection.id, owner));
-			<PalletStructure<T>>::unnest_if_nested(
-				owner,
-				collection.id,
-				TokenId::default()
-			);
+			<PalletStructure<T>>::unnest_if_nested(owner, collection.id, TokenId::default());
 		} else {
 			<Balance<T>>::insert((collection.id, owner), balance);
 		}
@@ -249,18 +245,14 @@
 			to,
 			collection.id,
 			TokenId::default(),
-			nesting_budget
+			nesting_budget,
 		)?;
 
 		if let Some(balance_to) = balance_to {
 			// from != to
 			if balance_from == 0 {
 				<Balance<T>>::remove((collection.id, from));
-				<PalletStructure<T>>::unnest_if_nested(
-					from,
-					collection.id,
-					TokenId::default()
-				);
+				<PalletStructure<T>>::unnest_if_nested(from, collection.id, TokenId::default());
 			} else {
 				<Balance<T>>::insert((collection.id, from), balance_from);
 			}
@@ -333,7 +325,11 @@
 		<TotalSupply<T>>::insert(collection.id, total_supply);
 		for (user, amount) in balances {
 			<Balance<T>>::insert((collection.id, &user), amount);
-			<PalletStructure<T>>::nest_if_sent_to_token_unchecked(&user, collection.id, TokenId::default());
+			<PalletStructure<T>>::nest_if_sent_to_token_unchecked(
+				&user,
+				collection.id,
+				TokenId::default(),
+			);
 			<PalletEvm<T>>::deposit_log(
 				ERC20Events::Transfer {
 					from: H160::default(),
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -22,7 +22,7 @@
 	PropertyKeyPermission, PropertyValue,
 };
 use pallet_common::{
-	CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _
+	CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _,
 };
 use sp_runtime::DispatchError;
 use sp_std::vec::Vec;
@@ -353,19 +353,11 @@
 		<Pallet<T>>::check_nesting(self, sender, from, under, budget)
 	}
 
-	fn nest(
-		&self,
-		under: TokenId,
-		to_nest: (CollectionId, TokenId)
-	) {
+	fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId)) {
 		<Pallet<T>>::nest((self.id, under), to_nest);
 	}
 
-	fn unnest(
-		&self,
-		under: TokenId,
-		to_unnest: (CollectionId, TokenId)
-	) {
+	fn unnest(&self, under: TokenId, to_unnest: (CollectionId, TokenId)) {
 		<Pallet<T>>::unnest((self.id, under), to_unnest);
 	}
 
@@ -415,10 +407,7 @@
 		.unwrap_or_else(|| {
 			properties
 				.into_iter()
-				.map(|(key, value)| Property {
-					key,
-					value,
-				})
+				.map(|(key, value)| Property { key, value })
 				.collect()
 		})
 	}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -426,11 +426,10 @@
 	Ok(a)
 }
 
-fn has_token_permission<T: Config>(
-	collection_id: CollectionId,
-	key: &PropertyKey,
-) -> bool {
-	if let Ok(token_property_permissions) = CollectionPropertyPermissions::<T>::try_get(collection_id) {
+fn has_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> bool {
+	if let Ok(token_property_permissions) =
+		CollectionPropertyPermissions::<T>::try_get(collection_id)
+	{
 		return token_property_permissions.contains_key(key);
 	}
 
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -164,31 +164,44 @@
 		fn on_runtime_upgrade() -> Weight {
 			if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
 				let mut had_consts = BTreeSet::new();
-				<TokenData<T>>::translate::<ItemDataVersion1<T::CrossAccountId>, _>(|(collection, token), v| {
-					let mut props = vec![];
-					if !v.const_data.is_empty() {
-						props.push(Property {
-							key: b"_old_constData".to_vec().try_into().unwrap(),
-							value: v.const_data.clone().into_inner().try_into().expect("const too long"),
-						});
-						had_consts.insert(collection);
-					}
-					if !v.variable_data.is_empty() {
-						props.push(Property {
-							key: b"_old_variableData".to_vec().try_into().unwrap(),
-							value: v.variable_data.clone().into_inner().try_into().expect("variable too long"),
-						})
-					}
-					if !props.is_empty() {
-						Self::set_scoped_token_properties(
-							collection,
-							token,
-							PropertyScope::None,
-							props.into_iter(),
-						).expect("existing token data exceeds property storage");
-					}
-					Some(<ItemDataVersion2<T::CrossAccountId>>::from(v))
-				});
+				<TokenData<T>>::translate::<ItemDataVersion1<T::CrossAccountId>, _>(
+					|(collection, token), v| {
+						let mut props = vec![];
+						if !v.const_data.is_empty() {
+							props.push(Property {
+								key: b"_old_constData".to_vec().try_into().unwrap(),
+								value: v
+									.const_data
+									.clone()
+									.into_inner()
+									.try_into()
+									.expect("const too long"),
+							});
+							had_consts.insert(collection);
+						}
+						if !v.variable_data.is_empty() {
+							props.push(Property {
+								key: b"_old_variableData".to_vec().try_into().unwrap(),
+								value: v
+									.variable_data
+									.clone()
+									.into_inner()
+									.try_into()
+									.expect("variable too long"),
+							})
+						}
+						if !props.is_empty() {
+							Self::set_scoped_token_properties(
+								collection,
+								token,
+								PropertyScope::None,
+								props.into_iter(),
+							)
+							.expect("existing token data exceeds property storage");
+						}
+						Some(<ItemDataVersion2<T::CrossAccountId>>::from(v))
+					},
+				);
 				for collection in had_consts {
 					<PalletCommon<T>>::set_property_permission_unchecked(
 						collection,
@@ -199,8 +212,9 @@
 								collection_admin: true,
 								token_owner: false,
 							},
-						}
-					).expect("failed to configure permission");
+						},
+					)
+					.expect("failed to configure permission");
 				}
 			}
 
@@ -263,7 +277,7 @@
 		collection_id: CollectionId,
 		token_id: TokenId,
 		scope: PropertyScope,
-		properties: impl Iterator<Item=Property>,
+		properties: impl Iterator<Item = Property>,
 	) -> DispatchResult {
 		TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {
 			stored_properties.try_scoped_set_from_iter(scope, properties)
@@ -347,11 +361,7 @@
 			<AccountBalance<T>>::insert((collection.id, token_data.owner.clone()), balance);
 		}
 
-		<PalletStructure<T>>::unnest_if_nested(
-			&token_data.owner,
-			collection.id,
-			token
-		);
+		<PalletStructure<T>>::unnest_if_nested(&token_data.owner, collection.id, token);
 
 		<Owned<T>>::remove((collection.id, &token_data.owner, token));
 		<TokensBurnt<T>>::insert(collection.id, burnt);
@@ -589,16 +599,12 @@
 			to,
 			collection.id,
 			token,
-			nesting_budget
+			nesting_budget,
 		)?;
 
 		// =========
 
-		<PalletStructure<T>>::unnest_if_nested(
-			from,
-			collection.id,
-			token
-		);
+		<PalletStructure<T>>::unnest_if_nested(from, collection.id, token);
 
 		<TokenData<T>>::insert(
 			(collection.id, token),
@@ -709,7 +715,11 @@
 					},
 				);
 
-				<PalletStructure<T>>::nest_if_sent_to_token_unchecked(&data.owner, collection.id, TokenId(token));
+				<PalletStructure<T>>::nest_if_sent_to_token_unchecked(
+					&data.owner,
+					collection.id,
+					TokenId(token),
+				);
 
 				if let Err(e) = Self::set_token_properties(
 					collection,
@@ -958,31 +968,24 @@
 		Ok(())
 	}
 
-	fn nest(
-		under: (CollectionId, TokenId),
-		to_nest: (CollectionId, TokenId),
-	) {
-		<TokenChildren<T>>::insert(
-			(under.0, under.1, (to_nest.0, to_nest.1)),
-			true
-		);
+	fn nest(under: (CollectionId, TokenId), to_nest: (CollectionId, TokenId)) {
+		<TokenChildren<T>>::insert((under.0, under.1, (to_nest.0, to_nest.1)), true);
 	}
 
-	fn unnest(
-		under: (CollectionId, TokenId),
-		to_unnest: (CollectionId, TokenId),
-	) {
-		<TokenChildren<T>>::remove(
-			(under.0, under.1, to_unnest)
-		);
+	fn unnest(under: (CollectionId, TokenId), to_unnest: (CollectionId, TokenId)) {
+		<TokenChildren<T>>::remove((under.0, under.1, to_unnest));
 	}
 
 	fn collection_has_tokens(collection_id: CollectionId) -> bool {
-		<TokenData<T>>::iter_prefix((collection_id,)).next().is_some()
+		<TokenData<T>>::iter_prefix((collection_id,))
+			.next()
+			.is_some()
 	}
 
 	fn token_has_children(collection_id: CollectionId, token_id: TokenId) -> bool {
-		<TokenChildren<T>>::iter_prefix((collection_id, token_id)).next().is_some()
+		<TokenChildren<T>>::iter_prefix((collection_id, token_id))
+			.next()
+			.is_some()
 	}
 
 	/// Delegated to `create_multiple_items`
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -21,7 +21,9 @@
 use sp_runtime::{DispatchError, Permill, traits::StaticLookup};
 use sp_std::vec::Vec;
 use up_data_structs::*;
-use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};
+use pallet_common::{
+	Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations,
+};
 use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle, TokenData};
 use pallet_evm::account::CrossAccountId;
 use core::convert::AsRef;
@@ -38,18 +40,17 @@
 
 #[frame_support::pallet]
 pub mod pallet {
-    use super::*;
-    use pallet_evm::account;
+	use super::*;
+	use pallet_evm::account;
 
 	#[pallet::config]
-	pub trait Config: frame_system::Config
-                    + pallet_common::Config
-                    + pallet_nonfungible::Config
-                    + account::Config {
+	pub trait Config:
+		frame_system::Config + pallet_common::Config + pallet_nonfungible::Config + account::Config
+	{
 		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
 	}
 
-    #[pallet::storage]
+	#[pallet::storage]
 	#[pallet::getter(fn collection_index)]
 	pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;
 
@@ -60,33 +61,33 @@
 	#[pallet::event]
 	#[pallet::generate_deposit(pub(super) fn deposit_event)]
 	pub enum Event<T: Config> {
-        CollectionCreated {
+		CollectionCreated {
 			issuer: T::AccountId,
 			collection_id: RmrkCollectionId,
 		},
-        CollectionDestroyed {
+		CollectionDestroyed {
 			issuer: T::AccountId,
 			collection_id: RmrkCollectionId,
 		},
-        IssuerChanged {
+		IssuerChanged {
 			old_issuer: T::AccountId,
 			new_issuer: T::AccountId,
 			collection_id: RmrkCollectionId,
 		},
-        CollectionLocked {
+		CollectionLocked {
 			issuer: T::AccountId,
 			collection_id: RmrkCollectionId,
 		},
-        NftMinted {
+		NftMinted {
 			owner: T::AccountId,
 			collection_id: RmrkCollectionId,
 			nft_id: RmrkNftId,
 		},
-        NFTBurned {
+		NFTBurned {
 			owner: T::AccountId,
 			nft_id: RmrkNftId,
 		},
-        PropertySet {
+		PropertySet {
 			collection_id: RmrkCollectionId,
 			maybe_nft_id: Option<RmrkNftId>,
 			key: RmrkKeyString,
@@ -96,24 +97,24 @@
 
 	#[pallet::error]
 	pub enum Error<T> {
-        /* Unique-specific events */
-        CorruptedCollectionType,
-        NftTypeEncodeError,
-        RmrkPropertyKeyIsTooLong,
-        RmrkPropertyValueIsTooLong,
+		/* Unique-specific events */
+		CorruptedCollectionType,
+		NftTypeEncodeError,
+		RmrkPropertyKeyIsTooLong,
+		RmrkPropertyValueIsTooLong,
 
-        /* RMRK compatible events */
-        CollectionNotEmpty,
-        NoAvailableCollectionId,
-        NoAvailableNftId,
-        CollectionUnknown,
-        NoPermission,
-        CollectionFullOrLocked,
+		/* RMRK compatible events */
+		CollectionNotEmpty,
+		NoAvailableCollectionId,
+		NoAvailableNftId,
+		CollectionUnknown,
+		NoPermission,
+		CollectionFullOrLocked,
 	}
 
 	#[pallet::call]
 	impl<T: Config> Pallet<T> {
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
 		pub fn create_collection(
 			origin: OriginFor<T>,
@@ -121,127 +122,141 @@
 			max: Option<u32>,
 			symbol: RmrkCollectionSymbol,
 		) -> DispatchResult {
-            let sender = ensure_signed(origin)?;
+			let sender = ensure_signed(origin)?;
 
-            let limits = CollectionLimits {
-                owner_can_transfer: Some(false),
-                token_limit: max,
-                ..Default::default()
-            };
+			let limits = CollectionLimits {
+				owner_can_transfer: Some(false),
+				token_limit: max,
+				..Default::default()
+			};
 
-            let data = CreateCollectionData {
-                limits: Some(limits),
-                token_prefix: symbol.into_inner()
-                    .try_into()
-                    .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
-                ..Default::default()
-            };
+			let data = CreateCollectionData {
+				limits: Some(limits),
+				token_prefix: symbol
+					.into_inner()
+					.try_into()
+					.map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
+				..Default::default()
+			};
 
-            let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
+			let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
 
-            if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
-                return Err(<Error<T>>::NoAvailableCollectionId.into());
-            }
+			if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
+				return Err(<Error<T>>::NoAvailableCollectionId.into());
+			}
 
-            let collection_id = collection_id_res?;
+			let collection_id = collection_id_res?;
 
-            <PalletCommon<T>>::set_scoped_collection_properties(
-                collection_id,
-                PropertyScope::Rmrk,
-                [
-                    Self::rmrk_property(Metadata, &metadata)?,
-                    Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,
-                ].into_iter()
-            )?;
+			<PalletCommon<T>>::set_scoped_collection_properties(
+				collection_id,
+				PropertyScope::Rmrk,
+				[
+					Self::rmrk_property(Metadata, &metadata)?,
+					Self::rmrk_property(CollectionType, &misc::CollectionType::Regular)?,
+				]
+				.into_iter(),
+			)?;
 
-            <CollectionIndex<T>>::mutate(|n| *n += 1);
+			<CollectionIndex<T>>::mutate(|n| *n += 1);
 
-            Self::deposit_event(Event::CollectionCreated {
-                issuer: sender,
-                collection_id: collection_id.0
-            });
+			Self::deposit_event(Event::CollectionCreated {
+				issuer: sender,
+				collection_id: collection_id.0,
+			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
 		pub fn destroy_collection(
 			origin: OriginFor<T>,
 			collection_id: RmrkCollectionId,
 		) -> DispatchResult {
-            let sender = ensure_signed(origin)?;
-            let cross_sender = T::CrossAccountId::from_sub(sender.clone());
+			let sender = ensure_signed(origin)?;
+			let cross_sender = T::CrossAccountId::from_sub(sender.clone());
 
-            let unique_collection_id = collection_id.into();
+			let unique_collection_id = collection_id.into();
 
-            let collection = Self::get_typed_nft_collection(unique_collection_id, misc::CollectionType::Regular)?;
+			let collection = Self::get_typed_nft_collection(
+				unique_collection_id,
+				misc::CollectionType::Regular,
+			)?;
 
-            ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
+			ensure!(
+				collection.total_supply() == 0,
+				<Error<T>>::CollectionNotEmpty
+			);
 
-            <PalletNft<T>>::destroy_collection(collection, &cross_sender)
-                .map_err(Self::map_common_err_to_proxy)?;
+			<PalletNft<T>>::destroy_collection(collection, &cross_sender)
+				.map_err(Self::map_common_err_to_proxy)?;
 
-            Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });
+			Self::deposit_event(Event::CollectionDestroyed {
+				issuer: sender,
+				collection_id,
+			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
 		pub fn change_collection_issuer(
 			origin: OriginFor<T>,
 			collection_id: RmrkCollectionId,
 			new_issuer: <T::Lookup as StaticLookup>::Source,
 		) -> DispatchResult {
-            let sender = ensure_signed(origin)?;
+			let sender = ensure_signed(origin)?;
 
-            let new_issuer = T::Lookup::lookup(new_issuer)?;
+			let new_issuer = T::Lookup::lookup(new_issuer)?;
 
-            Self::change_collection_owner(
-                collection_id.into(),
-                misc::CollectionType::Regular,
-                sender.clone(),
-                new_issuer.clone()
-            )?;
+			Self::change_collection_owner(
+				collection_id.into(),
+				misc::CollectionType::Regular,
+				sender.clone(),
+				new_issuer.clone(),
+			)?;
 
-            Self::deposit_event(Event::IssuerChanged {
+			Self::deposit_event(Event::IssuerChanged {
 				old_issuer: sender,
 				new_issuer,
 				collection_id,
 			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
 		pub fn lock_collection(
 			origin: OriginFor<T>,
 			collection_id: RmrkCollectionId,
 		) -> DispatchResult {
-            let sender = ensure_signed(origin)?;
-            let cross_sender = T::CrossAccountId::from_sub(sender.clone());
+			let sender = ensure_signed(origin)?;
+			let cross_sender = T::CrossAccountId::from_sub(sender.clone());
 
-            let collection = Self::get_typed_nft_collection(
-                collection_id.into(),
-                misc::CollectionType::Regular
-            )?;
+			let collection = Self::get_typed_nft_collection(
+				collection_id.into(),
+				misc::CollectionType::Regular,
+			)?;
 
-            Self::check_collection_owner(&collection, &cross_sender)?;
+			Self::check_collection_owner(&collection, &cross_sender)?;
 
-            let token_count = collection.total_supply();
+			let token_count = collection.total_supply();
 
-            let mut collection = collection.into_inner();
-            collection.limits.token_limit = Some(token_count);
-            collection.save()?;
+			let mut collection = collection.into_inner();
+			collection.limits.token_limit = Some(token_count);
+			collection.save()?;
 
-			Self::deposit_event(Event::CollectionLocked { issuer: sender, collection_id });
+			Self::deposit_event(Event::CollectionLocked {
+				issuer: sender,
+				collection_id,
+			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
 		pub fn mint_nft(
 			origin: OriginFor<T>,
@@ -251,47 +266,49 @@
 			royalty_amount: Option<Permill>,
 			metadata: RmrkString,
 		) -> DispatchResult {
-            let sender = ensure_signed(origin)?;
-            let sender = T::CrossAccountId::from_sub(sender);
-            let cross_owner = T::CrossAccountId::from_sub(owner.clone());
+			let sender = ensure_signed(origin)?;
+			let sender = T::CrossAccountId::from_sub(sender);
+			let cross_owner = T::CrossAccountId::from_sub(owner.clone());
 
-            let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {
-                recipient: recipient.unwrap_or_else(|| owner.clone()),
-                amount
-            });
+			let royalty_info = royalty_amount.map(|amount| rmrk::RoyaltyInfo {
+				recipient: recipient.unwrap_or_else(|| owner.clone()),
+				amount,
+			});
 
-            let collection = Self::get_typed_nft_collection(
-                collection_id.into(),
-                misc::CollectionType::Regular,
-            )?;
+			let collection = Self::get_typed_nft_collection(
+				collection_id.into(),
+				misc::CollectionType::Regular,
+			)?;
 
-            let nft_id = Self::create_nft(
-                &sender,
-                &cross_owner,
-                &collection,
-                NftType::Regular,
-                [
-                    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)
-            })?;
+			let nft_id = Self::create_nft(
+				&sender,
+				&cross_owner,
+				&collection,
+				NftType::Regular,
+				[
+					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,
-                collection_id,
-                nft_id: nft_id.0
-            });
+			Self::deposit_event(Event::NftMinted {
+				owner,
+				collection_id,
+				nft_id: nft_id.0,
+			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
 		pub fn burn_nft(
 			origin: OriginFor<T>,
@@ -299,21 +316,24 @@
 			nft_id: RmrkNftId,
 		) -> DispatchResult {
 			let sender = ensure_signed(origin)?;
-            let cross_sender = T::CrossAccountId::from_sub(sender.clone());
+			let cross_sender = T::CrossAccountId::from_sub(sender.clone());
 
-            Self::destroy_nft(
-                cross_sender,
-                collection_id.into(),
-                misc::CollectionType::Regular,
-                nft_id.into()
-            )?;
+			Self::destroy_nft(
+				cross_sender,
+				collection_id.into(),
+				misc::CollectionType::Regular,
+				nft_id.into(),
+			)?;
 
-            Self::deposit_event(Event::NFTBurned { owner: sender, nft_id });
+			Self::deposit_event(Event::NFTBurned {
+				owner: sender,
+				nft_id,
+			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
 		#[transactional]
 		pub fn set_property(
 			origin: OriginFor<T>,
@@ -322,323 +342,346 @@
 			key: RmrkKeyString,
 			value: RmrkValueString,
 		) -> DispatchResult {
-            let sender = ensure_signed(origin)?;
-            let sender = T::CrossAccountId::from_sub(sender);
+			let sender = ensure_signed(origin)?;
+			let sender = T::CrossAccountId::from_sub(sender);
 
-            let collection_id: CollectionId = rmrk_collection_id.into();
+			let collection_id: CollectionId = rmrk_collection_id.into();
 
-            match maybe_nft_id {
-                Some(nft_id) => {
-                    let token_id: TokenId = nft_id.into();
+			match maybe_nft_id {
+				Some(nft_id) => {
+					let token_id: TokenId = nft_id.into();
 
-                    Self::ensure_nft_owner(collection_id, token_id, &sender)?;
-                    Self::ensure_nft_type(collection_id, token_id, NftType::Regular)?;
+					Self::ensure_nft_owner(collection_id, token_id, &sender)?;
+					Self::ensure_nft_type(collection_id, token_id, NftType::Regular)?;
 
-                    <PalletNft<T>>::set_scoped_token_property(
-                        collection_id,
-                        token_id,
-                        PropertyScope::Rmrk,
-                        Self::rmrk_property(UserProperty(key.as_slice()), &value)?
-                    )?;
-                },
-                None => {
-                    let collection = Self::get_typed_nft_collection(
-                        collection_id,
-                        misc::CollectionType::Regular
-                    )?;
+					<PalletNft<T>>::set_scoped_token_property(
+						collection_id,
+						token_id,
+						PropertyScope::Rmrk,
+						Self::rmrk_property(UserProperty(key.as_slice()), &value)?,
+					)?;
+				}
+				None => {
+					let collection = Self::get_typed_nft_collection(
+						collection_id,
+						misc::CollectionType::Regular,
+					)?;
 
-                    Self::check_collection_owner(&collection, &sender)?;
+					Self::check_collection_owner(&collection, &sender)?;
 
-                    <PalletCommon<T>>::set_scoped_collection_property(
-                        collection_id,
-                        PropertyScope::Rmrk,
-                        Self::rmrk_property(UserProperty(key.as_slice()), &value)?
-                    )?;
-                }
-            }
+					<PalletCommon<T>>::set_scoped_collection_property(
+						collection_id,
+						PropertyScope::Rmrk,
+						Self::rmrk_property(UserProperty(key.as_slice()), &value)?,
+					)?;
+				}
+			}
 
-            Self::deposit_event(
-                Event::PropertySet {
-                    collection_id: rmrk_collection_id,
-                    maybe_nft_id,
-                    key,
-                    value
-                }
-            );
+			Self::deposit_event(Event::PropertySet {
+				collection_id: rmrk_collection_id,
+				maybe_nft_id,
+				key,
+				value,
+			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 	}
 }
 
 impl<T: Config> Pallet<T> {
-    pub fn rmrk_property_key(rmrk_key: RmrkProperty) -> Result<PropertyKey, DispatchError> {
-        let key = rmrk_key.to_key::<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)?;
+		let scoped_key = PropertyScope::Rmrk
+			.apply(key)
+			.map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)?;
 
-        Ok(scoped_key)
-    }
+		Ok(scoped_key)
+	}
 
-    pub fn rmrk_property<E: Encode>(rmrk_key: RmrkProperty, value: &E) -> Result<Property, DispatchError> {
-        let key = rmrk_key.to_key::<T>()?;
+	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 value = value
+			.encode()
+			.try_into()
+			.map_err(|_| <Error<T>>::RmrkPropertyValueIsTooLong)?;
 
-        let property = Property {
-            key,
-            value,
-        };
+		let property = Property { key, value };
 
-        Ok(property)
-    }
+		Ok(property)
+	}
 
-    pub fn create_nft(
-        sender: &T::CrossAccountId,
-        owner: &T::CrossAccountId,
-        collection: &NonfungibleHandle<T>,
-        nft_type: NftType,
-        properties: impl Iterator<Item=Property>
-    ) -> Result<TokenId, DispatchError> {
-        todo!("store nft type");
-        let data = CreateNftExData {
-            properties: BoundedVec::default(),
-            owner: owner.clone(),
-        };
+	pub fn create_nft(
+		sender: &T::CrossAccountId,
+		owner: &T::CrossAccountId,
+		collection: &NonfungibleHandle<T>,
+		nft_type: NftType,
+		properties: impl Iterator<Item = Property>,
+	) -> Result<TokenId, DispatchError> {
+		todo!("store nft type");
+		let data = CreateNftExData {
+			properties: BoundedVec::default(),
+			owner: owner.clone(),
+		};
 
-        let budget = budget::Value::new(2);
+		let budget = budget::Value::new(2);
 
-        <PalletNft<T>>::create_item(
-            collection,
-            sender,
-            data,
-            &budget,
-        )?;
+		<PalletNft<T>>::create_item(collection, sender, data, &budget)?;
 
-        let nft_id = <PalletNft<T>>::current_token_id(collection.id);
+		let nft_id = <PalletNft<T>>::current_token_id(collection.id);
 
-        <PalletNft<T>>::set_scoped_token_properties(
-            collection.id,
-            nft_id,
-            PropertyScope::Rmrk,
-            properties
-        )?;
+		<PalletNft<T>>::set_scoped_token_properties(
+			collection.id,
+			nft_id,
+			PropertyScope::Rmrk,
+			properties,
+		)?;
 
-        Ok(nft_id)
-    }
+		Ok(nft_id)
+	}
 
-    fn destroy_nft(
-        sender: T::CrossAccountId,
-        collection_id: CollectionId,
-        collection_type: misc::CollectionType,
-        token_id: TokenId
-    ) -> DispatchResult {
-        let collection = Self::get_typed_nft_collection(
-            collection_id,
-            collection_type
-        )?;
+	fn destroy_nft(
+		sender: T::CrossAccountId,
+		collection_id: CollectionId,
+		collection_type: misc::CollectionType,
+		token_id: TokenId,
+	) -> DispatchResult {
+		let collection = Self::get_typed_nft_collection(collection_id, collection_type)?;
 
-        <PalletNft<T>>::burn(&collection, &sender, token_id)
-            .map_err(Self::map_common_err_to_proxy)?;
+		<PalletNft<T>>::burn(&collection, &sender, token_id)
+			.map_err(Self::map_common_err_to_proxy)?;
 
-        Ok(())
-    }
+		Ok(())
+	}
 
-    fn change_collection_owner(
-        collection_id: CollectionId,
-        collection_type: misc::CollectionType,
-        sender: T::AccountId,
-        new_owner: T::AccountId,
-    ) -> DispatchResult {
-        let collection = Self::get_typed_nft_collection(
-            collection_id,
-            collection_type
-        )?;
-        Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?;
+	fn change_collection_owner(
+		collection_id: CollectionId,
+		collection_type: misc::CollectionType,
+		sender: T::AccountId,
+		new_owner: T::AccountId,
+	) -> DispatchResult {
+		let collection = Self::get_typed_nft_collection(collection_id, collection_type)?;
+		Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?;
 
-        let mut collection = collection.into_inner();
+		let mut collection = collection.into_inner();
 
-        collection.owner = new_owner;
-        collection.save()
-    }
+		collection.owner = new_owner;
+		collection.save()
+	}
 
-    fn check_collection_owner(collection: &NonfungibleHandle<T>, account: &T::CrossAccountId) -> DispatchResult {
-        collection.check_is_owner(account)
-            .map_err(Self::map_common_err_to_proxy)
-    }
+	fn check_collection_owner(
+		collection: &NonfungibleHandle<T>,
+		account: &T::CrossAccountId,
+	) -> DispatchResult {
+		collection
+			.check_is_owner(account)
+			.map_err(Self::map_common_err_to_proxy)
+	}
 
-    pub fn last_collection_idx() -> RmrkCollectionId {
-        <CollectionIndex<T>>::get()
-    }
+	pub fn last_collection_idx() -> RmrkCollectionId {
+		<CollectionIndex<T>>::get()
+	}
 
-    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)?;
+	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)?;
 
-        match collection.mode {
-            CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)),
-            _ => Err(<Error<T>>::CollectionUnknown.into())
-        }
-    }
+		match collection.mode {
+			CollectionMode::NFT => Ok(NonfungibleHandle::cast(collection)),
+			_ => Err(<Error<T>>::CollectionUnknown.into()),
+		}
+	}
 
-    pub fn collection_exists(collection_id: CollectionId) -> bool {
-        <CollectionHandle<T>>::try_get(collection_id).is_ok()
-    }
+	pub fn collection_exists(collection_id: CollectionId) -> bool {
+		<CollectionHandle<T>>::try_get(collection_id).is_ok()
+	}
 
-    pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool {
-        <TokenData<T>>::contains_key((collection_id, nft_id))
-    }
+	pub fn nft_exists(collection_id: CollectionId, nft_id: TokenId) -> bool {
+		<TokenData<T>>::contains_key((collection_id, nft_id))
+	}
 
-    pub fn get_collection_property(collection_id: CollectionId, key: RmrkProperty) -> Result<PropertyValue, DispatchError> {
-        let collection_property = <PalletCommon<T>>::collection_properties(collection_id)
-            .get(&Self::rmrk_property_key(key)?)
-            .ok_or(<Error<T>>::CollectionUnknown)?
-            .clone();
+	pub fn get_collection_property(
+		collection_id: CollectionId,
+		key: RmrkProperty,
+	) -> Result<PropertyValue, DispatchError> {
+		let collection_property = <PalletCommon<T>>::collection_properties(collection_id)
+			.get(&Self::rmrk_property_key(key)?)
+			.ok_or(<Error<T>>::CollectionUnknown)?
+			.clone();
 
-        Ok(collection_property)
-    }
+		Ok(collection_property)
+	}
 
-    pub fn get_collection_type(collection_id: CollectionId) -> Result<misc::CollectionType, DispatchError> {
-        let value = Self::get_collection_property(collection_id, CollectionType)?;
+	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();
+		let mut value = value.as_slice();
 
-        misc::CollectionType::decode(&mut value)
-            .map_err(|_| <Error<T>>::CorruptedCollectionType.into())
-    }
+		misc::CollectionType::decode(&mut value)
+			.map_err(|_| <Error<T>>::CorruptedCollectionType.into())
+	}
 
-    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);
+	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
+		);
 
-        Ok(())
-    }
+		Ok(())
+	}
 
-    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(&Self::rmrk_property_key(key)?)
-            .ok_or(<Error<T>>::NoAvailableNftId)?
-            .clone();
+	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(&Self::rmrk_property_key(key)?)
+			.ok_or(<Error<T>>::NoAvailableNftId)?
+			.clone();
 
-        Ok(nft_property)
-    }
+		Ok(nft_property)
+	}
 
-    pub fn get_nft_type(_collection_id: CollectionId, _token_id: TokenId) -> Result<NftType, DispatchError> {
-        todo!("should get it from properties?")
-    }
+	pub fn get_nft_type(
+		_collection_id: CollectionId,
+		_token_id: TokenId,
+	) -> Result<NftType, DispatchError> {
+		todo!("should get it from properties?")
+	}
 
-    pub fn ensure_nft_type(collection_id: CollectionId, token_id: TokenId, nft_type: NftType) -> DispatchResult {
-        let actual_type = Self::get_nft_type(collection_id, token_id)?;
-        ensure!(actual_type == nft_type, <Error<T>>::NoPermission);
+	pub fn ensure_nft_type(
+		collection_id: CollectionId,
+		token_id: TokenId,
+		nft_type: NftType,
+	) -> DispatchResult {
+		let actual_type = Self::get_nft_type(collection_id, token_id)?;
+		ensure!(actual_type == nft_type, <Error<T>>::NoPermission);
 
-        Ok(())
-    }
+		Ok(())
+	}
 
-    pub fn ensure_nft_owner(
-        collection_id: CollectionId,
-        token_id: TokenId,
-        possible_owner: &T::CrossAccountId
-    ) -> DispatchResult {
-        let token_data = <TokenData<T>>::get((collection_id, token_id))
-            .ok_or(<Error<T>>::NoAvailableNftId)?;
+	pub fn ensure_nft_owner(
+		collection_id: CollectionId,
+		token_id: TokenId,
+		possible_owner: &T::CrossAccountId,
+	) -> DispatchResult {
+		let token_data =
+			<TokenData<T>>::get((collection_id, token_id)).ok_or(<Error<T>>::NoAvailableNftId)?;
 
-        ensure!(token_data.owner == *possible_owner, <Error<T>>::NoPermission);
+		ensure!(
+			token_data.owner == *possible_owner,
+			<Error<T>>::NoPermission
+		);
 
-        Ok(())
-    }
+		Ok(())
+	}
 
-    pub fn filter_user_properties<Key, Value, R, Mapper>(
-        collection_id: CollectionId,
-        token_id: Option<TokenId>,
-        filter_keys: Option<Vec<RmrkPropertyKey>>,
-        mapper: Mapper,
-    ) -> Result<Vec<R>, DispatchError>
-    where
-        Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,
-        Value: Decode + Default,
-        Mapper: Fn(Key, Value) -> R
-    {
-        filter_keys.map(|keys| {
-            let properties = keys.into_iter()
-                .filter_map(|key| {
-                    let key: Key = key.try_into().ok()?;
+	pub fn filter_user_properties<Key, Value, R, Mapper>(
+		collection_id: CollectionId,
+		token_id: Option<TokenId>,
+		filter_keys: Option<Vec<RmrkPropertyKey>>,
+		mapper: Mapper,
+	) -> Result<Vec<R>, DispatchError>
+	where
+		Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,
+		Value: Decode + Default,
+		Mapper: Fn(Key, Value) -> R,
+	{
+		filter_keys
+			.map(|keys| {
+				let properties = keys
+					.into_iter()
+					.filter_map(|key| {
+						let key: Key = key.try_into().ok()?;
 
-                    let value = match token_id {
-                        Some(token_id) => Self::get_nft_property(
-                            collection_id,
-                            token_id,
-                            UserProperty(key.as_ref())
-                        ),
-                        None => Self::get_collection_property(
-                            collection_id,
-                            UserProperty(key.as_ref())
-                        )
-                    }.ok()?.decode_or_default();
+						let value = match token_id {
+							Some(token_id) => Self::get_nft_property(
+								collection_id,
+								token_id,
+								UserProperty(key.as_ref()),
+							),
+							None => Self::get_collection_property(
+								collection_id,
+								UserProperty(key.as_ref()),
+							),
+						}
+						.ok()?
+						.decode_or_default();
 
-                    Some(mapper(key, value))
-                })
-                .collect();
+						Some(mapper(key, value))
+					})
+					.collect();
 
-            Ok(properties)
-        }).unwrap_or_else(|| {
-            let properties = Self::iterate_user_properties(collection_id, token_id, mapper)?
-                .collect();
+				Ok(properties)
+			})
+			.unwrap_or_else(|| {
+				let properties =
+					Self::iterate_user_properties(collection_id, token_id, mapper)?.collect();
 
-            Ok(properties)
-        })
-    }
+				Ok(properties)
+			})
+	}
 
-    pub fn iterate_user_properties<Key, Value, R, Mapper>(
-        collection_id: CollectionId,
-        token_id: Option<TokenId>,
-        mapper: Mapper,
-    ) -> Result<impl Iterator<Item=R>, DispatchError>
-    where
-        Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,
-        Value: Decode + Default,
-        Mapper: Fn(Key, Value) -> R
-    {
-        let key_prefix = Self::rmrk_property_key(UserProperty(b""))?;
+	pub fn iterate_user_properties<Key, Value, R, Mapper>(
+		collection_id: CollectionId,
+		token_id: Option<TokenId>,
+		mapper: Mapper,
+	) -> Result<impl Iterator<Item = R>, DispatchError>
+	where
+		Key: TryFrom<RmrkPropertyKey> + AsRef<[u8]>,
+		Value: Decode + Default,
+		Mapper: Fn(Key, Value) -> R,
+	{
+		let key_prefix = Self::rmrk_property_key(UserProperty(b""))?;
 
-        let properties = match token_id {
-            Some(token_id) => <PalletNft<T>>::token_properties((collection_id, token_id)),
-            None => <PalletCommon<T>>::collection_properties(collection_id)
-        };
+		let properties = match token_id {
+			Some(token_id) => <PalletNft<T>>::token_properties((collection_id, token_id)),
+			None => <PalletCommon<T>>::collection_properties(collection_id),
+		};
 
-        let properties = properties
-            .into_iter()
-            .filter_map(move |(key, value)| {
-                let key = key.as_slice().strip_prefix(key_prefix.as_slice())?;
+		let properties = properties.into_iter().filter_map(move |(key, value)| {
+			let key = key.as_slice().strip_prefix(key_prefix.as_slice())?;
 
-                let key: Key = key.to_vec().try_into().ok()?;
-                let value: Value = value.decode_or_default();
+			let key: Key = key.to_vec().try_into().ok()?;
+			let value: Value = value.decode_or_default();
 
-                Some(mapper(key, value))
-            });
+			Some(mapper(key, value))
+		});
 
-        Ok(properties)
-    }
+		Ok(properties)
+	}
 
-    pub fn get_typed_nft_collection(
-        collection_id: CollectionId,
-        collection_type: misc::CollectionType
-    ) -> Result<NonfungibleHandle<T>, DispatchError> {
-        Self::ensure_collection_type(collection_id, collection_type)?;
+	pub fn get_typed_nft_collection(
+		collection_id: CollectionId,
+		collection_type: misc::CollectionType,
+	) -> Result<NonfungibleHandle<T>, DispatchError> {
+		Self::ensure_collection_type(collection_id, collection_type)?;
 
-        Self::get_nft_collection(collection_id)
-    }
+		Self::get_nft_collection(collection_id)
+	}
 
-    fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {
-        map_common_err_to_proxy! {
-            match err {
-                NoPermission => NoPermission,
-                CollectionTokenLimitExceeded => CollectionFullOrLocked,
-                PublicMintingNotAllowed => NoPermission,
-                TokenNotFound => NoAvailableNftId
-            }
-        }
-    }
+	fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {
+		map_common_err_to_proxy! {
+			match err {
+				NoPermission => NoPermission,
+				CollectionTokenLimitExceeded => CollectionFullOrLocked,
+				PublicMintingNotAllowed => NoPermission,
+				TokenNotFound => NoAvailableNftId
+			}
+		}
+	}
 }
modifiedpallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/misc.rs
+++ b/pallets/proxy-rmrk-core/src/misc.rs
@@ -15,41 +15,42 @@
 }
 
 pub trait RmrkDecode<T: Decode + Default, S> {
-    fn decode_or_default(&self) -> T;
+	fn decode_or_default(&self) -> T;
 }
 
 impl<T: Decode + Default, S> RmrkDecode<T, S> for BoundedVec<u8, S> {
-    fn decode_or_default(&self) -> T {
-        let mut value = self.as_slice();
+	fn decode_or_default(&self) -> T {
+		let mut value = self.as_slice();
 
-        T::decode(&mut value).unwrap_or_default()
-    }
+		T::decode(&mut value).unwrap_or_default()
+	}
 }
 
 pub trait RmrkRebind<T, S> {
-    fn rebind(&self) -> BoundedVec<u8, S>;
+	fn rebind(&self) -> BoundedVec<u8, S>;
 }
 
-impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T> where BoundedVec<u8, S>: TryFrom<Vec<u8>> {
-    fn rebind(&self) -> BoundedVec<u8, S> {
-        BoundedVec::<u8, S>::try_from(
-            self.clone().into_inner()
-        ).unwrap_or_default()
-    }
+impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>
+where
+	BoundedVec<u8, S>: TryFrom<Vec<u8>>,
+{
+	fn rebind(&self) -> BoundedVec<u8, S> {
+		BoundedVec::<u8, S>::try_from(self.clone().into_inner()).unwrap_or_default()
+	}
 }
 
 #[derive(Encode, Decode, PartialEq, Eq)]
 pub enum CollectionType {
-    Regular,
-    Resource,
-    Base,
+	Regular,
+	Resource,
+	Base,
 }
 
 #[derive(Encode, Decode, PartialEq, Eq)]
 pub enum NftType {
-    Regular,
-    Resource,
-    FixedPart,
-    SlotPart,
-    Theme
+	Regular,
+	Resource,
+	FixedPart,
+	SlotPart,
+	Theme,
 }
modifiedpallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/property.rs
+++ b/pallets/proxy-rmrk-core/src/property.rs
@@ -2,38 +2,38 @@
 use core::convert::AsRef;
 
 pub enum RmrkProperty<'r> {
-    Metadata,
-    CollectionType,
-    RoyaltyInfo,
-    Equipped,
-    ResourceCollection,
-    ResourcePriorities,
-    ResourceType,
-    PendingResourceAccept,
-    PendingResourceRemoval,
-    Parts,
-    Base,
-    Src,
-    Slot,
-    License,
-    Thumb,
-    EquippedNft,
-    BaseType,
-    ExternalPartId,
-    EquippableList,
-    ZIndex,
-    ThemeName,
-    ThemeInherit,
-    UserProperty(&'r [u8]),
+	Metadata,
+	CollectionType,
+	RoyaltyInfo,
+	Equipped,
+	ResourceCollection,
+	ResourcePriorities,
+	ResourceType,
+	PendingResourceAccept,
+	PendingResourceRemoval,
+	Parts,
+	Base,
+	Src,
+	Slot,
+	License,
+	Thumb,
+	EquippedNft,
+	BaseType,
+	ExternalPartId,
+	EquippableList,
+	ZIndex,
+	ThemeName,
+	ThemeInherit,
+	UserProperty(&'r [u8]),
 }
 
 impl<'r> RmrkProperty<'r> {
-    pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {
-        fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {
-            container.as_ref()
-        }
+	pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {
+		fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {
+			container.as_ref()
+		}
 
-        macro_rules! key {
+		macro_rules! key {
             ($($component:expr),+) => {
                 PropertyKey::try_from([$(key!(@ &$component)),+].concat())
                     .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)
@@ -44,30 +44,30 @@
             };
         }
 
-        match self {
-            Self::Metadata => key!("metadata"),
-            Self::CollectionType => key!("collection-type"),
-            Self::RoyaltyInfo => key!("royalty-info"),
-            Self::Equipped => key!("equipped"),
-            Self::ResourceCollection => key!("resource-collection"),
-            Self::ResourcePriorities => key!("resource-priorities"),
-            Self::ResourceType => key!("resource-type"),
-            Self::PendingResourceAccept => key!("pending-accept"),
-            Self::PendingResourceRemoval => key!("pending-removal"),
-            Self::Parts => key!("parts"),
-            Self::Base => key!("base"),
-            Self::Src => key!("src"),
-            Self::Slot => key!("slot"),
-            Self::License => key!("license"),
-            Self::Thumb => key!("thumb"),
-            Self::EquippedNft => key!("equipped-nft"),
-            Self::BaseType => key!("base-type"),
-            Self::ExternalPartId => key!("ext-part-id"),
-            Self::EquippableList => key!("equippable-list"),
-            Self::ZIndex => key!("z-index"),
-            Self::ThemeName => key!("theme-name"),
-            Self::ThemeInherit => key!("theme-inherit"),
-            Self::UserProperty(name) => key!("userprop-", name),
-        }
-    }
+		match self {
+			Self::Metadata => key!("metadata"),
+			Self::CollectionType => key!("collection-type"),
+			Self::RoyaltyInfo => key!("royalty-info"),
+			Self::Equipped => key!("equipped"),
+			Self::ResourceCollection => key!("resource-collection"),
+			Self::ResourcePriorities => key!("resource-priorities"),
+			Self::ResourceType => key!("resource-type"),
+			Self::PendingResourceAccept => key!("pending-accept"),
+			Self::PendingResourceRemoval => key!("pending-removal"),
+			Self::Parts => key!("parts"),
+			Self::Base => key!("base"),
+			Self::Src => key!("src"),
+			Self::Slot => key!("slot"),
+			Self::License => key!("license"),
+			Self::Thumb => key!("thumb"),
+			Self::EquippedNft => key!("equipped-nft"),
+			Self::BaseType => key!("base-type"),
+			Self::ExternalPartId => key!("ext-part-id"),
+			Self::EquippableList => key!("equippable-list"),
+			Self::ZIndex => key!("z-index"),
+			Self::ThemeName => key!("theme-name"),
+			Self::ThemeInherit => key!("theme-inherit"),
+			Self::UserProperty(name) => key!("userprop-", name),
+		}
+	}
 }
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -21,7 +21,11 @@
 use sp_runtime::DispatchError;
 use up_data_structs::*;
 use pallet_common::{Pallet as PalletCommon, Error as CommonError};
-use pallet_rmrk_core::{Pallet as PalletCore, misc::{self, *}, property::RmrkProperty::*};
+use pallet_rmrk_core::{
+	Pallet as PalletCore,
+	misc::{self, *},
+	property::RmrkProperty::*,
+};
 use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};
 use pallet_evm::account::CrossAccountId;
 
@@ -29,212 +33,206 @@
 
 #[frame_support::pallet]
 pub mod pallet {
-    use super::*;
+	use super::*;
 
 	#[pallet::config]
-	pub trait Config: frame_system::Config
-                    + pallet_rmrk_core::Config {
+	pub trait Config: frame_system::Config + pallet_rmrk_core::Config {
 		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
 	}
 
-    #[pallet::storage]
+	#[pallet::storage]
 	#[pallet::getter(fn internal_part_id)]
-	pub type InernalPartId<T: Config> = StorageDoubleMap<
-        _,
-        Twox64Concat,
-        CollectionId,
-        Twox64Concat,
-        RmrkPartId,
-        TokenId
-    >;
+	pub type InernalPartId<T: Config> =
+		StorageDoubleMap<_, Twox64Concat, CollectionId, Twox64Concat, RmrkPartId, TokenId>;
 
-    #[pallet::storage]
+	#[pallet::storage]
 	#[pallet::getter(fn base_has_default_theme)]
-    pub type BaseHasDefaultTheme<T: Config> = StorageMap<
-        _,
-        Twox64Concat,
-        CollectionId,
-        bool,
-        ValueQuery
-    >;
+	pub type BaseHasDefaultTheme<T: Config> =
+		StorageMap<_, Twox64Concat, CollectionId, bool, ValueQuery>;
 
-    #[pallet::pallet]
+	#[pallet::pallet]
 	#[pallet::generate_store(pub(super) trait Store)]
 	pub struct Pallet<T>(_);
 
 	#[pallet::event]
 	#[pallet::generate_deposit(pub(super) fn deposit_event)]
 	pub enum Event<T: Config> {
-        BaseCreated {
+		BaseCreated {
 			issuer: T::AccountId,
 			base_id: RmrkBaseId,
 		},
-    }
+	}
 
-    #[pallet::error]
+	#[pallet::error]
 	pub enum Error<T> {
-        PermissionError,
-        NoAvailableBaseId,
-        NoAvailablePartId,
-        BaseDoesntExist,
-        NeedsDefaultThemeFirst,
-    }
+		PermissionError,
+		NoAvailableBaseId,
+		NoAvailablePartId,
+		BaseDoesntExist,
+		NeedsDefaultThemeFirst,
+	}
 
-    #[pallet::call]
+	#[pallet::call]
 	impl<T: Config> Pallet<T> {
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
-        #[transactional]
+		#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
+		#[transactional]
 		pub fn create_base(
 			origin: OriginFor<T>,
 			base_type: RmrkString,
 			symbol: RmrkString,
 			parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,
 		) -> DispatchResult {
-            let sender = ensure_signed(origin)?;
-            let cross_sender = T::CrossAccountId::from_sub(sender.clone());
+			let sender = ensure_signed(origin)?;
+			let cross_sender = T::CrossAccountId::from_sub(sender.clone());
 
-            let data = CreateCollectionData {
-                limits: None,
-                token_prefix: symbol.into_inner()
-                    .try_into()
-                    .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
-                ..Default::default()
-            };
+			let data = CreateCollectionData {
+				limits: None,
+				token_prefix: symbol
+					.into_inner()
+					.try_into()
+					.map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,
+				..Default::default()
+			};
 
-            let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
+			let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);
 
-            if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
-                return Err(<Error<T>>::NoAvailableBaseId.into());
-            }
+			if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {
+				return Err(<Error<T>>::NoAvailableBaseId.into());
+			}
 
-            let collection_id = collection_id_res?;
+			let collection_id = collection_id_res?;
 
-            <PalletCommon<T>>::set_scoped_collection_properties(
-                collection_id,
-                PropertyScope::Rmrk,
-                [
-                    <PalletCore<T>>::rmrk_property(CollectionType, &misc::CollectionType::Base)?,
-                    <PalletCore<T>>::rmrk_property(BaseType, &base_type)?,
-                ].into_iter()
-            )?;
+			<PalletCommon<T>>::set_scoped_collection_properties(
+				collection_id,
+				PropertyScope::Rmrk,
+				[
+					<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)?;
+			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(
-                    &cross_sender,
-                    &collection,
-                    part
-                )?;
+			for part in parts {
+				let part_id = part.id();
+				let part_token_id = Self::create_part(&cross_sender, &collection, part)?;
 
-                <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);
+				<InernalPartId<T>>::insert(collection_id, part_id, part_token_id);
 
-                <PalletNft<T>>::set_scoped_token_property(
-                    collection_id,
-                    part_token_id,
-                    PropertyScope::Rmrk,
-                    <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?
-                )?;
-            }
+				<PalletNft<T>>::set_scoped_token_property(
+					collection_id,
+					part_token_id,
+					PropertyScope::Rmrk,
+					<PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?,
+				)?;
+			}
 
-            Self::deposit_event(Event::BaseCreated { issuer: sender, base_id: collection_id.0 });
+			Self::deposit_event(Event::BaseCreated {
+				issuer: sender,
+				base_id: collection_id.0,
+			});
 
-            Ok(())
-        }
+			Ok(())
+		}
 
-        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
-        #[transactional]
+		#[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 = ensure_signed(origin)?;
 
-            let sender = T::CrossAccountId::from_sub(sender);
-            let owner = &sender;
+			let sender = T::CrossAccountId::from_sub(sender);
+			let owner = &sender;
 
-            let collection_id: CollectionId = base_id.into();
+			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)?;
+			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());
-            }
+			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)?;
+			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(
-                        UserProperty(property.key.as_slice()),
-                        &property.value
-                    )?
-                )?;
-            }
+			for property in theme.properties {
+				<PalletNft<T>>::set_scoped_token_property(
+					collection_id,
+					token_id,
+					PropertyScope::Rmrk,
+					<PalletCore<T>>::rmrk_property(
+						UserProperty(property.key.as_slice()),
+						&property.value,
+					)?,
+				)?;
+			}
 
-            Ok(())
-        }
-    }
+			Ok(())
+		}
+	}
 }
 
 impl<T: Config> Pallet<T> {
-    fn create_part(
-        sender: &T::CrossAccountId,
-        collection: &NonfungibleHandle<T>,
-        part: RmrkPartType
-    ) -> Result<TokenId, DispatchError> {
-        let owner = sender;
+	fn create_part(
+		sender: &T::CrossAccountId,
+		collection: &NonfungibleHandle<T>,
+		part: RmrkPartType,
+	) -> Result<TokenId, DispatchError> {
+		let owner = sender;
 
-        let src = part.src();
-        let z_index = part.z_index();
+		let src = part.src();
+		let z_index = part.z_index();
 
-        let nft_type = match part {
-            RmrkPartType::FixedPart(_) => NftType::FixedPart,
-            RmrkPartType::SlotPart(_) => NftType::SlotPart,
-        };
+		let nft_type = match part {
+			RmrkPartType::FixedPart(_) => NftType::FixedPart,
+			RmrkPartType::SlotPart(_) => NftType::SlotPart,
+		};
 
-        let token_id = <PalletCore<T>>::create_nft(
-            sender,
-            owner,
-            collection,
-            nft_type,
-            [
-                <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
-        })?;
+		let token_id = <PalletCore<T>>::create_nft(
+			sender,
+			owner,
+			collection,
+			nft_type,
+			[
+				<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.id,
-                token_id,
-                PropertyScope::Rmrk,
-                <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?
-            )?;
-        }
+		if let RmrkPartType::SlotPart(part) = part {
+			<PalletNft<T>>::set_scoped_token_property(
+				collection.id,
+				token_id,
+				PropertyScope::Rmrk,
+				<PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?,
+			)?;
+		}
 
-        Ok(token_id)
-    }
+		Ok(token_id)
+	}
 }
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -313,17 +313,9 @@
 		fail!(<Error<T>>::RefungibleDisallowsNesting)
 	}
 
-	fn nest(
-		&self,
-		_under: TokenId,
-		_to_nest: (CollectionId, TokenId)
-	) {}
+	fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}
 
-	fn unnest(
-		&self,
-		_under: TokenId,
-		_to_nest: (CollectionId, TokenId)
-	) {}
+	fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}
 
 	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
 		<Owned<T>>::iter_prefix((self.id, account))
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
before · pallets/refungible/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::{ensure, BoundedVec};20use up_data_structs::{21	AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,22	CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,23};24use pallet_evm::account::CrossAccountId;25use pallet_common::{26	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,27};28use pallet_structure::Pallet as PalletStructure;29use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};30use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};31use core::ops::Deref;32use codec::{Encode, Decode, MaxEncodedLen};33use scale_info::TypeInfo;3435pub use pallet::*;36#[cfg(feature = "runtime-benchmarks")]37pub mod benchmarking;38pub mod common;39pub mod erc;40pub mod weights;41pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;4243#[struct_versioning::versioned(version = 2, upper)]44#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]45pub struct ItemData {46	pub const_data: BoundedVec<u8, CustomDataLimit>,4748	#[version(..2)]49	pub variable_data: BoundedVec<u8, CustomDataLimit>,50}5152#[frame_support::pallet]53pub mod pallet {54	use super::*;55	use frame_support::{56		Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key,57		traits::StorageVersion,58	};59	use frame_system::pallet_prelude::*;60	use up_data_structs::{CollectionId, TokenId};61	use super::weights::WeightInfo;6263	#[pallet::error]64	pub enum Error<T> {65		/// Not Refungible item data used to mint in Refungible collection.66		NotRefungibleDataUsedToMintFungibleCollectionToken,67		/// Maximum refungibility exceeded68		WrongRefungiblePieces,69		/// Refungible token can't nest other tokens70		RefungibleDisallowsNesting,71		/// Setting item properties is not allowed72		SettingPropertiesNotAllowed,73	}7475	#[pallet::config]76	pub trait Config:77		frame_system::Config + pallet_common::Config + pallet_structure::Config78	{79		type WeightInfo: WeightInfo;80	}8182	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);8384	#[pallet::pallet]85	#[pallet::storage_version(STORAGE_VERSION)]86	#[pallet::generate_store(pub(super) trait Store)]87	pub struct Pallet<T>(_);8889	#[pallet::storage]90	pub type TokensMinted<T: Config> =91		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;92	#[pallet::storage]93	pub type TokensBurnt<T: Config> =94		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;9596	#[pallet::storage]97	pub type TokenData<T: Config> = StorageNMap<98		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),99		Value = ItemData,100		QueryKind = ValueQuery,101	>;102103	#[pallet::storage]104	pub type TotalSupply<T: Config> = StorageNMap<105		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),106		Value = u128,107		QueryKind = ValueQuery,108	>;109110	/// Used to enumerate tokens owned by account111	#[pallet::storage]112	pub type Owned<T: Config> = StorageNMap<113		Key = (114			Key<Twox64Concat, CollectionId>,115			Key<Blake2_128Concat, T::CrossAccountId>,116			Key<Twox64Concat, TokenId>,117		),118		Value = bool,119		QueryKind = ValueQuery,120	>;121122	#[pallet::storage]123	pub type AccountBalance<T: Config> = StorageNMap<124		Key = (125			Key<Twox64Concat, CollectionId>,126			// Owner127			Key<Blake2_128Concat, T::CrossAccountId>,128		),129		Value = u32,130		QueryKind = ValueQuery,131	>;132133	#[pallet::storage]134	pub type Balance<T: Config> = StorageNMap<135		Key = (136			Key<Twox64Concat, CollectionId>,137			Key<Twox64Concat, TokenId>,138			// Owner139			Key<Blake2_128Concat, T::CrossAccountId>,140		),141		Value = u128,142		QueryKind = ValueQuery,143	>;144145	#[pallet::storage]146	pub type Allowance<T: Config> = StorageNMap<147		Key = (148			Key<Twox64Concat, CollectionId>,149			Key<Twox64Concat, TokenId>,150			// Owner151			Key<Blake2_128, T::CrossAccountId>,152			// Spender153			Key<Blake2_128Concat, T::CrossAccountId>,154		),155		Value = u128,156		QueryKind = ValueQuery,157	>;158159	#[pallet::hooks]160	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {161		fn on_runtime_upgrade() -> Weight {162			if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {163				<TokenData<T>>::translate_values::<ItemDataVersion1, _>(|v| {164					Some(<ItemDataVersion2>::from(v))165				})166			}167168			0169		}170	}171}172173pub struct RefungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);174impl<T: Config> RefungibleHandle<T> {175	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {176		Self(inner)177	}178	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {179		self.0180	}181}182impl<T: Config> Deref for RefungibleHandle<T> {183	type Target = pallet_common::CollectionHandle<T>;184185	fn deref(&self) -> &Self::Target {186		&self.0187	}188}189190impl<T: Config> Pallet<T> {191	pub fn total_supply(collection: &RefungibleHandle<T>) -> u32 {192		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)193	}194	pub fn token_exists(collection: &RefungibleHandle<T>, token: TokenId) -> bool {195		<TotalSupply<T>>::contains_key((collection.id, token))196	}197}198199// unchecked calls skips any permission checks200impl<T: Config> Pallet<T> {201	pub fn init_collection(202		owner: T::AccountId,203		data: CreateCollectionData<T::AccountId>,204	) -> Result<CollectionId, DispatchError> {205		<PalletCommon<T>>::init_collection(owner, data)206	}207	pub fn destroy_collection(208		collection: RefungibleHandle<T>,209		sender: &T::CrossAccountId,210	) -> DispatchResult {211		let id = collection.id;212213		if Self::collection_has_tokens(id) {214			return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());215		}216217		// =========218219		PalletCommon::destroy_collection(collection.0, sender)?;220221		<TokensMinted<T>>::remove(id);222		<TokensBurnt<T>>::remove(id);223		<TokenData<T>>::remove_prefix((id,), None);224		<TotalSupply<T>>::remove_prefix((id,), None);225		<Balance<T>>::remove_prefix((id,), None);226		<Allowance<T>>::remove_prefix((id,), None);227		<Owned<T>>::remove_prefix((id,), None);228		<AccountBalance<T>>::remove_prefix((id,), None);229		Ok(())230	}231232	fn collection_has_tokens(collection_id: CollectionId) -> bool {233		<TokenData<T>>::iter_prefix((collection_id,)).next().is_some()234	}235236	pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {237		let burnt = <TokensBurnt<T>>::get(collection.id)238			.checked_add(1)239			.ok_or(ArithmeticError::Overflow)?;240241		<TokensBurnt<T>>::insert(collection.id, burnt);242		<TokenData<T>>::remove((collection.id, token_id));243		<TotalSupply<T>>::remove((collection.id, token_id));244		<Balance<T>>::remove_prefix((collection.id, token_id), None);245		<Allowance<T>>::remove_prefix((collection.id, token_id), None);246		// TODO: ERC721 transfer event247		Ok(())248	}249250	pub fn burn(251		collection: &RefungibleHandle<T>,252		owner: &T::CrossAccountId,253		token: TokenId,254		amount: u128,255	) -> DispatchResult {256		let total_supply = <TotalSupply<T>>::get((collection.id, token))257			.checked_sub(amount)258			.ok_or(<CommonError<T>>::TokenValueTooLow)?;259260		// This was probally last owner of this token?261		if total_supply == 0 {262			// Ensure user actually owns this amount263			ensure!(264				<Balance<T>>::get((collection.id, token, owner)) == amount,265				<CommonError<T>>::TokenValueTooLow266			);267			let account_balance = <AccountBalance<T>>::get((collection.id, owner))268				.checked_sub(1)269				// Should not occur270				.ok_or(ArithmeticError::Underflow)?;271272			// =========273274			<Owned<T>>::remove((collection.id, owner, token));275			<PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);276			<AccountBalance<T>>::insert((collection.id, owner), account_balance);277			Self::burn_token(collection, token)?;278			<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(279				collection.id,280				token,281				owner.clone(),282				amount,283			));284			return Ok(());285		}286287		let balance = <Balance<T>>::get((collection.id, token, owner))288			.checked_sub(amount)289			.ok_or(<CommonError<T>>::TokenValueTooLow)?;290		let account_balance = if balance == 0 {291			<AccountBalance<T>>::get((collection.id, owner))292				.checked_sub(1)293				// Should not occur294				.ok_or(ArithmeticError::Underflow)?295		} else {296			0297		};298299		// =========300301		if balance == 0 {302			<Owned<T>>::remove((collection.id, owner, token));303			<PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);304			<Balance<T>>::remove((collection.id, token, owner));305			<AccountBalance<T>>::insert((collection.id, owner), account_balance);306		} else {307			<Balance<T>>::insert((collection.id, token, owner), balance);308		}309		<TotalSupply<T>>::insert((collection.id, token), total_supply);310		// TODO: ERC20 transfer event311		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(312			collection.id,313			token,314			owner.clone(),315			amount,316		));317		Ok(())318	}319320	pub fn transfer(321		collection: &RefungibleHandle<T>,322		from: &T::CrossAccountId,323		to: &T::CrossAccountId,324		token: TokenId,325		amount: u128,326		nesting_budget: &dyn Budget,327	) -> DispatchResult {328		ensure!(329			collection.limits.transfers_enabled(),330			<CommonError<T>>::TransferNotAllowed331		);332333		if collection.permissions.access() == AccessMode::AllowList {334			collection.check_allowlist(from)?;335			collection.check_allowlist(to)?;336		}337		<PalletCommon<T>>::ensure_correct_receiver(to)?;338339		let balance_from = <Balance<T>>::get((collection.id, token, from))340			.checked_sub(amount)341			.ok_or(<CommonError<T>>::TokenValueTooLow)?;342		let mut create_target = false;343		let from_to_differ = from != to;344		let balance_to = if from != to {345			let old_balance = <Balance<T>>::get((collection.id, token, to));346			if old_balance == 0 {347				create_target = true;348			}349			Some(350				old_balance351					.checked_add(amount)352					.ok_or(ArithmeticError::Overflow)?,353			)354		} else {355			None356		};357358		let account_balance_from = if balance_from == 0 {359			Some(360				<AccountBalance<T>>::get((collection.id, from))361					.checked_sub(1)362					// Should not occur363					.ok_or(ArithmeticError::Underflow)?,364			)365		} else {366			None367		};368		// Account data is created in token, AccountBalance should be increased369		// But only if from != to as we shouldn't check overflow in this case370		let account_balance_to = if create_target && from_to_differ {371			let account_balance_to = <AccountBalance<T>>::get((collection.id, to))372				.checked_add(1)373				.ok_or(ArithmeticError::Overflow)?;374			ensure!(375				account_balance_to < collection.limits.account_token_ownership_limit(),376				<CommonError<T>>::AccountTokenLimitExceeded,377			);378379			Some(account_balance_to)380		} else {381			None382		};383384		// =========385386		<PalletStructure<T>>::nest_if_sent_to_token(387			from.clone(),388			to,389			collection.id,390			token,391			nesting_budget392		)?;393394		if let Some(balance_to) = balance_to {395			// from != to396			if balance_from == 0 {397				<Balance<T>>::remove((collection.id, token, from));398				<PalletStructure<T>>::unnest_if_nested(399					from,400					collection.id,401					token402				);403			} else {404				<Balance<T>>::insert((collection.id, token, from), balance_from);405			}406			<Balance<T>>::insert((collection.id, token, to), balance_to);407			if let Some(account_balance_from) = account_balance_from {408				<AccountBalance<T>>::insert((collection.id, from), account_balance_from);409				<Owned<T>>::remove((collection.id, from, token));410			}411			if let Some(account_balance_to) = account_balance_to {412				<AccountBalance<T>>::insert((collection.id, to), account_balance_to);413				<Owned<T>>::insert((collection.id, to, token), true);414			}415		}416417		// TODO: ERC20 transfer event418		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(419			collection.id,420			token,421			from.clone(),422			to.clone(),423			amount,424		));425		Ok(())426	}427428	pub fn create_multiple_items(429		collection: &RefungibleHandle<T>,430		sender: &T::CrossAccountId,431		data: Vec<CreateRefungibleExData<T::CrossAccountId>>,432		nesting_budget: &dyn Budget,433	) -> DispatchResult {434		if !collection.is_owner_or_admin(sender) {435			ensure!(436				collection.permissions.mint_mode(),437				<CommonError<T>>::PublicMintingNotAllowed438			);439			collection.check_allowlist(sender)?;440441			for item in data.iter() {442				for user in item.users.keys() {443					collection.check_allowlist(user)?;444				}445			}446		}447448		for item in data.iter() {449			for (owner, _) in item.users.iter() {450				<PalletCommon<T>>::ensure_correct_receiver(owner)?;451			}452		}453454		// Total pieces per tokens455		let totals = data456			.iter()457			.map(|data| {458				Ok(data459					.users460					.iter()461					.map(|u| u.1)462					.try_fold(0u128, |acc, v| acc.checked_add(*v))463					.ok_or(ArithmeticError::Overflow)?)464			})465			.collect::<Result<Vec<_>, DispatchError>>()?;466		for total in &totals {467			ensure!(468				*total <= MAX_REFUNGIBLE_PIECES,469				<Error<T>>::WrongRefungiblePieces470			);471		}472473		let first_token_id = <TokensMinted<T>>::get(collection.id);474		let tokens_minted = first_token_id475			.checked_add(data.len() as u32)476			.ok_or(ArithmeticError::Overflow)?;477		ensure!(478			tokens_minted < collection.limits.token_limit(),479			<CommonError<T>>::CollectionTokenLimitExceeded480		);481482		let mut balances = BTreeMap::new();483		for data in &data {484			for owner in data.users.keys() {485				let balance = balances486					.entry(owner)487					.or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));488				*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;489490				ensure!(491					*balance <= collection.limits.account_token_ownership_limit(),492					<CommonError<T>>::AccountTokenLimitExceeded,493				);494			}495		}496497		for (i, token) in data.iter().enumerate() {498			let token_id = TokenId(first_token_id + i as u32 + 1);499			for (to, _) in token.users.iter() {500501				<PalletStructure<T>>::check_nesting(502					sender.clone(),503					to,504					collection.id,505					token_id,506					nesting_budget,507				)?;508			}509		}510511		// =========512513		<TokensMinted<T>>::insert(collection.id, tokens_minted);514		for (account, balance) in balances {515			<AccountBalance<T>>::insert((collection.id, account), balance);516		}517		for (i, token) in data.into_iter().enumerate() {518			let token_id = first_token_id + i as u32 + 1;519			<TotalSupply<T>>::insert((collection.id, token_id), totals[i]);520521			<TokenData<T>>::insert(522				(collection.id, token_id),523				ItemData {524					const_data: token.const_data,525				},526			);527528			for (user, amount) in token.users.into_iter() {529				if amount == 0 {530					continue;531				}532				<Balance<T>>::insert((collection.id, token_id, &user), amount);533				<Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);534				<PalletStructure<T>>::nest_if_sent_to_token_unchecked(&user, collection.id, TokenId(token_id));535536				// TODO: ERC20 transfer event537				<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(538					collection.id,539					TokenId(token_id),540					user,541					amount,542				));543			}544		}545		Ok(())546	}547548	pub fn set_allowance_unchecked(549		collection: &RefungibleHandle<T>,550		sender: &T::CrossAccountId,551		spender: &T::CrossAccountId,552		token: TokenId,553		amount: u128,554	) {555		if amount == 0 {556			<Allowance<T>>::remove((collection.id, token, sender, spender));557		} else {558			<Allowance<T>>::insert((collection.id, token, sender, spender), amount);559		}560		// TODO: ERC20 approval event561		<PalletCommon<T>>::deposit_event(CommonEvent::Approved(562			collection.id,563			token,564			sender.clone(),565			spender.clone(),566			amount,567		))568	}569570	pub fn set_allowance(571		collection: &RefungibleHandle<T>,572		sender: &T::CrossAccountId,573		spender: &T::CrossAccountId,574		token: TokenId,575		amount: u128,576	) -> DispatchResult {577		if collection.permissions.access() == AccessMode::AllowList {578			collection.check_allowlist(sender)?;579			collection.check_allowlist(spender)?;580		}581582		<PalletCommon<T>>::ensure_correct_receiver(spender)?;583584		if <Balance<T>>::get((collection.id, token, sender)) < amount {585			ensure!(586				collection.ignores_owned_amount(sender) && Self::token_exists(collection, token),587				<CommonError<T>>::CantApproveMoreThanOwned588			);589		}590591		// =========592593		Self::set_allowance_unchecked(collection, sender, spender, token, amount);594		Ok(())595	}596597	/// Returns allowance, which should be set after transaction598	fn check_allowed(599		collection: &RefungibleHandle<T>,600		spender: &T::CrossAccountId,601		from: &T::CrossAccountId,602		token: TokenId,603		amount: u128,604		nesting_budget: &dyn Budget,605	) -> Result<Option<u128>, DispatchError> {606		if spender.conv_eq(from) {607			return Ok(None);608		}609		if collection.permissions.access() == AccessMode::AllowList {610			// `from`, `to` checked in [`transfer`]611			collection.check_allowlist(spender)?;612		}613		if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {614			// TODO: should collection owner be allowed to perform this transfer?615			ensure!(616				<PalletStructure<T>>::check_indirectly_owned(617					spender.clone(),618					source.0,619					source.1,620					None,621					nesting_budget622				)?,623				<CommonError<T>>::ApprovedValueTooLow,624			);625			return Ok(None);626		}627		let allowance =628			<Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);629		if allowance.is_none() {630			ensure!(631				collection.ignores_allowance(spender),632				<CommonError<T>>::ApprovedValueTooLow633			);634		}635		Ok(allowance)636	}637638	pub fn transfer_from(639		collection: &RefungibleHandle<T>,640		spender: &T::CrossAccountId,641		from: &T::CrossAccountId,642		to: &T::CrossAccountId,643		token: TokenId,644		amount: u128,645		nesting_budget: &dyn Budget,646	) -> DispatchResult {647		let allowance =648			Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;649650		// =========651652		Self::transfer(collection, from, to, token, amount, nesting_budget)?;653		if let Some(allowance) = allowance {654			Self::set_allowance_unchecked(collection, from, spender, token, allowance);655		}656		Ok(())657	}658659	pub fn burn_from(660		collection: &RefungibleHandle<T>,661		spender: &T::CrossAccountId,662		from: &T::CrossAccountId,663		token: TokenId,664		amount: u128,665		nesting_budget: &dyn Budget,666	) -> DispatchResult {667		let allowance =668			Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;669670		// =========671672		Self::burn(collection, from, token, amount)?;673		if let Some(allowance) = allowance {674			Self::set_allowance_unchecked(collection, from, spender, token, allowance);675		}676		Ok(())677	}678679	/// Delegated to `create_multiple_items`680	pub fn create_item(681		collection: &RefungibleHandle<T>,682		sender: &T::CrossAccountId,683		data: CreateRefungibleExData<T::CrossAccountId>,684		nesting_budget: &dyn Budget,685	) -> DispatchResult {686		Self::create_multiple_items(collection, sender, vec![data], nesting_budget)687	}688}
after · pallets/refungible/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::{ensure, BoundedVec};20use up_data_structs::{21	AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,22	CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,23};24use pallet_evm::account::CrossAccountId;25use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon};26use pallet_structure::Pallet as PalletStructure;27use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};28use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};29use core::ops::Deref;30use codec::{Encode, Decode, MaxEncodedLen};31use scale_info::TypeInfo;3233pub use pallet::*;34#[cfg(feature = "runtime-benchmarks")]35pub mod benchmarking;36pub mod common;37pub mod erc;38pub mod weights;39pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;4041#[struct_versioning::versioned(version = 2, upper)]42#[derive(Encode, Decode, Default, TypeInfo, MaxEncodedLen)]43pub struct ItemData {44	pub const_data: BoundedVec<u8, CustomDataLimit>,4546	#[version(..2)]47	pub variable_data: BoundedVec<u8, CustomDataLimit>,48}4950#[frame_support::pallet]51pub mod pallet {52	use super::*;53	use frame_support::{54		Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key,55		traits::StorageVersion,56	};57	use frame_system::pallet_prelude::*;58	use up_data_structs::{CollectionId, TokenId};59	use super::weights::WeightInfo;6061	#[pallet::error]62	pub enum Error<T> {63		/// Not Refungible item data used to mint in Refungible collection.64		NotRefungibleDataUsedToMintFungibleCollectionToken,65		/// Maximum refungibility exceeded66		WrongRefungiblePieces,67		/// Refungible token can't nest other tokens68		RefungibleDisallowsNesting,69		/// Setting item properties is not allowed70		SettingPropertiesNotAllowed,71	}7273	#[pallet::config]74	pub trait Config:75		frame_system::Config + pallet_common::Config + pallet_structure::Config76	{77		type WeightInfo: WeightInfo;78	}7980	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);8182	#[pallet::pallet]83	#[pallet::storage_version(STORAGE_VERSION)]84	#[pallet::generate_store(pub(super) trait Store)]85	pub struct Pallet<T>(_);8687	#[pallet::storage]88	pub type TokensMinted<T: Config> =89		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;90	#[pallet::storage]91	pub type TokensBurnt<T: Config> =92		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u32, QueryKind = ValueQuery>;9394	#[pallet::storage]95	pub type TokenData<T: Config> = StorageNMap<96		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),97		Value = ItemData,98		QueryKind = ValueQuery,99	>;100101	#[pallet::storage]102	pub type TotalSupply<T: Config> = StorageNMap<103		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),104		Value = u128,105		QueryKind = ValueQuery,106	>;107108	/// Used to enumerate tokens owned by account109	#[pallet::storage]110	pub type Owned<T: Config> = StorageNMap<111		Key = (112			Key<Twox64Concat, CollectionId>,113			Key<Blake2_128Concat, T::CrossAccountId>,114			Key<Twox64Concat, TokenId>,115		),116		Value = bool,117		QueryKind = ValueQuery,118	>;119120	#[pallet::storage]121	pub type AccountBalance<T: Config> = StorageNMap<122		Key = (123			Key<Twox64Concat, CollectionId>,124			// Owner125			Key<Blake2_128Concat, T::CrossAccountId>,126		),127		Value = u32,128		QueryKind = ValueQuery,129	>;130131	#[pallet::storage]132	pub type Balance<T: Config> = StorageNMap<133		Key = (134			Key<Twox64Concat, CollectionId>,135			Key<Twox64Concat, TokenId>,136			// Owner137			Key<Blake2_128Concat, T::CrossAccountId>,138		),139		Value = u128,140		QueryKind = ValueQuery,141	>;142143	#[pallet::storage]144	pub type Allowance<T: Config> = StorageNMap<145		Key = (146			Key<Twox64Concat, CollectionId>,147			Key<Twox64Concat, TokenId>,148			// Owner149			Key<Blake2_128, T::CrossAccountId>,150			// Spender151			Key<Blake2_128Concat, T::CrossAccountId>,152		),153		Value = u128,154		QueryKind = ValueQuery,155	>;156157	#[pallet::hooks]158	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {159		fn on_runtime_upgrade() -> Weight {160			if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {161				<TokenData<T>>::translate_values::<ItemDataVersion1, _>(|v| {162					Some(<ItemDataVersion2>::from(v))163				})164			}165166			0167		}168	}169}170171pub struct RefungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);172impl<T: Config> RefungibleHandle<T> {173	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {174		Self(inner)175	}176	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {177		self.0178	}179}180impl<T: Config> Deref for RefungibleHandle<T> {181	type Target = pallet_common::CollectionHandle<T>;182183	fn deref(&self) -> &Self::Target {184		&self.0185	}186}187188impl<T: Config> Pallet<T> {189	pub fn total_supply(collection: &RefungibleHandle<T>) -> u32 {190		<TokensMinted<T>>::get(collection.id) - <TokensBurnt<T>>::get(collection.id)191	}192	pub fn token_exists(collection: &RefungibleHandle<T>, token: TokenId) -> bool {193		<TotalSupply<T>>::contains_key((collection.id, token))194	}195}196197// unchecked calls skips any permission checks198impl<T: Config> Pallet<T> {199	pub fn init_collection(200		owner: T::AccountId,201		data: CreateCollectionData<T::AccountId>,202	) -> Result<CollectionId, DispatchError> {203		<PalletCommon<T>>::init_collection(owner, data)204	}205	pub fn destroy_collection(206		collection: RefungibleHandle<T>,207		sender: &T::CrossAccountId,208	) -> DispatchResult {209		let id = collection.id;210211		if Self::collection_has_tokens(id) {212			return Err(<CommonError<T>>::CantDestroyNotEmptyCollection.into());213		}214215		// =========216217		PalletCommon::destroy_collection(collection.0, sender)?;218219		<TokensMinted<T>>::remove(id);220		<TokensBurnt<T>>::remove(id);221		<TokenData<T>>::remove_prefix((id,), None);222		<TotalSupply<T>>::remove_prefix((id,), None);223		<Balance<T>>::remove_prefix((id,), None);224		<Allowance<T>>::remove_prefix((id,), None);225		<Owned<T>>::remove_prefix((id,), None);226		<AccountBalance<T>>::remove_prefix((id,), None);227		Ok(())228	}229230	fn collection_has_tokens(collection_id: CollectionId) -> bool {231		<TokenData<T>>::iter_prefix((collection_id,))232			.next()233			.is_some()234	}235236	pub fn burn_token(collection: &RefungibleHandle<T>, token_id: TokenId) -> DispatchResult {237		let burnt = <TokensBurnt<T>>::get(collection.id)238			.checked_add(1)239			.ok_or(ArithmeticError::Overflow)?;240241		<TokensBurnt<T>>::insert(collection.id, burnt);242		<TokenData<T>>::remove((collection.id, token_id));243		<TotalSupply<T>>::remove((collection.id, token_id));244		<Balance<T>>::remove_prefix((collection.id, token_id), None);245		<Allowance<T>>::remove_prefix((collection.id, token_id), None);246		// TODO: ERC721 transfer event247		Ok(())248	}249250	pub fn burn(251		collection: &RefungibleHandle<T>,252		owner: &T::CrossAccountId,253		token: TokenId,254		amount: u128,255	) -> DispatchResult {256		let total_supply = <TotalSupply<T>>::get((collection.id, token))257			.checked_sub(amount)258			.ok_or(<CommonError<T>>::TokenValueTooLow)?;259260		// This was probally last owner of this token?261		if total_supply == 0 {262			// Ensure user actually owns this amount263			ensure!(264				<Balance<T>>::get((collection.id, token, owner)) == amount,265				<CommonError<T>>::TokenValueTooLow266			);267			let account_balance = <AccountBalance<T>>::get((collection.id, owner))268				.checked_sub(1)269				// Should not occur270				.ok_or(ArithmeticError::Underflow)?;271272			// =========273274			<Owned<T>>::remove((collection.id, owner, token));275			<PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);276			<AccountBalance<T>>::insert((collection.id, owner), account_balance);277			Self::burn_token(collection, token)?;278			<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(279				collection.id,280				token,281				owner.clone(),282				amount,283			));284			return Ok(());285		}286287		let balance = <Balance<T>>::get((collection.id, token, owner))288			.checked_sub(amount)289			.ok_or(<CommonError<T>>::TokenValueTooLow)?;290		let account_balance = if balance == 0 {291			<AccountBalance<T>>::get((collection.id, owner))292				.checked_sub(1)293				// Should not occur294				.ok_or(ArithmeticError::Underflow)?295		} else {296			0297		};298299		// =========300301		if balance == 0 {302			<Owned<T>>::remove((collection.id, owner, token));303			<PalletStructure<T>>::unnest_if_nested(owner, collection.id, token);304			<Balance<T>>::remove((collection.id, token, owner));305			<AccountBalance<T>>::insert((collection.id, owner), account_balance);306		} else {307			<Balance<T>>::insert((collection.id, token, owner), balance);308		}309		<TotalSupply<T>>::insert((collection.id, token), total_supply);310		// TODO: ERC20 transfer event311		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(312			collection.id,313			token,314			owner.clone(),315			amount,316		));317		Ok(())318	}319320	pub fn transfer(321		collection: &RefungibleHandle<T>,322		from: &T::CrossAccountId,323		to: &T::CrossAccountId,324		token: TokenId,325		amount: u128,326		nesting_budget: &dyn Budget,327	) -> DispatchResult {328		ensure!(329			collection.limits.transfers_enabled(),330			<CommonError<T>>::TransferNotAllowed331		);332333		if collection.permissions.access() == AccessMode::AllowList {334			collection.check_allowlist(from)?;335			collection.check_allowlist(to)?;336		}337		<PalletCommon<T>>::ensure_correct_receiver(to)?;338339		let balance_from = <Balance<T>>::get((collection.id, token, from))340			.checked_sub(amount)341			.ok_or(<CommonError<T>>::TokenValueTooLow)?;342		let mut create_target = false;343		let from_to_differ = from != to;344		let balance_to = if from != to {345			let old_balance = <Balance<T>>::get((collection.id, token, to));346			if old_balance == 0 {347				create_target = true;348			}349			Some(350				old_balance351					.checked_add(amount)352					.ok_or(ArithmeticError::Overflow)?,353			)354		} else {355			None356		};357358		let account_balance_from = if balance_from == 0 {359			Some(360				<AccountBalance<T>>::get((collection.id, from))361					.checked_sub(1)362					// Should not occur363					.ok_or(ArithmeticError::Underflow)?,364			)365		} else {366			None367		};368		// Account data is created in token, AccountBalance should be increased369		// But only if from != to as we shouldn't check overflow in this case370		let account_balance_to = if create_target && from_to_differ {371			let account_balance_to = <AccountBalance<T>>::get((collection.id, to))372				.checked_add(1)373				.ok_or(ArithmeticError::Overflow)?;374			ensure!(375				account_balance_to < collection.limits.account_token_ownership_limit(),376				<CommonError<T>>::AccountTokenLimitExceeded,377			);378379			Some(account_balance_to)380		} else {381			None382		};383384		// =========385386		<PalletStructure<T>>::nest_if_sent_to_token(387			from.clone(),388			to,389			collection.id,390			token,391			nesting_budget,392		)?;393394		if let Some(balance_to) = balance_to {395			// from != to396			if balance_from == 0 {397				<Balance<T>>::remove((collection.id, token, from));398				<PalletStructure<T>>::unnest_if_nested(from, collection.id, token);399			} else {400				<Balance<T>>::insert((collection.id, token, from), balance_from);401			}402			<Balance<T>>::insert((collection.id, token, to), balance_to);403			if let Some(account_balance_from) = account_balance_from {404				<AccountBalance<T>>::insert((collection.id, from), account_balance_from);405				<Owned<T>>::remove((collection.id, from, token));406			}407			if let Some(account_balance_to) = account_balance_to {408				<AccountBalance<T>>::insert((collection.id, to), account_balance_to);409				<Owned<T>>::insert((collection.id, to, token), true);410			}411		}412413		// TODO: ERC20 transfer event414		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(415			collection.id,416			token,417			from.clone(),418			to.clone(),419			amount,420		));421		Ok(())422	}423424	pub fn create_multiple_items(425		collection: &RefungibleHandle<T>,426		sender: &T::CrossAccountId,427		data: Vec<CreateRefungibleExData<T::CrossAccountId>>,428		nesting_budget: &dyn Budget,429	) -> DispatchResult {430		if !collection.is_owner_or_admin(sender) {431			ensure!(432				collection.permissions.mint_mode(),433				<CommonError<T>>::PublicMintingNotAllowed434			);435			collection.check_allowlist(sender)?;436437			for item in data.iter() {438				for user in item.users.keys() {439					collection.check_allowlist(user)?;440				}441			}442		}443444		for item in data.iter() {445			for (owner, _) in item.users.iter() {446				<PalletCommon<T>>::ensure_correct_receiver(owner)?;447			}448		}449450		// Total pieces per tokens451		let totals = data452			.iter()453			.map(|data| {454				Ok(data455					.users456					.iter()457					.map(|u| u.1)458					.try_fold(0u128, |acc, v| acc.checked_add(*v))459					.ok_or(ArithmeticError::Overflow)?)460			})461			.collect::<Result<Vec<_>, DispatchError>>()?;462		for total in &totals {463			ensure!(464				*total <= MAX_REFUNGIBLE_PIECES,465				<Error<T>>::WrongRefungiblePieces466			);467		}468469		let first_token_id = <TokensMinted<T>>::get(collection.id);470		let tokens_minted = first_token_id471			.checked_add(data.len() as u32)472			.ok_or(ArithmeticError::Overflow)?;473		ensure!(474			tokens_minted < collection.limits.token_limit(),475			<CommonError<T>>::CollectionTokenLimitExceeded476		);477478		let mut balances = BTreeMap::new();479		for data in &data {480			for owner in data.users.keys() {481				let balance = balances482					.entry(owner)483					.or_insert_with(|| <AccountBalance<T>>::get((collection.id, owner)));484				*balance = balance.checked_add(1).ok_or(ArithmeticError::Overflow)?;485486				ensure!(487					*balance <= collection.limits.account_token_ownership_limit(),488					<CommonError<T>>::AccountTokenLimitExceeded,489				);490			}491		}492493		for (i, token) in data.iter().enumerate() {494			let token_id = TokenId(first_token_id + i as u32 + 1);495			for (to, _) in token.users.iter() {496				<PalletStructure<T>>::check_nesting(497					sender.clone(),498					to,499					collection.id,500					token_id,501					nesting_budget,502				)?;503			}504		}505506		// =========507508		<TokensMinted<T>>::insert(collection.id, tokens_minted);509		for (account, balance) in balances {510			<AccountBalance<T>>::insert((collection.id, account), balance);511		}512		for (i, token) in data.into_iter().enumerate() {513			let token_id = first_token_id + i as u32 + 1;514			<TotalSupply<T>>::insert((collection.id, token_id), totals[i]);515516			<TokenData<T>>::insert(517				(collection.id, token_id),518				ItemData {519					const_data: token.const_data,520				},521			);522523			for (user, amount) in token.users.into_iter() {524				if amount == 0 {525					continue;526				}527				<Balance<T>>::insert((collection.id, token_id, &user), amount);528				<Owned<T>>::insert((collection.id, &user, TokenId(token_id)), true);529				<PalletStructure<T>>::nest_if_sent_to_token_unchecked(530					&user,531					collection.id,532					TokenId(token_id),533				);534535				// TODO: ERC20 transfer event536				<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(537					collection.id,538					TokenId(token_id),539					user,540					amount,541				));542			}543		}544		Ok(())545	}546547	pub fn set_allowance_unchecked(548		collection: &RefungibleHandle<T>,549		sender: &T::CrossAccountId,550		spender: &T::CrossAccountId,551		token: TokenId,552		amount: u128,553	) {554		if amount == 0 {555			<Allowance<T>>::remove((collection.id, token, sender, spender));556		} else {557			<Allowance<T>>::insert((collection.id, token, sender, spender), amount);558		}559		// TODO: ERC20 approval event560		<PalletCommon<T>>::deposit_event(CommonEvent::Approved(561			collection.id,562			token,563			sender.clone(),564			spender.clone(),565			amount,566		))567	}568569	pub fn set_allowance(570		collection: &RefungibleHandle<T>,571		sender: &T::CrossAccountId,572		spender: &T::CrossAccountId,573		token: TokenId,574		amount: u128,575	) -> DispatchResult {576		if collection.permissions.access() == AccessMode::AllowList {577			collection.check_allowlist(sender)?;578			collection.check_allowlist(spender)?;579		}580581		<PalletCommon<T>>::ensure_correct_receiver(spender)?;582583		if <Balance<T>>::get((collection.id, token, sender)) < amount {584			ensure!(585				collection.ignores_owned_amount(sender) && Self::token_exists(collection, token),586				<CommonError<T>>::CantApproveMoreThanOwned587			);588		}589590		// =========591592		Self::set_allowance_unchecked(collection, sender, spender, token, amount);593		Ok(())594	}595596	/// Returns allowance, which should be set after transaction597	fn check_allowed(598		collection: &RefungibleHandle<T>,599		spender: &T::CrossAccountId,600		from: &T::CrossAccountId,601		token: TokenId,602		amount: u128,603		nesting_budget: &dyn Budget,604	) -> Result<Option<u128>, DispatchError> {605		if spender.conv_eq(from) {606			return Ok(None);607		}608		if collection.permissions.access() == AccessMode::AllowList {609			// `from`, `to` checked in [`transfer`]610			collection.check_allowlist(spender)?;611		}612		if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {613			// TODO: should collection owner be allowed to perform this transfer?614			ensure!(615				<PalletStructure<T>>::check_indirectly_owned(616					spender.clone(),617					source.0,618					source.1,619					None,620					nesting_budget621				)?,622				<CommonError<T>>::ApprovedValueTooLow,623			);624			return Ok(None);625		}626		let allowance =627			<Allowance<T>>::get((collection.id, token, from, &spender)).checked_sub(amount);628		if allowance.is_none() {629			ensure!(630				collection.ignores_allowance(spender),631				<CommonError<T>>::ApprovedValueTooLow632			);633		}634		Ok(allowance)635	}636637	pub fn transfer_from(638		collection: &RefungibleHandle<T>,639		spender: &T::CrossAccountId,640		from: &T::CrossAccountId,641		to: &T::CrossAccountId,642		token: TokenId,643		amount: u128,644		nesting_budget: &dyn Budget,645	) -> DispatchResult {646		let allowance =647			Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;648649		// =========650651		Self::transfer(collection, from, to, token, amount, nesting_budget)?;652		if let Some(allowance) = allowance {653			Self::set_allowance_unchecked(collection, from, spender, token, allowance);654		}655		Ok(())656	}657658	pub fn burn_from(659		collection: &RefungibleHandle<T>,660		spender: &T::CrossAccountId,661		from: &T::CrossAccountId,662		token: TokenId,663		amount: u128,664		nesting_budget: &dyn Budget,665	) -> DispatchResult {666		let allowance =667			Self::check_allowed(collection, spender, from, token, amount, nesting_budget)?;668669		// =========670671		Self::burn(collection, from, token, amount)?;672		if let Some(allowance) = allowance {673			Self::set_allowance_unchecked(collection, from, spender, token, allowance);674		}675		Ok(())676	}677678	/// Delegated to `create_multiple_items`679	pub fn create_item(680		collection: &RefungibleHandle<T>,681		sender: &T::CrossAccountId,682		data: CreateRefungibleExData<T::CrossAccountId>,683		nesting_budget: &dyn Budget,684	) -> DispatchResult {685		Self::create_multiple_items(collection, sender, vec![data], nesting_budget)686	}687}
modifiedpallets/structure/src/lib.rsdiffbeforeafterboth
--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -189,17 +189,11 @@
 		under: &T::CrossAccountId,
 		collection_id: CollectionId,
 		token_id: TokenId,
-		nesting_budget: &dyn Budget
+		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		Self::try_exec_if_owner_is_valid_nft(
-			under,
-			|d, parent_id| d.check_nesting(
-				from,
-				(collection_id, token_id),
-				parent_id,
-				nesting_budget
-			)
-		)
+		Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {
+			d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)
+		})
 	}
 
 	pub fn nest_if_sent_to_token(
@@ -207,69 +201,51 @@
 		under: &T::CrossAccountId,
 		collection_id: CollectionId,
 		token_id: TokenId,
-		nesting_budget: &dyn Budget
+		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		Self::try_exec_if_owner_is_valid_nft(
-			under,
-			|d, parent_id| {
-				d.check_nesting(
-					from,
-					(collection_id, token_id),
-					parent_id,
-					nesting_budget
-				)?;
+		Self::try_exec_if_owner_is_valid_nft(under, |d, parent_id| {
+			d.check_nesting(from, (collection_id, token_id), parent_id, nesting_budget)?;
 
-				d.nest(parent_id, (collection_id, token_id));
+			d.nest(parent_id, (collection_id, token_id));
 
-				Ok(())
-			}
-		)
+			Ok(())
+		})
 	}
 
 	pub fn nest_if_sent_to_token_unchecked(
 		owner: &T::CrossAccountId,
 		collection_id: CollectionId,
-		token_id: TokenId
+		token_id: TokenId,
 	) {
-		Self::exec_if_owner_is_valid_nft(
-			owner,
-			|d, parent_id| d.nest(
-				parent_id,
-				(collection_id, token_id)
-			)
-		);
+		Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {
+			d.nest(parent_id, (collection_id, token_id))
+		});
 	}
 
 	pub fn unnest_if_nested(
 		owner: &T::CrossAccountId,
 		collection_id: CollectionId,
-		token_id: TokenId
+		token_id: TokenId,
 	) {
-		Self::exec_if_owner_is_valid_nft(
-			owner,
-			|d, parent_id| d.unnest(
-			parent_id,
-			(collection_id, token_id)
-			)
-		);
+		Self::exec_if_owner_is_valid_nft(owner, |d, parent_id| {
+			d.unnest(parent_id, (collection_id, token_id))
+		});
 	}
 
 	fn exec_if_owner_is_valid_nft(
 		account: &T::CrossAccountId,
-		action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId)
+		action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId),
 	) {
-		Self::try_exec_if_owner_is_valid_nft(
-			account,
-			|d, id| {
-				action(d, id);
-				Ok(())
-			}
-		).unwrap();
+		Self::try_exec_if_owner_is_valid_nft(account, |d, id| {
+			action(d, id);
+			Ok(())
+		})
+		.unwrap();
 	}
 
 	fn try_exec_if_owner_is_valid_nft(
 		account: &T::CrossAccountId,
-		action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId) -> DispatchResult
+		action: impl FnOnce(&dyn CommonCollectionOperations<T>, TokenId) -> DispatchResult,
 	) -> DispatchResult {
 		let account = T::CrossTokenAddressMapping::address_to_token(account);
 
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -37,11 +37,10 @@
 use frame_system::{self as system, ensure_signed};
 use sp_runtime::{sp_std::prelude::Vec};
 use up_data_structs::{
-	MAX_COLLECTION_NAME_LENGTH,
-	MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData,
-	CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId, SponsorshipState,
-	CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,
-	PropertyKeyPermission,
+	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
+	AccessMode, CreateItemData, CollectionLimits, CollectionPermissions, CollectionId,
+	CollectionMode, TokenId, SponsorshipState, CreateCollectionData, CreateItemExData, budget,
+	Property, PropertyKey, PropertyKeyPermission,
 };
 use pallet_evm::account::CrossAccountId;
 use pallet_common::{
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -49,7 +49,8 @@
 	},
 	NftChild as RmrkNftChild, AccountIdOrCollectionNftTuple as RmrkAccountIdOrCollectionNftTuple,
 	FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart, EquippableList as RmrkEquippableList,
-	BasicResource as RmrkBasicResource, ComposableResource as RmrkComposableResource, SlotResource as RmrkSlotResource,
+	BasicResource as RmrkBasicResource, ComposableResource as RmrkComposableResource,
+	SlotResource as RmrkSlotResource,
 };
 
 mod bounded;
@@ -361,8 +362,7 @@
 pub type CollectionPropertiesPermissionsVec =
 	BoundedVec<PropertyKeyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
 
-pub type CollectionPropertiesVec =
-	BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
+pub type CollectionPropertiesVec = BoundedVec<Property, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
 
 /// All fields are wrapped in `Option`s, where None means chain default
 // When adding/removing fields from this struct - don't forget to also update clamp_limits
@@ -790,8 +790,8 @@
 	>::IntoIter;
 
 	fn into_iter(self) -> Self::IntoIter {
-        self.0.into_iter()
-    }
+		self.0.into_iter()
+	}
 }
 
 impl<Value> TrySetProperty for PropertiesMap<Value> {
@@ -853,8 +853,8 @@
 	type IntoIter = <PropertiesMap<PropertyValue> as IntoIterator>::IntoIter;
 
 	fn into_iter(self) -> Self::IntoIter {
-        self.map.into_iter()
-    }
+		self.map.into_iter()
+	}
 }
 
 impl TrySetProperty for Properties {
@@ -932,11 +932,7 @@
 pub type RmrkCollectionInfo<AccountId> =
 	CollectionInfo<RmrkString, RmrkCollectionSymbol, AccountId>;
 pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;
-pub type RmrkResourceInfo = ResourceInfo<
-	RmrkBoundedResource,
-	RmrkString,
-	RmrkBoundedParts,
->;
+pub type RmrkResourceInfo = ResourceInfo<RmrkBoundedResource, RmrkString, RmrkBoundedParts>;
 pub type RmrkPropertyInfo = PropertyInfo<RmrkKeyString, RmrkValueString>;
 pub type RmrkBaseInfo<AccountId> = BaseInfo<AccountId, RmrkString>;
 pub type RmrkPartType =
modifiedprimitives/data-structs/src/rmrk.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/rmrk.rs
+++ b/primitives/data-structs/src/rmrk.rs
@@ -20,37 +20,37 @@
 
 #[cfg(feature = "std")]
 mod serialize {
-    use core::convert::AsRef;
-    use serde::ser::{self, Serialize};
+	use core::convert::AsRef;
+	use serde::ser::{self, Serialize};
 
-    pub mod vec {
-        use super::*;
+	pub mod vec {
+		use super::*;
 
-        pub fn serialize<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>
-        where
-            D: ser::Serializer,
-            V: Serialize,
-            C: AsRef<[V]>,
-        {
-            value.as_ref().serialize(serializer)
-        }
-    }
+		pub fn serialize<D, V, C>(value: &C, serializer: D) -> Result<D::Ok, D::Error>
+		where
+			D: ser::Serializer,
+			V: Serialize,
+			C: AsRef<[V]>,
+		{
+			value.as_ref().serialize(serializer)
+		}
+	}
 
-    pub mod opt_vec {
-        use super::*;
+	pub mod opt_vec {
+		use super::*;
 
-        pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>
-        where
-            D: ser::Serializer,
-            V: Serialize,
-            C: AsRef<[V]>,
-        {
-            match value {
-                Some(value) => super::vec::serialize(value, serializer),
-                None => serializer.serialize_none()
-            }
-        }
-    }
+		pub fn serialize<D, V, C>(value: &Option<C>, serializer: D) -> Result<D::Ok, D::Error>
+		where
+			D: ser::Serializer,
+			V: Serialize,
+			C: AsRef<[V]>,
+		{
+			match value {
+				Some(value) => super::vec::serialize(value, serializer),
+				None => serializer.serialize_none(),
+			}
+		}
+	}
 }
 
 /// Collection info.
@@ -58,13 +58,11 @@
 #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			AccountId: Serialize,
 			BoundedString: AsRef<[u8]>,
 			BoundedSymbol: AsRef<[u8]>
-		"#
-	)
+		"#)
 )]
 pub struct CollectionInfo<BoundedString, BoundedSymbol, AccountId> {
 	/// Current bidder and bid price.
@@ -91,9 +89,9 @@
 #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
 pub struct RoyaltyInfo<AccountId, RoyaltyAmount> {
 	/// Recipient (AccountId) of the royalty
-    pub recipient: AccountId,
+	pub recipient: AccountId,
 	/// Amount (Permill) of the royalty
-    pub amount: RoyaltyAmount,
+	pub amount: RoyaltyAmount,
 }
 
 /// Nft info.
@@ -101,13 +99,11 @@
 #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			AccountId: Serialize,
 			RoyaltyAmount: Serialize,
 			BoundedString: AsRef<[u8]>
-		"#
-	)
+		"#)
 )]
 pub struct NftInfo<AccountId, RoyaltyAmount, BoundedString> {
 	/// The owner of the NFT, can be either an Account or a tuple (CollectionId, NftId)
@@ -129,22 +125,19 @@
 #[derive(Encode, Decode, TypeInfo, MaxEncodedLen)]
 pub struct NftChild {
 	pub collection_id: CollectionId,
-	pub nft_id: NftId
+	pub nft_id: NftId,
 }
 
 #[cfg_attr(feature = "std", derive(Serialize))]
 #[derive(Encode, Decode, PartialEq, TypeInfo)]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			BoundedKey: AsRef<[u8]>,
 			BoundedValue: AsRef<[u8]>
-		"#
-	)
+		"#)
 )]
-pub struct PropertyInfo<BoundedKey, BoundedValue>
-{
+pub struct PropertyInfo<BoundedKey, BoundedValue> {
 	/// Key of the property
 	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
 	pub key: BoundedKey,
@@ -156,10 +149,7 @@
 
 #[derive(Encode, Decode, Default, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
 #[cfg_attr(feature = "std", derive(Serialize))]
-#[cfg_attr(
-	feature = "std",
-	serde(bound = "BoundedString: AsRef<[u8]>")
-)]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
 pub struct BasicResource<BoundedString> {
 	/// If the resource is Media, the base property is absent. Media src should be a URI like an
 	/// IPFS hash.
@@ -188,12 +178,10 @@
 #[cfg_attr(feature = "std", derive(Serialize))]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			BoundedString: AsRef<[u8]>,
 			BoundedParts: AsRef<[PartId]>
-		"#
-	)
+		"#)
 )]
 pub struct ComposableResource<BoundedString, BoundedParts> {
 	/// If a resource is composed, it will have an array of parts that compose it
@@ -235,10 +223,7 @@
 
 #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
 #[cfg_attr(feature = "std", derive(Serialize))]
-#[cfg_attr(
-	feature = "std",
-	serde(bound = "BoundedString: AsRef<[u8]>")
-)]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
 pub struct SlotResource<BoundedString> {
 	/// A Base is uniquely identified by the combination of the word `base`, its minting block
 	/// number, and user provided symbol during Base creation, glued by dashes `-`, e.g.
@@ -279,14 +264,12 @@
 #[cfg_attr(feature = "std", derive(Serialize))]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			BoundedString: AsRef<[u8]>,
 			BoundedParts: AsRef<[PartId]>
-		"#
-	)
+		"#)
 )]
-#[derivative(Default(bound=""))]
+#[derivative(Default(bound = ""))]
 pub enum ResourceTypes<BoundedString: Default, BoundedParts> {
 	#[derivative(Default)]
 	Basic(BasicResource<BoundedString>),
@@ -294,18 +277,15 @@
 	Slot(SlotResource<BoundedString>),
 }
 
-
 #[derive(Encode, Decode, Eq, PartialEq, Clone, Debug, TypeInfo, MaxEncodedLen)]
 #[cfg_attr(feature = "std", derive(Serialize))]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			BoundedResource: AsRef<[u8]>,
 			BoundedString: AsRef<[u8]>,
 			BoundedParts: AsRef<[PartId]>
-		"#
-	)
+		"#)
 )]
 pub struct ResourceInfo<BoundedResource, BoundedString: Default, BoundedParts> {
 	/// id is a 5-character string of reasonable uniqueness.
@@ -328,12 +308,10 @@
 #[derive(Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			AccountId: Serialize,
 			BoundedString: AsRef<[u8]>
-		"#
-	)
+		"#)
 )]
 pub struct BaseInfo<AccountId, BoundedString> {
 	/// Original creator of the Base
@@ -350,10 +328,7 @@
 
 #[cfg_attr(feature = "std", derive(Serialize))]
 #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
-#[cfg_attr(
-	feature = "std",
-	serde(bound = "BoundedString: AsRef<[u8]>")
-)]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
 pub struct FixedPart<BoundedString> {
 	pub id: PartId,
 	pub z: ZIndex,
@@ -368,29 +343,24 @@
 	feature = "std",
 	serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")
 )]
-#[derivative(Default(bound=""))]
+#[derivative(Default(bound = ""))]
 pub enum EquippableList<BoundedCollectionList> {
 	All,
 
 	#[derivative(Default)]
 	Empty,
 
-	Custom(
-		#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
-		BoundedCollectionList
-	),
+	Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),
 }
 
 #[cfg_attr(feature = "std", derive(Serialize))]
 #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			BoundedString: AsRef<[u8]>,
 			BoundedCollectionList: AsRef<[CollectionId]>
-		"#
-	)
+		"#)
 )]
 pub struct SlotPart<BoundedString, BoundedCollectionList> {
 	pub id: PartId,
@@ -406,12 +376,10 @@
 #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			BoundedString: AsRef<[u8]>,
 			BoundedCollectionList: AsRef<[CollectionId]>
-		"#
-	)
+		"#)
 )]
 pub enum PartType<BoundedString, BoundedCollectionList> {
 	FixedPart(FixedPart<BoundedString>),
@@ -422,21 +390,21 @@
 	pub fn id(&self) -> PartId {
 		match self {
 			Self::FixedPart(part) => part.id,
-			Self::SlotPart(part) => part.id
+			Self::SlotPart(part) => part.id,
 		}
 	}
 
 	pub fn src(&self) -> &BoundedString {
 		match self {
 			Self::FixedPart(part) => &part.src,
-			Self::SlotPart(part) => &part.src
+			Self::SlotPart(part) => &part.src,
 		}
 	}
 
 	pub fn z_index(&self) -> ZIndex {
 		match self {
 			Self::FixedPart(part) => part.z,
-			Self::SlotPart(part) => part.z
+			Self::SlotPart(part) => part.z,
 		}
 	}
 }
@@ -445,12 +413,10 @@
 #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]
 #[cfg_attr(
 	feature = "std",
-	serde(
-		bound = r#"
+	serde(bound = r#"
 			BoundedString: AsRef<[u8]>,
 			PropertyList: AsRef<[ThemeProperty<BoundedString>]>,
-		"#
-	)
+		"#)
 )]
 pub struct Theme<BoundedString, PropertyList> {
 	/// Name of the theme
@@ -466,10 +432,7 @@
 
 #[cfg_attr(feature = "std", derive(Eq, Serialize))]
 #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]
-#[cfg_attr(
-	feature = "std",
-	serde(bound = "BoundedString: AsRef<[u8]>")
-)]
+#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]
 pub struct ThemeProperty<BoundedString> {
 	/// Key of the property
 	#[cfg_attr(feature = "std", serde(with = "serialize::vec"))]
modifiedruntime/tests/src/tests.rsdiffbeforeafterboth
--- a/runtime/tests/src/tests.rs
+++ b/runtime/tests/src/tests.rs
@@ -19,9 +19,9 @@
 use up_data_structs::{
 	COLLECTION_NUMBER_LIMIT, CollectionId, CreateItemData, CreateFungibleData, CreateNftData,
 	CreateReFungibleData, MAX_DECIMAL_POINTS, COLLECTION_ADMINS_LIMIT, TokenId,
-	MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionMode,
-	AccessMode, CollectionPermissions, PropertyKeyPermission, PropertyPermission,
-	Property, CollectionPropertiesVec, CollectionPropertiesPermissionsVec,
+	MAX_TOKEN_OWNERSHIP, CreateCollectionData, CollectionMode, AccessMode, CollectionPermissions,
+	PropertyKeyPermission, PropertyPermission, Property, CollectionPropertiesVec,
+	CollectionPropertiesPermissionsVec,
 };
 use frame_support::{assert_noop, assert_ok, assert_err};
 use sp_std::convert::TryInto;
@@ -47,12 +47,12 @@
 
 fn default_nft_data() -> CreateNftData {
 	CreateNftData {
-		properties: vec![
-			Property {
-				key: b"test-prop".to_vec().try_into().unwrap(),
-				value: b"test-nft-prop".to_vec().try_into().unwrap(),
-			},
-		].try_into().unwrap(),
+		properties: vec![Property {
+			key: b"test-prop".to_vec().try_into().unwrap(),
+			value: b"test-nft-prop".to_vec().try_into().unwrap(),
+		}]
+		.try_into()
+		.unwrap(),
 	}
 }
 
@@ -77,22 +77,23 @@
 	let col_name1: Vec<u16> = "Test1\0".encode_utf16().collect::<Vec<u16>>();
 	let col_desc1: Vec<u16> = "TestDescription1\0".encode_utf16().collect::<Vec<u16>>();
 	let token_prefix1: Vec<u8> = b"token_prefix1\0".to_vec();
-	let token_property_permissions: CollectionPropertiesPermissionsVec = vec![
-		PropertyKeyPermission {
+	let token_property_permissions: CollectionPropertiesPermissionsVec =
+		vec![PropertyKeyPermission {
 			key: b"test-prop".to_vec().try_into().unwrap(),
 			permission: PropertyPermission {
 				mutable: true,
 				collection_admin: false,
 				token_owner: true,
 			},
-		},
-	].try_into().unwrap();
-	let properties: CollectionPropertiesVec = vec![
-		Property {
-			key: b"test-collection-prop".to_vec().try_into().unwrap(),
-			value: b"test-collection-value".to_vec().try_into().unwrap(),
-		}
-	].try_into().unwrap();
+		}]
+		.try_into()
+		.unwrap();
+	let properties: CollectionPropertiesVec = vec![Property {
+		key: b"test-collection-prop".to_vec().try_into().unwrap(),
+		value: b"test-collection-value".to_vec().try_into().unwrap(),
+	}]
+	.try_into()
+	.unwrap();
 
 	let data: CreateCollectionData<u64> = CreateCollectionData {
 		name: col_name1.try_into().unwrap(),
@@ -150,30 +151,21 @@
 fn get_collection_property_permissions(collection_id: CollectionId) -> Vec<PropertyKeyPermission> {
 	<pallet_common::Pallet<Test>>::property_permissions(collection_id)
 		.into_iter()
-		.map(|(key, permission)| PropertyKeyPermission {
-			key,
-			permission,
-		})
+		.map(|(key, permission)| PropertyKeyPermission { key, permission })
 		.collect()
 }
 
 fn get_collection_properties(collection_id: CollectionId) -> Vec<Property> {
 	<pallet_common::Pallet<Test>>::collection_properties(collection_id)
 		.into_iter()
-		.map(|(key, value)| Property {
-			key,
-			value,
-		})
+		.map(|(key, value)| Property { key, value })
 		.collect()
 }
 
 fn get_token_properties(collection_id: CollectionId, token_id: TokenId) -> Vec<Property> {
 	<pallet_nonfungible::Pallet<Test>>::token_properties((collection_id, token_id))
 		.into_iter()
-		.map(|(key, value)| Property {
-			key,
-			value,
-		})
+		.map(|(key, value)| Property { key, value })
 		.collect()
 }