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
173 base_uri_value,173 base_uri_value,
174 add_properties,174 add_properties,
175 )?;175 )?;
176 let value = value.as_u128();
177 let creation_price: Result<u128> = T::CollectionCreationPrice::get()176 check_sent_amount_equals_collection_creation_price::<T>(value)?;
178 .try_into()
179 .map_err(|_| "collection creation price should be convertible to u128".into());
180 if value != creation_price? {
181 return Err("Sent amount not equals to collection creation price".into());
182 }
183 let collection_helpers_address = T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());177 let collection_helpers_address = T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
184178
185 let collection_id = T::CollectionDispatch::create(caller.clone(), collection_helpers_address, data)179 let collection_id = T::CollectionDispatch::create(caller.clone(), collection_helpers_address, data)
188 Ok(address)182 Ok(address)
189}183}
184
185fn check_sent_amount_equals_collection_creation_price<T: Config>(value: value) -> Result<()> {
186 let value = value.as_u128();
187 let creation_price: u128 = T::CollectionCreationPrice::get()
188 .try_into()
189 .map_err(|_| ()) // workaround for `expect` requiring `Debug` trait
190 .expect("Collection creation price should be convertible to u128");
191 if value != creation_price {
192 return Err(format!("Sent amount not equals to collection creation price ({0})", creation_price).into());
193 }
194 Ok(())
195}
190196
191/// @title Contract, which allows users to operate with collections197/// @title Contract, which allows users to operate with collections
192#[solidity_interface(name = CollectionHelpers, events(CollectionHelpersEvents))]198#[solidity_interface(name = CollectionHelpers, events(CollectionHelpersEvents))]
218 Default::default(),224 Default::default(),
219 false,225 false,
220 )?;226 )?;
221 let value = value.as_u128();
222 let creation_price: Result<u128> = T::CollectionCreationPrice::get()227 check_sent_amount_equals_collection_creation_price::<T>(value)?;
223 .try_into()
224 .map_err(|_| "collection creation price should be convertible to u128".into());
225 let creation_price = creation_price?;
226 if value != creation_price {
227 return Err(format!("Sent amount not equals to collection creation price ({0})", creation_price).into());
228 }
229 let collection_helpers_address = T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());228 let collection_helpers_address = T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
230 let collection_id =229 let collection_id =
231 T::CollectionDispatch::create(caller, collection_helpers_address, data).map_err(dispatch_to_evm::<T>)?;230 T::CollectionDispatch::create(caller, collection_helpers_address, data).map_err(dispatch_to_evm::<T>)?;
255 base_uri_value,254 base_uri_value,
256 true,255 true,
257 )?;256 )?;
258 let value = value.as_u128();
259 let creation_price: Result<u128> = T::CollectionCreationPrice::get()257 check_sent_amount_equals_collection_creation_price::<T>(value)?;
260 .try_into()
261 .map_err(|_| "collection creation price should be convertible to u128".into());
262 if value != creation_price? {
263 return Err("Sent amount not equals to collection creation price".into());
264 }
265 let collection_helpers_address = T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());258 let collection_helpers_address = T::CrossAccountId::from_eth(<T as pallet_common::Config>::ContractAddress::get());
266 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)259 let collection_id = T::CollectionDispatch::create(caller, collection_helpers_address, data)
267 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;260 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;