git.delta.rocks / unique-network / refs/commits / 52730495c578

difftreelog

patch: Change dispathed call for create item (return collection id).

Trubnikov Sergey2022-07-25parent: #6434da3.patch.diff
in: master

4 files changed

modifiedpallets/common/src/dispatch.rsdiffbeforeafterboth
8 weights::Pays,8 weights::Pays,
9 traits::Get,9 traits::Get,
10};10};
11use sp_runtime::DispatchError;
11use up_data_structs::{CollectionId, CreateCollectionData};12use up_data_structs::{CollectionId, CreateCollectionData};
1213
13use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};14use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};
78 fn create(79 fn create(
79 sender: T::CrossAccountId,80 sender: T::CrossAccountId,
80 data: CreateCollectionData<T::AccountId>,81 data: CreateCollectionData<T::AccountId>,
81 ) -> DispatchResult;82 ) -> Result<CollectionId, DispatchError>;
8283
83 /// Delete the collection.84 /// Delete the collection.
84 ///85 ///
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -32,6 +32,7 @@
 		static_property::{key, value as property_value},
 		CollectionHelpersEvents,
 	},
+	dispatch::CollectionDispatch,
 };
 use crate::{SelfWeightOf, Config, weights::WeightInfo};
 
@@ -179,9 +180,8 @@
 			Default::default(),
 			false,
 		)?;
-		let collection_id =
-			<pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, false)
-				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(caller, data)
+			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
@@ -207,9 +207,8 @@
 			base_uri_value,
 			true,
 		)?;
-		let collection_id =
-			<pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, true)
-				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+		let collection_id = T::CollectionDispatch::create(caller, data)
+			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
 		Ok(address)
@@ -233,7 +232,7 @@
 			Default::default(),
 			false,
 		)?;
-		let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)
+		let collection_id = T::CollectionDispatch::create(caller, data)
 			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
@@ -260,7 +259,7 @@
 			base_uri_value,
 			true,
 		)?;
-		let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)
+		let collection_id = T::CollectionDispatch::create(caller, data)
 			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 
 		let address = pallet_common::eth::collection_id_to_address(collection_id);
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -352,7 +352,7 @@
 
 			// =========
 
-			T::CollectionDispatch::create(T::CrossAccountId::from_sub(sender), data)?;
+			let _id = T::CollectionDispatch::create(T::CrossAccountId::from_sub(sender), data)?;
 
 			Ok(())
 		}
modifiedruntime/common/src/dispatch.rsdiffbeforeafterboth
--- a/runtime/common/src/dispatch.rs
+++ b/runtime/common/src/dispatch.rs
@@ -17,6 +17,7 @@
 use frame_support::{dispatch::DispatchResult, ensure};
 use pallet_evm::{PrecompileHandle, PrecompileResult};
 use sp_core::H160;
+use sp_runtime::DispatchError;
 use sp_std::{borrow::ToOwned, vec::Vec};
 use pallet_common::{
 	CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,
@@ -30,6 +31,7 @@
 };
 use up_data_structs::{
 	CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,
+	CollectionId,
 };
 
 pub enum CollectionDispatchT<T>
@@ -51,8 +53,8 @@
 	fn create(
 		sender: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
-	) -> DispatchResult {
-		let _id = match data.mode {
+	) -> Result<CollectionId, DispatchError> {
+		let id = match data.mode {
 			CollectionMode::NFT => <PalletNonfungible<T>>::init_collection(sender, data, false)?,
 			CollectionMode::Fungible(decimal_points) => {
 				// check params
@@ -64,7 +66,7 @@
 			}
 			CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,
 		};
-		Ok(())
+		Ok(id)
 	}
 
 	fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {