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

difftreelog

CORE-346 Remove evm_collection namespace

Trubnikov Sergey2022-05-27parent: #79ed02e.patch.diff
in: master

6 files changed

modifiedMakefilediffbeforeafterboth
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@
 CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/
 CONTRACT_HELPERS_ABI=./tests/src/eth/util/contractHelpersAbi.json
 
-COLLECTION_HELPER_STUBS=$(COLLECTION_STUBS)
+COLLECTION_HELPER_STUBS=./pallets/unique/src/eth/stubs/
 COLLECTION_HELPER_ABI=./tests/src/eth/collectionHelperAbi.json
 
 TESTS_API=./tests/src/eth/api/
@@ -36,8 +36,8 @@
 	PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_impl OUTPUT=$(CONTRACT_HELPERS_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
 
 CollectionHelper.sol:
-	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
-	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_impl OUTPUT=$(COLLECTION_HELPER_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
+	PACKAGE=pallet-unique NAME=eth::collection_helper_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
+	PACKAGE=pallet-unique NAME=eth::collection_helper_impl OUTPUT=$(COLLECTION_HELPER_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
 
 UniqueFungible: UniqueFungible.sol
 	INPUT=$(FUNGIBLE_EVM_STUBS)/$< OUTPUT=$(FUNGIBLE_EVM_STUBS)/UniqueFungible.raw ./.maintain/scripts/compile_stub.sh
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -14,161 +14,159 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-pub mod evm_collection {
-	use core::marker::PhantomData;
-	use evm_coder::{execution::*, generate_stubgen, solidity_interface, types::*, ToLog};
-	use ethereum as _;
-	use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-	use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, Pallet as PalletEvm};
-	use up_data_structs::{
-		CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
-		MAX_COLLECTION_NAME_LENGTH,
-	};
-	use frame_support::traits::Get;
-	use sp_core::H160;
-	use pallet_common::CollectionById;
-	
-	use sp_std::vec::Vec;
-	use alloc::format;
-	
-	pub trait Config:
-		frame_system::Config
-		+ pallet_evm_coder_substrate::Config
-		+ pallet_evm::account::Config
-		+ pallet_nonfungible::Config
-	{
-		type ContractAddress: Get<H160>;
+use core::marker::PhantomData;
+use evm_coder::{execution::*, generate_stubgen, solidity_interface, types::*, ToLog};
+use ethereum as _;
+use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
+use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, Pallet as PalletEvm};
+use up_data_structs::{
+	CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
+	MAX_COLLECTION_NAME_LENGTH,
+};
+use frame_support::traits::Get;
+use sp_core::H160;
+use pallet_common::CollectionById;
+
+use sp_std::vec::Vec;
+use alloc::format;
+
+pub trait Config:
+	frame_system::Config
+	+ pallet_evm_coder_substrate::Config
+	+ pallet_evm::account::Config
+	+ pallet_nonfungible::Config
+{
+	type ContractAddress: Get<H160>;
+}
+
+struct EvmCollectionHelper<T: Config>(SubstrateRecorder<T>);
+impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {
+	fn recorder(&self) -> &SubstrateRecorder<T> {
+		&self.0
 	}
 
-	struct EvmCollectionHelper<T: Config>(SubstrateRecorder<T>);
-	impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {
-		fn recorder(&self) -> &SubstrateRecorder<T> {
-			&self.0
-		}
-	
-		fn into_recorder(self) -> SubstrateRecorder<T> {
-			self.0
-		}
+	fn into_recorder(self) -> SubstrateRecorder<T> {
+		self.0
 	}
+}
+
+#[solidity_interface(name = "CollectionHelper")]
+impl<T: Config> EvmCollectionHelper<T> {
+	fn create_721_collection(
+		&self,
+		caller: caller,
+		name: string,
+		description: string,
+		token_prefix: string,
+	) -> Result<address> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let name = name
+			.encode_utf16()
+			.collect::<Vec<u16>>()
+			.try_into()
+			.map_err(|_| error_feild_too_long(stringify!(name), MAX_COLLECTION_NAME_LENGTH))?;
+		let description = description
+			.encode_utf16()
+			.collect::<Vec<u16>>()
+			.try_into()
+			.map_err(|_| {
+				error_feild_too_long(stringify!(description), MAX_COLLECTION_DESCRIPTION_LENGTH)
+			})?;
+		let token_prefix = token_prefix
+			.into_bytes()
+			.try_into()
+			.map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;
+
+		let key: string = "tokenURI".into(); //TODO: make static
+		let key: up_data_structs::PropertyKey = key.into_bytes().try_into().map_err(|_| Error::Revert("".into()))?;
+		let permission = up_data_structs::PropertyPermission {
+			mutable: true,
+			collection_admin: true,
+			token_owner: false,
+		};
+		let mut token_property_permissions = up_data_structs::CollectionPropertiesPermissionsVec::default();
+		token_property_permissions.try_push(up_data_structs::PropertyKeyPermission{
+			key,
+			permission,
+		}).map_err(|e| Error::Revert(format!("{:?}", e)))?;
 
-	#[solidity_interface(name = "CollectionHelper")]
-	impl<T: Config> EvmCollectionHelper<T> {
-		fn create_721_collection(
-			&self,
-			caller: caller,
-			name: string,
-			description: string,
-			token_prefix: string,
-		) -> Result<address> {
-			let caller = T::CrossAccountId::from_eth(caller);
-			let name = name
-				.encode_utf16()
-				.collect::<Vec<u16>>()
-				.try_into()
-				.map_err(|_| error_feild_too_long(stringify!(name), MAX_COLLECTION_NAME_LENGTH))?;
-			let description = description
-				.encode_utf16()
-				.collect::<Vec<u16>>()
-				.try_into()
-				.map_err(|_| {
-					error_feild_too_long(stringify!(description), MAX_COLLECTION_DESCRIPTION_LENGTH)
-				})?;
-			let token_prefix = token_prefix
-				.into_bytes()
-				.try_into()
-				.map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;
-	
-			let key: string = "tokenURI".into(); //TODO: make static
-			let key: up_data_structs::PropertyKey = key.into_bytes().try_into().map_err(|_| Error::Revert("".into()))?;
-			let permission = up_data_structs::PropertyPermission {
-				mutable: true,
-				collection_admin: true,
-				token_owner: false,
-			};
-			let mut token_property_permissions = up_data_structs::CollectionPropertiesPermissionsVec::default();
-			token_property_permissions.try_push(up_data_structs::PropertyKeyPermission{
-				key,
-				permission,
-			}).map_err(|e| Error::Revert(format!("{:?}", e)))?;
+		let data = CreateCollectionData {
+			name,
+			description,
+			token_prefix,
+			token_property_permissions,
+			..Default::default()
+		};
 
-			let data = CreateCollectionData {
-				name,
-				description,
-				token_prefix,
-				token_property_permissions,
-				..Default::default()
-			};
-	
-			let collection_id =
-				<pallet_nonfungible::Pallet<T>>::init_collection(caller.as_sub().clone(), data)
-					.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
-	
-			let address = pallet_common::eth::collection_id_to_address(collection_id);
-			<PalletEvm<T>>::deposit_log(
-				EthCollectionEvent::CollectionCreated {
-					owner: *caller.as_eth(),
-					collection_id: address,
-				}
-				.to_log(address),
-			);
-			Ok(address)
-		}
+		let collection_id =
+			<pallet_nonfungible::Pallet<T>>::init_collection(caller.as_sub().clone(), data)
+				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
 
-		fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {
-			if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {
-				let collection_id = id;
-				return Ok(<CollectionById<T>>::contains_key(collection_id));
+		let address = pallet_common::eth::collection_id_to_address(collection_id);
+		<PalletEvm<T>>::deposit_log(
+			EthCollectionEvent::CollectionCreated {
+				owner: *caller.as_eth(),
+				collection_id: address,
 			}
+			.to_log(address),
+		);
+		Ok(address)
+	}
 
-			Ok(false)
+	fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {
+		if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {
+			let collection_id = id;
+			return Ok(<CollectionById<T>>::contains_key(collection_id));
 		}
+
+		Ok(false)
+	}
+}
+
+#[derive(ToLog)]
+pub enum EthCollectionEvent {
+	CollectionCreated {
+		#[indexed]
+		owner: address,
+		#[indexed]
+		collection_id: address,
+	},
+}
+
+pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);
+impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {
+	fn is_reserved(contract: &sp_core::H160) -> bool {
+		contract == &T::ContractAddress::get()
 	}
-	
-	#[derive(ToLog)]
-	pub enum EthCollectionEvent {
-		CollectionCreated {
-			#[indexed]
-			owner: address,
-			#[indexed]
-			collection_id: address,
-		},
+
+	fn is_used(contract: &sp_core::H160) -> bool {
+		contract == &T::ContractAddress::get()
 	}
 
-	pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);
-	impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {
-		fn is_reserved(contract: &sp_core::H160) -> bool {
-			contract == &T::ContractAddress::get()
-		}
-	
-		fn is_used(contract: &sp_core::H160) -> bool {
-			contract == &T::ContractAddress::get()
+	fn call(
+		source: &sp_core::H160,
+		target: &sp_core::H160,
+		gas_left: u64,
+		input: &[u8],
+		value: sp_core::U256,
+	) -> Option<PrecompileResult> {
+		if target != &T::ContractAddress::get() {
+			return None;
 		}
-	
-		fn call(
-			source: &sp_core::H160,
-			target: &sp_core::H160,
-			gas_left: u64,
-			input: &[u8],
-			value: sp_core::U256,
-		) -> Option<PrecompileResult> {
-			if target != &T::ContractAddress::get() {
-				return None;
-			}
-	
-			let helpers = EvmCollectionHelper::<T>(SubstrateRecorder::<T>::new(gas_left));
-			pallet_evm_coder_substrate::call(*source, helpers, value, input)
-		}
-	
-		fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
-			(contract == &T::ContractAddress::get())
-				.then(|| include_bytes!("./stubs/CollectionHelper.raw").to_vec())
-		}
+
+		let helpers = EvmCollectionHelper::<T>(SubstrateRecorder::<T>::new(gas_left));
+		pallet_evm_coder_substrate::call(*source, helpers, value, input)
 	}
-	
-	generate_stubgen!(collection_helper_impl, CollectionHelperCall<()>, true);
-	generate_stubgen!(collection_helper_iface, CollectionHelperCall<()>, false);
 
-	fn error_feild_too_long(feild: &str, bound: u32) -> Error {
-		Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))
+	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
+		(contract == &T::ContractAddress::get())
+			.then(|| include_bytes!("./stubs/CollectionHelper.raw").to_vec())
 	}
 }
+
+generate_stubgen!(collection_helper_impl, CollectionHelperCall<()>, true);
+generate_stubgen!(collection_helper_iface, CollectionHelperCall<()>, false);
+
+fn error_feild_too_long(feild: &str, bound: u32) -> Error {
+	Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))
+}
modifiedpallets/unique/src/eth/stubs/CollectionHelper.rawdiffbeforeafterboth

binary blob — no preview

modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -80,7 +80,6 @@
 };
 use smallvec::smallvec;
 use codec::{Encode, Decode};
-use pallet_unique::eth::evm_collection;
 use fp_rpc::TransactionStatus;
 use sp_runtime::{
 	traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},
@@ -307,7 +306,7 @@
 		pallet_evm_migration::OnMethodCall<Self>,
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
-		evm_collection::CollectionHelperOnMethodCall<Self>,
+		pallet_unique::eth::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
 	type ChainId = ChainId;
@@ -988,7 +987,7 @@
 	type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
 }
 
