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
before · pallets/common/src/erc.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 evm_coder::{solidity_interface, types::*, execution::{Result, Error}};18pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};19use pallet_evm_coder_substrate::dispatch_to_evm;20use sp_core::{H160, U256};21use sp_std::vec::Vec;22use up_data_structs::{Property, SponsoringRateLimit};23use alloc::format;2425use crate::{Pallet, CollectionHandle, Config, CollectionProperties};2627/// Does not always represent a full collection, for RFT it is either28/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)29pub trait CommonEvmHandler {30	const CODE: &'static [u8];3132	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult>;33}3435#[solidity_interface(name = "Collection")]36impl<T: Config> CollectionHandle<T> {37	fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {38		let caller = T::CrossAccountId::from_eth(caller);39		let key = <Vec<u8>>::from(key)40			.try_into()41			.map_err(|_| "key too large")?;42		let value = value.try_into().map_err(|_| "value too large")?;4344		<Pallet<T>>::set_collection_property(self, &caller, Property { key, value })45			.map_err(dispatch_to_evm::<T>)46	}4748	fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {49		let caller = T::CrossAccountId::from_eth(caller);50		let key = <Vec<u8>>::from(key)51			.try_into()52			.map_err(|_| "key too large")?;5354		<Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)55	}5657	/// Throws error if key not found58	fn collection_property(&self, key: string) -> Result<bytes> {59		let key = <Vec<u8>>::from(key)60			.try_into()61			.map_err(|_| "key too large")?;6263		let props = <CollectionProperties<T>>::get(self.id);64		let prop = props.get(&key).ok_or("key not found")?;6566		Ok(prop.to_vec())67	}6869	fn eth_set_sponsor(70		&mut self,71		caller: caller,72		sponsor: address,73	) -> Result<void> {74		check_is_owner(caller, self)?;7576		let sponsor = T::CrossAccountId::from_eth(sponsor);77		self.set_sponsor(sponsor.as_sub().clone());78		save(self);79		Ok(())80	}8182	fn eth_confirm_sponsorship(&mut self, caller: caller) -> Result<void> {83		let caller = T::CrossAccountId::from_eth(caller);84		if !self.confirm_sponsorship(caller.as_sub()) {85			return Err(Error::Revert("Caller is not set as sponsor".into()));86		}87		save(self);88		Ok(())89	}9091	fn set_limit(92		&mut self,93		caller: caller,94		limit: string,95		value: string,96	) -> Result<void> {97		check_is_owner(caller, self)?;98		let mut limits = self.limits.clone();99100		match limit.as_str() {101			"accountTokenOwnershipLimit" => {102				limits.account_token_ownership_limit = parse_int(value)?;103			},104			"sponsoredDataSize" => {105				limits.sponsored_data_size = parse_int(value)?;106			},107			"sponsoredDataRateLimit" => {108				limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));109			},110			"tokenLimit" => {111				limits.token_limit = parse_int(value)?;112			},113			"sponsorTransferTimeout" => {114				limits.sponsor_transfer_timeout = parse_int(value)?;115			},116			"sponsorApproveTimeout" => {117				limits.sponsor_approve_timeout = parse_int(value)?;118			},119			"ownerCanTransfer" => {120				limits.owner_can_transfer = parse_bool(value)?;121			},122			"ownerCanDestroy" => {123				limits.owner_can_destroy = parse_bool(value)?;124			},125			"transfersEnabled" => {126				limits.transfers_enabled = parse_bool(value)?;127			},128			_ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit)))129		}130		self.limits = limits;131		save(self);132		Ok(())133	}134135	fn contract_address(&self, _caller: caller) -> Result<address> {136		Ok(crate::eth::collection_id_to_address(self.id))137	}138}139140fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {141	let caller = T::CrossAccountId::from_eth(caller);142	collection143		.check_is_owner(&caller)144		.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;145	Ok(())146}147148fn save<T: Config>(collection: &CollectionHandle<T>) {149	<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());150}151152fn parse_int(value: string) -> Result<Option<u32>> {153	value.parse::<u32>()154		.map_err(|e| Error::Revert(format!("Int value \"{}\" parse error: {}", value, e)))155		.map(|value| Some(value))156}157158fn parse_bool(value: string) -> Result<Option<bool>> {159	value.parse::<bool>()160		.map_err(|e| Error::Revert(format!("Bool value \"{}\" parse error: {}", value, e)))161		.map(|value| Some(value))162}
after · pallets/common/src/erc.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 evm_coder::{18	solidity_interface,19	types::*,20	execution::{Result, Error},21};22pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};23use pallet_evm_coder_substrate::dispatch_to_evm;24use sp_core::{H160, U256};25use sp_std::vec::Vec;26use up_data_structs::{Property, SponsoringRateLimit};27use alloc::format;2829use crate::{Pallet, CollectionHandle, Config, CollectionProperties};3031/// Does not always represent a full collection, for RFT it is either32/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)33pub trait CommonEvmHandler {34	const CODE: &'static [u8];3536	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult>;37}3839#[solidity_interface(name = "Collection")]40impl<T: Config> CollectionHandle<T> {41	fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {42		let caller = T::CrossAccountId::from_eth(caller);43		let key = <Vec<u8>>::from(key)44			.try_into()45			.map_err(|_| "key too large")?;46		let value = value.try_into().map_err(|_| "value too large")?;4748		<Pallet<T>>::set_collection_property(self, &caller, Property { key, value })49			.map_err(dispatch_to_evm::<T>)50	}5152	fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {53		let caller = T::CrossAccountId::from_eth(caller);54		let key = <Vec<u8>>::from(key)55			.try_into()56			.map_err(|_| "key too large")?;5758		<Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)59	}6061	/// Throws error if key not found62	fn collection_property(&self, key: string) -> Result<bytes> {63		let key = <Vec<u8>>::from(key)64			.try_into()65			.map_err(|_| "key too large")?;6667		let props = <CollectionProperties<T>>::get(self.id);68		let prop = props.get(&key).ok_or("key not found")?;6970		Ok(prop.to_vec())71	}7273	fn eth_set_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {74		check_is_owner(caller, self)?;7576		let sponsor = T::CrossAccountId::from_eth(sponsor);77		self.set_sponsor(sponsor.as_sub().clone());78		save(self);79		Ok(())80	}8182	fn eth_confirm_sponsorship(&mut self, caller: caller) -> Result<void> {83		let caller = T::CrossAccountId::from_eth(caller);84		if !self.confirm_sponsorship(caller.as_sub()) {85			return Err(Error::Revert("Caller is not set as sponsor".into()));86		}87		save(self);88		Ok(())89	}9091	fn set_limit(&mut self, caller: caller, limit: string, value: string) -> Result<void> {92		check_is_owner(caller, self)?;93		let mut limits = self.limits.clone();9495		match limit.as_str() {96			"accountTokenOwnershipLimit" => {97				limits.account_token_ownership_limit = parse_int(value)?;98			}99			"sponsoredDataSize" => {100				limits.sponsored_data_size = parse_int(value)?;101			}102			"sponsoredDataRateLimit" => {103				limits.sponsored_data_rate_limit =104					Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));105			}106			"tokenLimit" => {107				limits.token_limit = parse_int(value)?;108			}109			"sponsorTransferTimeout" => {110				limits.sponsor_transfer_timeout = parse_int(value)?;111			}112			"sponsorApproveTimeout" => {113				limits.sponsor_approve_timeout = parse_int(value)?;114			}115			"ownerCanTransfer" => {116				limits.owner_can_transfer = parse_bool(value)?;117			}118			"ownerCanDestroy" => {119				limits.owner_can_destroy = parse_bool(value)?;120			}121			"transfersEnabled" => {122				limits.transfers_enabled = parse_bool(value)?;123			}124			_ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit))),125		}126		self.limits = limits;127		save(self);128		Ok(())129	}130131	fn contract_address(&self, _caller: caller) -> Result<address> {132		Ok(crate::eth::collection_id_to_address(self.id))133	}134}135136fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {137	let caller = T::CrossAccountId::from_eth(caller);138	collection139		.check_is_owner(&caller)140		.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;141	Ok(())142}143144fn save<T: Config>(collection: &CollectionHandle<T>) {145	<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());146}147148fn parse_int(value: string) -> Result<Option<u32>> {149	value150		.parse::<u32>()151		.map_err(|e| Error::Revert(format!("Int value \"{}\" parse error: {}", value, e)))152		.map(|value| Some(value))153}154155fn parse_bool(value: string) -> Result<Option<bool>> {156	value157		.parse::<bool>()158		.map_err(|e| Error::Revert(format!("Bool value \"{}\" parse error: {}", value, e)))159		.map(|value| Some(value))160}
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
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -83,11 +83,11 @@
 			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 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,
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,