git.delta.rocks / unique-network / refs/commits / 58de5ce0e935

difftreelog

CArgo fmt

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

6 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -14,7 +14,11 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-use evm_coder::{solidity_interface, types::*, execution::{Result, Error}};
+use evm_coder::{
+	solidity_interface,
+	types::*,
+	execution::{Result, Error},
+};
 pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};
 use pallet_evm_coder_substrate::dispatch_to_evm;
 use sp_core::{H160, U256};
@@ -66,11 +70,7 @@
 		Ok(prop.to_vec())
 	}
 
-	fn eth_set_sponsor(
-		&mut self,
-		caller: caller,
-		sponsor: address,
-	) -> Result<void> {
+	fn eth_set_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {
 		check_is_owner(caller, self)?;
 
 		let sponsor = T::CrossAccountId::from_eth(sponsor);
@@ -88,44 +88,40 @@
 		Ok(())
 	}
 
-	fn set_limit(
-		&mut self,
-		caller: caller,
-		limit: string,
-		value: string,
-	) -> Result<void> {
+	fn set_limit(&mut self, caller: caller, limit: string, value: string) -> Result<void> {
 		check_is_owner(caller, self)?;
 		let mut limits = self.limits.clone();
 
 		match limit.as_str() {
 			"accountTokenOwnershipLimit" => {
 				limits.account_token_ownership_limit = parse_int(value)?;
-			},
+			}
 			"sponsoredDataSize" => {
 				limits.sponsored_data_size = parse_int(value)?;
-			},
+			}
 			"sponsoredDataRateLimit" => {
-				limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));
-			},
+				limits.sponsored_data_rate_limit =
+					Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));
+			}
 			"tokenLimit" => {
 				limits.token_limit = parse_int(value)?;
-			},
+			}
 			"sponsorTransferTimeout" => {
 				limits.sponsor_transfer_timeout = parse_int(value)?;
-			},
+			}
 			"sponsorApproveTimeout" => {
 				limits.sponsor_approve_timeout = parse_int(value)?;
-			},
+			}
 			"ownerCanTransfer" => {
 				limits.owner_can_transfer = parse_bool(value)?;
-			},
+			}
 			"ownerCanDestroy" => {
 				limits.owner_can_destroy = parse_bool(value)?;
-			},
+			}
 			"transfersEnabled" => {
 				limits.transfers_enabled = parse_bool(value)?;
-			},
-			_ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit)))
+			}
+			_ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit))),
 		}
 		self.limits = limits;
 		save(self);
@@ -150,13 +146,15 @@
 }
 
 fn parse_int(value: string) -> Result<Option<u32>> {
-	value.parse::<u32>()
+	value
+		.parse::<u32>()
 		.map_err(|e| Error::Revert(format!("Int value \"{}\" parse error: {}", value, e)))
 		.map(|value| Some(value))
 }
 
 fn parse_bool(value: string) -> Result<Option<bool>> {
-	value.parse::<bool>()
+	value
+		.parse::<bool>()
 		.map_err(|e| Error::Revert(format!("Bool value \"{}\" parse error: {}", value, e)))
 		.map(|value| Some(value))
-}
\ No newline at end of file
+}
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -20,7 +20,7 @@
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
 use pallet_evm::{
 	ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,
-	account::CrossAccountId
+	account::CrossAccountId,
 };
 use sp_core::H160;
 use crate::{
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -23,6 +23,7 @@
 };
 use pallet_common::{
 	CommonCollectionOperations, CommonWeightInfo, with_weight, weights::WeightInfo as _,
+	PropertyKeyPermission,
 };
 use sp_runtime::DispatchError;
 use sp_std::vec::Vec;
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -21,7 +21,10 @@
 };
 use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
 use frame_support::BoundedVec;
-use up_data_structs::{TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey, CollectionPropertiesVec};
+use up_data_structs::{
+	TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property, CollectionId,
+	PropertyKey, CollectionPropertiesVec,
+};
 use pallet_evm_coder_substrate::dispatch_to_evm;
 use sp_core::{H160, U256};
 use sp_std::vec::Vec;
@@ -382,11 +385,15 @@
 		}
 
 		let mut properties = CollectionPropertiesVec::default();
-		properties.try_push(Property{
-			key,
-			value: token_uri.into_bytes().try_into()
-				.map_err(|_| "token uri is too long")?
-		}).map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;
+		properties
+			.try_push(Property {
+				key,
+				value: token_uri
+					.into_bytes()
+					.try_into()
+					.map_err(|_| "token uri is too long")?,
+			})
+			.map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;
 
 		<Pallet<T>>::create_item(
 			self,
@@ -407,10 +414,14 @@
 	}
 }
 
