git.delta.rocks / unique-network / refs/commits / 9d0fd83a5da6

difftreelog

fix use CollectionIssuer enum for collection creation

Daniel Shiposha2023-11-24parent: #b4d745d.patch.diff
in: master

6 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -11,7 +11,7 @@
 use sp_weights::Weight;
 use up_data_structs::{CollectionId, CreateCollectionData};
 
-use crate::{pallet::Config, CommonCollectionOperations};
+use crate::{pallet::Config, CollectionIssuer, CommonCollectionOperations};
 
 // TODO: move to benchmarking
 /// Price of [`dispatch_tx`] call with noop `call` argument
@@ -72,26 +72,11 @@
 	/// Create a regular collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).
 	///
 	/// * `sender` - The user who will become the owner of the collection.
-	/// * `payer` - If set, the user who pays the collection creation deposit.
+	/// * `issuer` - An entity that creates the collection.
 	/// * `data` - Description of the created collection.
 	fn create(
 		sender: T::CrossAccountId,
-		payer: Option<T::CrossAccountId>,
-		data: CreateCollectionData<T::CrossAccountId>,
-	) -> Result<CollectionId, DispatchError> {
-		Self::create_raw(sender, payer, false, data)
-	}
-
-	/// Function for creating regular and special collections.
-	///
-	/// * `sender` - The user who will become the owner of the collection.
-	/// * `payer` - If set, the user who pays the collection creation deposit.
-	/// * `data` - Description of the created collection.
-	/// * `is_special_collection` -- Whether this collection is a special one, i.e. can have special flags set.
-	fn create_raw(
-		sender: T::CrossAccountId,
-		payer: Option<T::CrossAccountId>,
-		is_special_collection: bool,
+		issuer: CollectionIssuer<T::CrossAccountId>,
 		data: CreateCollectionData<T::CrossAccountId>,
 	) -> Result<CollectionId, DispatchError>;
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
944 }944 }
945}945}
946
947/// An issuer of a collection.
948pub enum CollectionIssuer<CrossAccountId> {
949 /// A user who creates the collection.
950 User(CrossAccountId),
951
952 /// The internal mechanisms are creating the collection.
953 Internals,
954}
946955
947fn check_token_permissions<T: Config>(956fn check_token_permissions<T: Config>(
948 collection_admin_permitted: bool,957 collection_admin_permitted: bool,
1128 /// Create new collection.1137 /// Create new collection.
1129 ///1138 ///
1130 /// * `owner` - The owner of the collection.1139 /// * `owner` - The owner of the collection.
1131 /// * `payer` - If set, the user that will pay a deposit for the collection creation.
1132 /// * `data` - Description of the created collection.1140 /// * `issuer` - An entity that creates the collection.
1133 /// * `is_special_collection` -- Whether this collection is a special one, i.e. can have special flags set.1141 /// * `is_special_collection` -- Whether this collection is a special one, i.e. can have special flags set.
1134 pub fn init_collection(1142 pub fn init_collection(
1135 owner: T::CrossAccountId,1143 owner: T::CrossAccountId,
1136 payer: Option<T::CrossAccountId>,1144 issuer: CollectionIssuer<T::CrossAccountId>,
1137 is_special_collection: bool,
1138 data: CreateCollectionData<T::CrossAccountId>,1145 data: CreateCollectionData<T::CrossAccountId>,
1139 ) -> Result<CollectionId, DispatchError> {1146 ) -> Result<CollectionId, DispatchError> {
1140 if !is_special_collection {1147 match issuer {
1141 ensure!(data.flags.is_allowed_for_user(), <Error<T>>::NoPermission);
1142 }
1143
1144 // Take a (non-refundable) deposit of collection creation
1145 if let Some(payer) = payer {1148 CollectionIssuer::User(payer) => {
1149 ensure!(data.flags.is_allowed_for_user(), <Error<T>>::NoPermission);
1150
1151 // Take a (non-refundable) deposit of collection creation
1146 let mut imbalance = <Debt<T::AccountId, <T as Config>::Currency>>::zero();1152 let mut imbalance = <Debt<T::AccountId, <T as Config>::Currency>>::zero();
1147 imbalance.subsume(<T as Config>::Currency::deposit(1153 imbalance.subsume(<T as Config>::Currency::deposit(
1148 &T::TreasuryAccountId::get(),1154 &T::TreasuryAccountId::get(),
1162 )
1154 .map_err(|_| Error::<T>::NotSufficientFounds)?;1163 .map_err(|_| Error::<T>::NotSufficientFounds)?;
11551164
1156 debug_assert!(credit.peek().is_zero())1165 debug_assert!(credit.peek().is_zero());
1157 }1166 }
1167 CollectionIssuer::Internals => {}
1168 }
11581169
1159 {1170 {
1160 ensure!(1171 ensure!(
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -56,6 +56,7 @@
 
 #[frame_support::pallet]
 pub mod module {
+	use pallet_common::CollectionIssuer;
 	use up_data_structs::{
 		CollectionDescription, Property, PropertyKeyPermission, PropertyPermission,
 	};
@@ -169,12 +170,9 @@
 				.try_into()
 				.expect("description length < max description length; qed");
 
-			let payer = None;
-			let is_special_collection = true;
-			let collection_id = T::CollectionDispatch::create_raw(
+			let collection_id = T::CollectionDispatch::create(
 				foreign_collection_owner,
-				payer,
-				is_special_collection,
+				CollectionIssuer::Internals,
 				CreateCollectionData {
 					name,
 					token_prefix,
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -26,7 +26,7 @@
 	dispatch::CollectionDispatch,
 	erc::{static_property::key, CollectionHelpersEvents},
 	eth::{self, collection_id_to_address, map_eth_to_id},
-	CollectionById, CollectionHandle, Pallet as PalletCommon,
+	CollectionById, CollectionHandle, CollectionIssuer, Pallet as PalletCommon,
 };
 use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
 use pallet_evm_coder_substrate::{
@@ -110,9 +110,12 @@
 	let collection_helpers_address =
 		T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
 
-	let collection_id =
-		T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)
-			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+	let collection_id = T::CollectionDispatch::create(
+		caller,
+		CollectionIssuer::User(collection_helpers_address),
+		data,
+	)
+	.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 	let address = pallet_common::eth::collection_id_to_address(collection_id);
 	Ok(address)
 }
@@ -241,9 +244,12 @@
 		let collection_helpers_address =
 			T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
 
-		let collection_id =
-			T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)
-				.map_err(dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(
+			caller,
+			CollectionIssuer::User(collection_helpers_address),
+			data,
+		)
+		.map_err(dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
@@ -276,9 +282,12 @@
 		check_sent_amount_equals_collection_creation_price::<T>(value)?;
 		let collection_helpers_address =
 			T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
-		let collection_id =
-			T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)
-				.map_err(dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(
+			caller,
+			CollectionIssuer::User(collection_helpers_address),
+			data,
+		)
+		.map_err(dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -93,7 +93,8 @@
 	use frame_system::{ensure_root, ensure_signed};
 	use pallet_common::{
 		dispatch::{dispatch_tx, CollectionDispatch},
-		CollectionHandle, CommonWeightInfo, Pallet as PalletCommon, RefungibleExtensionsWeightInfo,
+		CollectionHandle, CollectionIssuer, CommonWeightInfo, Pallet as PalletCommon,
+		RefungibleExtensionsWeightInfo,
 	};
 	use pallet_evm::account::CrossAccountId;
 	use pallet_structure::weights::WeightInfo as StructureWeightInfo;
@@ -401,7 +402,11 @@
 
 			// =========
 			let sender = T::CrossAccountId::from_sub(sender);
-			let _id = T::CollectionDispatch::create(sender.clone(), Some(sender), data)?;
+			let _id = T::CollectionDispatch::create(
+				sender.clone(),
+				CollectionIssuer::User(sender),
+				data,
+			)?;
 
 			Ok(())
 		}
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -18,7 +18,7 @@
 use pallet_balances_adapter::NativeFungibleHandle;
 pub use pallet_common::dispatch::CollectionDispatch;
 use pallet_common::{
-	erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle,
+	erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle, CollectionIssuer,
 	CommonCollectionOperations, Pallet as PalletCommon,
 };
 use pallet_evm::{PrecompileHandle, PrecompileResult};
@@ -66,10 +66,9 @@
 		}
 	}
 
-	fn create_raw(
+	fn create(
 		sender: T::CrossAccountId,
-		payer: Option<T::CrossAccountId>,
-		is_special_collection: bool,
+		issuer: CollectionIssuer<T::CrossAccountId>,
 		data: CreateCollectionData<T::CrossAccountId>,
 	) -> Result<CollectionId, DispatchError> {
 		match data.mode {
@@ -87,7 +86,7 @@
 			_ => {}
 		};
 
-		<PalletCommon<T>>::init_collection(sender, payer, is_special_collection, data)
+		<PalletCommon<T>>::init_collection(sender, issuer, data)
 	}
 
 	fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {