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

difftreelog

refactor create collection with optional payer

Daniel Shiposha2023-10-18parent: #383b7ef.patch.diff
in: master

5 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
72 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).72 /// Create a collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).
73 ///73 ///
74 /// * `sender` - The user who will become the owner of the collection.74 /// * `sender` - The user who will become the owner of the collection.
75 /// * `payer` - The user who pays the collection creation fee.75 /// * `payer` - If set, the user who pays the collection creation deposit.
76 /// * `data` - Description of the created collection.76 /// * `data` - Description of the created collection.
77 fn create(77 fn create(
78 sender: T::CrossAccountId,78 sender: T::CrossAccountId,
79 payer: T::CrossAccountId,79 payer: Option<T::CrossAccountId>,
80 data: CreateCollectionData<T::CrossAccountId>,80 data: CreateCollectionData<T::CrossAccountId>,
81 ) -> Result<CollectionId, DispatchError>;81 ) -> Result<CollectionId, DispatchError>;
82
83 /// Create a foreign collection. The collection will be created according to the value of [`data.mode`](CreateCollectionData::mode).
84 ///
85 /// * `sender` - The user who will become the owner of the collection.
86 /// * `data` - Description of the created collection.
87 fn create_foreign(
88 sender: T::CrossAccountId,
89 data: CreateCollectionData<T::CrossAccountId>,
90 ) -> Result<CollectionId, DispatchError>;
9182
92 /// Delete the collection.83 /// Delete the collection.
93 ///84 ///
modifiedpallets/foreign-assets/src/lib.rsdiffbeforeafterboth
--- a/pallets/foreign-assets/src/lib.rs
+++ b/pallets/foreign-assets/src/lib.rs
@@ -152,8 +152,10 @@
 				.try_into()
 				.expect("description length < max description length; qed");
 
-			let collection_id = T::CollectionDispatch::create_foreign(
+			let payer = None;
+			let collection_id = T::CollectionDispatch::create(
 				foreign_collection_owner,
+				payer,
 				CreateCollectionData {
 					name,
 					description,
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -110,8 +110,9 @@
 	let collection_helpers_address =
 		T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
 
-	let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
-		.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+	let collection_id =
+		T::CollectionDispatch::create(caller, Some(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)
 }
@@ -240,8 +241,9 @@
 		let collection_helpers_address =
 			T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
 
-		let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
-			.map_err(dispatch_to_evm::<T>)?;
+		let collection_id =
+			T::CollectionDispatch::create(caller, Some(collection_helpers_address), data)
+				.map_err(dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
@@ -274,8 +276,9 @@
 		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, collection_helpers_address, data)
-			.map_err(dispatch_to_evm::<T>)?;
+		let collection_id =
+			T::CollectionDispatch::create(caller, Some(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
@@ -401,7 +401,7 @@
 
 			// =========
 			let sender = T::CrossAccountId::from_sub(sender);
-			let _id = T::CollectionDispatch::create(sender.clone(), sender, data)?;
+			let _id = T::CollectionDispatch::create(sender.clone(), Some(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, unsupported, CollectionById, CollectionHandle,
+	erc::CommonEvmHandler, eth::map_eth_to_id, CollectionById, CollectionHandle,
 	CommonCollectionOperations, Pallet as PalletCommon,
 };
 use pallet_evm::{PrecompileHandle, PrecompileResult};
@@ -68,7 +68,7 @@
 
 	fn create(
 		sender: T::CrossAccountId,
-		payer: T::CrossAccountId,
+		payer: Option<T::CrossAccountId>,
 		data: CreateCollectionData<T::CrossAccountId>,
 	) -> Result<CollectionId, DispatchError> {
 		match data.mode {
@@ -85,28 +85,7 @@
 
 			_ => {}
 		};
-
-		<PalletCommon<T>>::init_collection(sender, Some(payer), data)
-	}
 
-	fn create_foreign(
-		sender: <T>::CrossAccountId,
-		data: CreateCollectionData<<T>::CrossAccountId>,
-	) -> Result<CollectionId, DispatchError> {
-		match data.mode {
-			CollectionMode::Fungible(decimal_points) => {
-				// check params
-				ensure!(
-					decimal_points <= MAX_DECIMAL_POINTS,
-					pallet_unique::Error::<T>::CollectionDecimalPointLimitExceeded
-				);
-			}
-
-			CollectionMode::ReFungible => return unsupported!(T),
-			_ => {}
-		};
-
-		let payer = None;
 		<PalletCommon<T>>::init_collection(sender, payer, data)
 	}