-impl evm_collection::Config for Runtime {
+impl pallet_unique::eth::Config for Runtime {
 	type ContractAddress = EvmCollectionHelperAddress;
 }
 
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -78,7 +78,6 @@
 };
 use smallvec::smallvec;
 use codec::{Encode, Decode};
-use pallet_unique::eth::evm_collection;
 use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping};
 use fp_rpc::TransactionStatus;
 use sp_runtime::{
@@ -286,7 +285,7 @@
 		pallet_evm_migration::OnMethodCall<Self>,
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
-		evm_collection::CollectionHelperOnMethodCall<Self>,
+		pallet_unique::eth::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
 	type ChainId = ChainId;
@@ -973,7 +972,7 @@
 	type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
 }
 
-impl evm_collection::Config for Runtime {
+impl pallet_unique::eth::Config for Runtime {
 	type ContractAddress = EvmCollectionHelperAddress;
 }
 
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
85};85};
86use smallvec::smallvec;86use smallvec::smallvec;
87use codec::{Encode, Decode};87use codec::{Encode, Decode};
88use pallet_unique::eth::evm_collection;
89use fp_rpc::TransactionStatus;88use fp_rpc::TransactionStatus;
90use sp_runtime::{89use sp_runtime::{
91 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},90 traits::{BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating},
291 pallet_evm_migration::OnMethodCall<Self>,290 pallet_evm_migration::OnMethodCall<Self>,
292 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,291 pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
293 CollectionDispatchT<Self>,292 CollectionDispatchT<Self>,
294 evm_collection::CollectionHelperOnMethodCall<Self>,293 pallet_unique::eth::CollectionHelperOnMethodCall<Self>,
295 );294 );
296 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;295 type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
297 type ChainId = ChainId;296 type ChainId = ChainId;
978 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;977 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
979}978}
980979
981impl evm_collection::Config for Runtime {980impl pallet_unique::eth::Config for Runtime {
982 type ContractAddress = EvmCollectionHelperAddress;981 type ContractAddress = EvmCollectionHelperAddress;
983}982}
984983