-fn get_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> Result<PropertyPermission> {
+fn get_token_permission<T: Config>(
+	collection_id: CollectionId,
+	key: &PropertyKey,
+) -> Result<PropertyPermission> {
 	let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)
 		.map_err(|_| Error::Revert("No permissions for collection".into()))?;
-	let a = token_property_permissions.get(key)
+	let a = token_property_permissions
+		.get(key)
 		.map(|p| p.clone())
 		.ok_or_else(|| Error::Revert("No permission for tokenURI".into()))?;
 	Ok(a)
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
before · pallets/unique/src/eth/mod.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;18use evm_coder::{execution::*, generate_stubgen, solidity_interface, types::*, ToLog};19use ethereum as _;20use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};21use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, Pallet as PalletEvm};22use up_data_structs::{23	CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,24	MAX_COLLECTION_NAME_LENGTH,25};26use frame_support::traits::Get;27use sp_core::H160;28use pallet_common::CollectionById;2930use sp_std::vec::Vec;31use alloc::format;3233pub trait Config:34	frame_system::Config35	+ pallet_evm_coder_substrate::Config36	+ pallet_evm::account::Config37	+ pallet_nonfungible::Config38{39	type ContractAddress: Get<H160>;40}4142struct EvmCollectionHelper<T: Config>(SubstrateRecorder<T>);43impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {44	fn recorder(&self) -> &SubstrateRecorder<T> {45		&self.046	}4748	fn into_recorder(self) -> SubstrateRecorder<T> {49		self.050	}51}5253#[solidity_interface(name = "CollectionHelper")]54impl<T: Config> EvmCollectionHelper<T> {55	fn create_721_collection(56		&self,57		caller: caller,58		name: string,59		description: string,60		token_prefix: string,61	) -> Result<address> {62		let caller = T::CrossAccountId::from_eth(caller);63		let name = name64			.encode_utf16()65			.collect::<Vec<u16>>()66			.try_into()67			.map_err(|_| error_feild_too_long(stringify!(name), MAX_COLLECTION_NAME_LENGTH))?;68		let description = description69			.encode_utf16()70			.collect::<Vec<u16>>()71			.try_into()72			.map_err(|_| {73				error_feild_too_long(stringify!(description), MAX_COLLECTION_DESCRIPTION_LENGTH)74			})?;75		let token_prefix = token_prefix76			.into_bytes()77			.try_into()78			.map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;7980		let key = pallet_common::eth::KEY_TOKEN_URI.clone();81		let permission = up_data_structs::PropertyPermission {82			mutable: true,83			collection_admin: true,84			token_owner: false,85		};86		let mut token_property_permissions = up_data_structs::CollectionPropertiesPermissionsVec::default();87		token_property_permissions.try_push(up_data_structs::PropertyKeyPermission{88			key,89			permission,90		}).map_err(|e| Error::Revert(format!("{:?}", e)))?;9192		let data = CreateCollectionData {93			name,94			description,95			token_prefix,96			token_property_permissions,97			..Default::default()98		};99100		let collection_id =101			<pallet_nonfungible::Pallet<T>>::init_collection(caller.as_sub().clone(), data)102				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;103104		let address = pallet_common::eth::collection_id_to_address(collection_id);105		<PalletEvm<T>>::deposit_log(106			EthCollectionEvent::CollectionCreated {107				owner: *caller.as_eth(),108				collection_id: address,109			}110			.to_log(address),111		);112		Ok(address)113	}114115	fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {116		if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {117			let collection_id = id;118			return Ok(<CollectionById<T>>::contains_key(collection_id));119		}120121		Ok(false)122	}123}124125#[derive(ToLog)]126pub enum EthCollectionEvent {127	CollectionCreated {128		#[indexed]129		owner: address,130		#[indexed]131		collection_id: address,132	},133}134135pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);136impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {137	fn is_reserved(contract: &sp_core::H160) -> bool {138		contract == &T::ContractAddress::get()139	}140141	fn is_used(contract: &sp_core::H160) -> bool {142		contract == &T::ContractAddress::get()143	}144145	fn call(146		source: &sp_core::H160,147		target: &sp_core::H160,148		gas_left: u64,149		input: &[u8],150		value: sp_core::U256,151	) -> Option<PrecompileResult> {152		if target != &T::ContractAddress::get() {153			return None;154		}155156		let helpers = EvmCollectionHelper::<T>(SubstrateRecorder::<T>::new(gas_left));157		pallet_evm_coder_substrate::call(*source, helpers, value, input)158	}159160	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {161		(contract == &T::ContractAddress::get())162			.then(|| include_bytes!("./stubs/CollectionHelper.raw").to_vec())163	}164}165166generate_stubgen!(collection_helper_impl, CollectionHelperCall<()>, true);167generate_stubgen!(collection_helper_iface, CollectionHelperCall<()>, false);168169fn error_feild_too_long(feild: &str, bound: u32) -> Error {170	Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))171}
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -49,8 +49,8 @@
 // A few exports that help ease life for downstream crates.
 pub use pallet_balances::Call as BalancesCall;
 pub use pallet_evm::{
-	EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _, OnMethodCall,
-	Account as EVMAccount, FeeCalculator, GasWeightMapping,
+	EnsureAddressTruncated, HashedAddressMapping, Runner, account::CrossAccountId as _,
+	OnMethodCall, Account as EVMAccount, FeeCalculator, GasWeightMapping,
 };
 pub use frame_support::{
 	construct_runtime, match_types,