git.delta.rocks / unique-network / refs/commits / 57eaceedfd43

difftreelog

chore fix code review requests

Grigoriy Simonov2022-09-30parent: #c9c7549.patch.diff
in: master

2 files changed

modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
648 .unwrap_or_else(|| cases::camelcase::to_camel_case(&ident.to_string()));648 .unwrap_or_else(|| cases::camelcase::to_camel_case(&ident.to_string()));
649 let mut selector_str = camel_name.clone();649 let mut selector_str = camel_name.clone();
650 selector_str.push('(');650 selector_str.push('(');
651 let mut normal_args_count = 0u32;
652 let mut has_value_args = false;651 let mut has_normal_args = false;
653 for arg in args.iter() {652 for (i, arg) in args.iter().filter(|arg| !arg.is_special()).enumerate() {
654 if arg.is_value() {
655 has_value_args = true;
656 } else if !arg.is_special() {
657 if normal_args_count != 0 {653 if i != 0 {
658 selector_str.push(',');654 selector_str.push(',');
659 }655 }
660 write!(selector_str, "{}", arg.selector_ty()).unwrap();656 write!(selector_str, "{}", arg.selector_ty()).unwrap();
661 normal_args_count = normal_args_count.saturating_add(1);657 has_normal_args = true;
662 }658 }
663 }
664 let has_normal_args = normal_args_count > 0;659 let has_value_args = args.iter().any(|a| a.is_value());
665 selector_str.push(')');660 selector_str.push(')');
666 let selector = fn_selector_str(&selector_str);661 let selector = fn_selector_str(&selector_str);
667662
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -173,13 +173,7 @@
 		base_uri_value,
 		add_properties,
 	)?;
-	let value = value.as_u128();
-	let creation_price: Result<u128> = T::CollectionCreationPrice::get()
-		.try_into()
-		.map_err(|_| "collection creation price should be convertible to u128".into());
-	if value != creation_price? {
-		return Err("Sent amount not equals to collection creation price".into());
-	}
+	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.clone(), collection_helpers_address, data)
@@ -188,6 +182,18 @@
 	Ok(address)
 }
 
+fn check_sent_amount_equals_collection_creation_price<T: Config>(value: value) -> Result<()> {
+	let value = value.as_u128();
+	let creation_price: u128 = T::CollectionCreationPrice::get()
+		.try_into()
+		.map_err(|_| ()) // workaround for `expect` requiring `Debug` trait
+		.expect("Collection creation price should be convertible to u128");
+	if value != creation_price {
+		return Err(format!("Sent amount not equals to collection creation price ({0})", creation_price).into());
+	}
+	Ok(())
+}
+
 /// @title Contract, which allows users to operate with collections
 #[solidity_interface(name = CollectionHelpers, events(CollectionHelpersEvents))]
 impl<T> EvmCollectionHelpers<T>
@@ -218,14 +224,7 @@
 			Default::default(),
 			false,
 		)?;
-		let value = value.as_u128();
-		let creation_price: Result<u128> = T::CollectionCreationPrice::get()
-			.try_into()
-			.map_err(|_| "collection creation price should be convertible to u128".into());
-		let creation_price = creation_price?;
-		if value != creation_price {
-			return Err(format!("Sent amount not equals to collection creation price ({0})", creation_price).into());
-		}
+		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>)?;
@@ -255,13 +254,7 @@
 			base_uri_value,
 			true,
 		)?;
-		let value = value.as_u128();
-		let creation_price: Result<u128> = T::CollectionCreationPrice::get()
-			.try_into()
-			.map_err(|_| "collection creation price should be convertible to u128".into());
-		if value != creation_price? {
-			return Err("Sent amount not equals to collection creation price".into());
-		}
+		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(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;