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
--- a/pallets/common/src/dispatch.rs
+++ b/pallets/common/src/dispatch.rs
@@ -8,6 +8,7 @@
 	weights::Pays,
 	traits::Get,
 };
+use sp_runtime::DispatchError;
 use up_data_structs::{CollectionId, CreateCollectionData};
 
 use crate::{pallet::Config, CommonCollectionOperations, CollectionHandle};
@@ -78,7 +79,7 @@
 	fn create(
 		sender: T::CrossAccountId,
 		data: CreateCollectionData<T::AccountId>,
-	) -> DispatchResult;
+	) -> Result<CollectionId, DispatchError>;
 
 	/// Delete the collection.
 	///
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
17use frame_support::{dispatch::DispatchResult, ensure};17use frame_support::{dispatch::DispatchResult, ensure};
18use pallet_evm::{PrecompileHandle, PrecompileResult};18use pallet_evm::{PrecompileHandle, PrecompileResult};
19use sp_core::H160;19use sp_core::H160;
20use sp_runtime::DispatchError;
20use sp_std::{borrow::ToOwned, vec::Vec};21use sp_std::{borrow::ToOwned, vec::Vec};
21use pallet_common::{22use pallet_common::{
22 CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,23 CollectionById, CollectionHandle, CommonCollectionOperations, erc::CommonEvmHandler,
30};31};
31use up_data_structs::{32use up_data_structs::{
32 CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,33 CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,
34 CollectionId,
33};35};
3436
35pub enum CollectionDispatchT<T>37pub enum CollectionDispatchT<T>
51 fn create(53 fn create(
52 sender: T::CrossAccountId,54 sender: T::CrossAccountId,
53 data: CreateCollectionData<T::AccountId>,55 data: CreateCollectionData<T::AccountId>,
54 ) -> DispatchResult {56 ) -> Result<CollectionId, DispatchError> {
55 let _id = match data.mode {57 let id = match data.mode {
56 CollectionMode::NFT => <PalletNonfungible<T>>::init_collection(sender, data, false)?,58 CollectionMode::NFT => <PalletNonfungible<T>>::init_collection(sender, data, false)?,
57 CollectionMode::Fungible(decimal_points) => {59 CollectionMode::Fungible(decimal_points) => {
58 // check params60 // check params
64 }66 }
65 CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,67 CollectionMode::ReFungible => <PalletRefungible<T>>::init_collection(sender, data)?,
66 };68 };
67 Ok(())69 Ok(id)
68 }70 }
6971
70 fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {72 fn destroy(sender: T::CrossAccountId, collection: CollectionHandle<T>) -> DispatchResult {