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

difftreelog

fix PR

Trubnikov Sergey2022-12-22parent: #a22e53f.patch.diff
in: master

10 files changed

modifiedcrates/evm-coder/procedural/src/abi_derive/derive_enum.rsdiffbeforeafterboth
--- a/crates/evm-coder/procedural/src/abi_derive/derive_enum.rs
+++ b/crates/evm-coder/procedural/src/abi_derive/derive_enum.rs
@@ -47,11 +47,10 @@
 	)
 }
 
-pub fn impl_enum_abi_type(name: &syn::Ident, option_count: usize) -> proc_macro2::TokenStream {
+pub fn impl_enum_abi_type(name: &syn::Ident) -> proc_macro2::TokenStream {
 	quote! {
 		impl ::evm_coder::abi::AbiType for #name {
 			const SIGNATURE: ::evm_coder::custom_signature::SignatureUnit = <u8 as ::evm_coder::abi::AbiType>::SIGNATURE;
-			const FIELDS_COUNT: usize = #option_count;
 
 			fn is_dynamic() -> bool {
 				<u8 as ::evm_coder::abi::AbiType>::is_dynamic()
modifiedcrates/evm-coder/procedural/src/abi_derive/derive_struct.rsdiffbeforeafterboth
--- a/crates/evm-coder/procedural/src/abi_derive/derive_struct.rs
+++ b/crates/evm-coder/procedural/src/abi_derive/derive_struct.rs
@@ -100,12 +100,10 @@
 pub fn impl_struct_abi_type(
 	name: &syn::Ident,
 	tuple_type: proc_macro2::TokenStream,
-	fields_count: usize,
 ) -> proc_macro2::TokenStream {
 	quote! {
 		impl ::evm_coder::abi::AbiType for #name {
 			const SIGNATURE: ::evm_coder::custom_signature::SignatureUnit = <#tuple_type as ::evm_coder::abi::AbiType>::SIGNATURE;
-			const FIELDS_COUNT: usize = #fields_count;
 			fn is_dynamic() -> bool {
 				<#tuple_type as ::evm_coder::abi::AbiType>::is_dynamic()
 			}
modifiedcrates/evm-coder/procedural/src/abi_derive/mod.rsdiffbeforeafterboth
--- a/crates/evm-coder/procedural/src/abi_derive/mod.rs
+++ b/crates/evm-coder/procedural/src/abi_derive/mod.rs
@@ -49,7 +49,7 @@
 	let struct_from_tuple = struct_from_tuple(name, is_named_fields, field_names.clone());
 
 	let can_be_plcaed_in_vec = impl_can_be_placed_in_vec(name);
-	let abi_type = impl_struct_abi_type(name, tuple_type.clone(), params_count);
+	let abi_type = impl_struct_abi_type(name, tuple_type.clone());
 	let abi_read = impl_struct_abi_read(name, tuple_type, tuple_names, struct_from_tuple);
 	let abi_write = impl_struct_abi_write(name, is_named_fields, tuple_ref_type, tuple_data);
 	let solidity_type = impl_struct_solidity_type(name, field_types.clone(), params_count);
@@ -83,7 +83,7 @@
 	let from = impl_enum_from_u8(name, enum_options.clone());
 	let solidity_option = impl_solidity_option(name, enum_options.clone());
 	let can_be_plcaed_in_vec = impl_can_be_placed_in_vec(name);
-	let abi_type = impl_enum_abi_type(name, option_count);
+	let abi_type = impl_enum_abi_type(name);
 	let abi_read = impl_enum_abi_read(name);
 	let abi_write = impl_enum_abi_write(name);
 	let solidity_type = impl_enum_solidity_type(name);
modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -16,7 +16,6 @@
 
 		impl AbiType for $ty {
 			const SIGNATURE: SignatureUnit = make_signature!(new fixed(stringify!($name)));
-			const FIELDS_COUNT: usize = 1;
 
 			fn is_dynamic() -> bool {
 				$dynamic
@@ -97,7 +96,6 @@
 
 impl<T: AbiType> AbiType for &T {
 	const SIGNATURE: SignatureUnit = T::SIGNATURE;
-	const FIELDS_COUNT: usize = T::FIELDS_COUNT;
 
 	fn is_dynamic() -> bool {
 		T::is_dynamic()
@@ -127,7 +125,6 @@
 
 impl<T: AbiType> AbiType for Vec<T> {
 	const SIGNATURE: SignatureUnit = make_signature!(new nameof(T::SIGNATURE) fixed("[]"));
-	const FIELDS_COUNT: usize = 1;
 
 	fn is_dynamic() -> bool {
 		true
@@ -203,7 +200,6 @@
                 shift_left(1)
                 fixed(")")
             );
-			const FIELDS_COUNT: usize = count!($($ident)*);
 
 			fn is_dynamic() -> bool {
 				false
modifiedcrates/evm-coder/src/abi/traits.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi/traits.rs
+++ b/crates/evm-coder/src/abi/traits.rs
@@ -10,9 +10,6 @@
 	/// Signature for Etherium ABI.
 	const SIGNATURE: SignatureUnit;
 
-	/// Count of enum variants or struct fields.
-	const FIELDS_COUNT: usize;
-
 	/// Signature as str.
 	fn as_str() -> &'static str {
 		from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")
modifiedcrates/evm-coder/tests/abi_derive_generation.rsdiffbeforeafterboth
--- a/crates/evm-coder/tests/abi_derive_generation.rs
+++ b/crates/evm-coder/tests/abi_derive_generation.rs
@@ -173,50 +173,6 @@
 	}
 
 	#[test]
-	fn impl_abi_type_fields_count() {
-		assert_eq!(
-			<TypeStruct1SimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			1
-		);
-		assert_eq!(
-			<TypeStruct1DynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			1
-		);
-		assert_eq!(
-			<TypeStruct2SimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			2
-		);
-		assert_eq!(
-			<TypeStruct2DynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			2
-		);
-		assert_eq!(
-			<TypeStruct2MixedParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			2
-		);
-		assert_eq!(
-			<TypeStruct1DerivedSimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			1
-		);
-		assert_eq!(
-			<TypeStruct2DerivedSimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			2
-		);
-		assert_eq!(
-			<TypeStruct1DerivedDynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			1
-		);
-		assert_eq!(
-			<TypeStruct2DerivedDynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			2
-		);
-		assert_eq!(
-			<TypeStruct3DerivedMixedParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
-			3
-		);
-	}
-
-	#[test]
 	fn impl_abi_type_is_dynamic() {
 		assert_eq!(
 			<TypeStruct1SimpleParam as evm_coder::abi::AbiType>::is_dynamic(),
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -347,6 +347,10 @@
 	) -> Result<void> {
 		self.consume_store_reads_and_writes(1, 1)?;
 
+		if !limit.has_value() {
+			return Err(Error::Revert("user can't disable limits".into()));
+		}
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		<Pallet<T>>::update_limits(&caller, self, limit.try_into()?).map_err(dispatch_to_evm::<T>)
 	}
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -264,16 +264,17 @@
 			value: value.into(),
 		}
 	}
+
+	/// Whether the field contains a value.
+	pub fn has_value(&self) -> bool {
+		self.value.status
+	}
 }
 
 impl TryInto<up_data_structs::CollectionLimits> for CollectionLimit {
 	type Error = evm_coder::execution::Error;
 
 	fn try_into(self) -> Result<up_data_structs::CollectionLimits, Self::Error> {
-		if !self.value.status {
-			return Err(Self::Error::Revert("user can't disable limits".into()));
-		}
-
 		let value = self.value.value.try_into().map_err(|error| {
 			Self::Error::Revert(format!(
 				"can't convert value to u32 \"{}\" because: \"{error}\"",
@@ -433,17 +434,6 @@
 		let mut perms = Vec::new();
 
 		for TokenPropertyPermission { key, permissions } in permissions {
-			if permissions.len() > <TokenPermissionField as evm_coder::abi::AbiType>::FIELDS_COUNT {
-				return Err(alloc::format!(
-					"Actual number of fields {} for {}, which exceeds the maximum value of {}",
-					permissions.len(),
-					stringify!(EthTokenPermissions),
-					<TokenPermissionField as evm_coder::abi::AbiType>::FIELDS_COUNT
-				)
-				.as_str()
-				.into());
-			}
-
 			let token_permission = PropertyPermission::from_vec(permissions);
 
 			perms.push(up_data_structs::PropertyKeyPermission {
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -38,6 +38,7 @@
 use pallet_common::{
 	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
 	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
+	eth,
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
 use pallet_evm_coder_substrate::call;
@@ -93,25 +94,21 @@
 	fn set_token_property_permissions(
 		&mut self,
 		caller: caller,
-		permissions: Vec<pallet_common::eth::TokenPropertyPermission>,
+		permissions: Vec<eth::TokenPropertyPermission>,
 	) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
-		let perms = pallet_common::eth::TokenPropertyPermission::into_property_key_permissions(
-			permissions,
-		)?;
+		let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;
 
 		<Pallet<T>>::set_token_property_permissions(self, &caller, perms)
 			.map_err(dispatch_to_evm::<T>)
 	}
 
 	/// @notice Get permissions for token properties.
-	fn token_property_permissions(
-		&self,
-	) -> Result<Vec<pallet_common::eth::TokenPropertyPermission>> {
+	fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {
 		let perms = <Pallet<T>>::token_property_permission(self.id);
 		Ok(perms
 			.into_iter()
-			.map(pallet_common::eth::TokenPropertyPermission::from)
+			.map(eth::TokenPropertyPermission::from)
 			.collect())
 	}
 
@@ -159,7 +156,7 @@
 		&mut self,
 		caller: caller,
 		token_id: uint256,
-		properties: Vec<pallet_common::eth::Property>,
+		properties: Vec<eth::Property>,
 	) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -170,7 +167,7 @@
 
 		let properties = properties
 			.into_iter()
-			.map(pallet_common::eth::Property::try_into)
+			.map(eth::Property::try_into)
 			.collect::<Result<Vec<_>>>()?;
 
 		<Pallet<T>>::set_token_properties(
@@ -753,9 +750,9 @@
 	/// Returns the owner (in cross format) of the token.
 	///
 	/// @param tokenId Id for the token.
-	fn cross_owner_of(&self, token_id: uint256) -> Result<pallet_common::eth::CrossAddress> {
+	fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {
 		Self::token_owner(&self, token_id.try_into()?)
-			.map(|o| pallet_common::eth::CrossAddress::from_sub_cross_account::<T>(&o))
+			.map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
 			.ok_or(Error::Revert("key too large".into()))
 	}
 
@@ -764,11 +761,7 @@
 	/// @param tokenId Id for the token.
 	/// @param keys Properties keys. Empty keys for all propertyes.
 	/// @return Vector of properties key/value pairs.
-	fn properties(
-		&self,
-		token_id: uint256,
-		keys: Vec<string>,
-	) -> Result<Vec<pallet_common::eth::Property>> {
+	fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
 		let keys = keys
 			.into_iter()
 			.map(|key| {
@@ -784,7 +777,7 @@
 			if keys.is_empty() { None } else { Some(keys) },
 		)
 		.into_iter()
-		.map(pallet_common::eth::Property::try_from)
+		.map(eth::Property::try_from)
 		.collect::<Result<Vec<_>>>()
 	}
 
@@ -798,7 +791,7 @@
 	fn approve_cross(
 		&mut self,
 		caller: caller,
-		approved: pallet_common::eth::CrossAddress,
+		approved: eth::CrossAddress,
 		token_id: uint256,
 	) -> Result<void> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -837,7 +830,7 @@
 	fn transfer_cross(
 		&mut self,
 		caller: caller,
-		to: pallet_common::eth::CrossAddress,
+		to: eth::CrossAddress,
 		token_id: uint256,
 	) -> Result<void> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -861,8 +854,8 @@
 	fn transfer_from_cross(
 		&mut self,
 		caller: caller,
-		from: pallet_common::eth::CrossAddress,
-		to: pallet_common::eth::CrossAddress,
+		from: eth::CrossAddress,
+		to: eth::CrossAddress,
 		token_id: uint256,
 	) -> Result<void> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -908,7 +901,7 @@
 	fn burn_from_cross(
 		&mut self,
 		caller: caller,
-		from: pallet_common::eth::CrossAddress,
+		from: eth::CrossAddress,
 		token_id: uint256,
 	) -> Result<void> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -1030,8 +1023,8 @@
 	fn mint_cross(
 		&mut self,
 		caller: caller,
-		to: pallet_common::eth::CrossAddress,
-		properties: Vec<pallet_common::eth::Property>,
+		to: eth::CrossAddress,
+		properties: Vec<eth::Property>,
 	) -> Result<uint256> {
 		let token_id = <TokensMinted<T>>::get(self.id)
 			.checked_add(1)
@@ -1041,7 +1034,7 @@
 
 		let properties = properties
 			.into_iter()
-			.map(pallet_common::eth::Property::try_into)
+			.map(eth::Property::try_into)
 			.collect::<Result<Vec<_>>>()?
 			.try_into()
 			.map_err(|_| Error::Revert(alloc::format!("too many properties")))?;
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
32use frame_support::{BoundedBTreeMap, BoundedVec};32use frame_support::{BoundedBTreeMap, BoundedVec};
33use pallet_common::{33use pallet_common::{
34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
35 Error as CommonError,
35 erc::{CommonEvmHandler, CollectionCall, static_property::key},36 erc::{CommonEvmHandler, CollectionCall, static_property::key},
36 Error as CommonError,37 eth,
37};38};
38use pallet_evm::{account::CrossAccountId, PrecompileHandle};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};
39use pallet_evm_coder_substrate::{call, dispatch_to_evm};40use pallet_evm_coder_substrate::{call, dispatch_to_evm};
96 fn set_token_property_permissions(97 fn set_token_property_permissions(
97 &mut self,98 &mut self,
98 caller: caller,99 caller: caller,
99 permissions: Vec<pallet_common::eth::TokenPropertyPermission>,100 permissions: Vec<eth::TokenPropertyPermission>,
100 ) -> Result<()> {101 ) -> Result<()> {
101 let caller = T::CrossAccountId::from_eth(caller);102 let caller = T::CrossAccountId::from_eth(caller);
102 let perms = pallet_common::eth::TokenPropertyPermission::into_property_key_permissions(103 let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;
103 permissions,
104 )?;
105104
110 /// @notice Get permissions for token properties.109 /// @notice Get permissions for token properties.
111 fn token_property_permissions(110 fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {
112 &self,
113 ) -> Result<Vec<pallet_common::eth::TokenPropertyPermission>> {
114 let perms = <Pallet<T>>::token_property_permission(self.id);111 let perms = <Pallet<T>>::token_property_permission(self.id);
115 Ok(perms112 Ok(perms
116 .into_iter()113 .into_iter()
117 .map(pallet_common::eth::TokenPropertyPermission::from)114 .map(eth::TokenPropertyPermission::from)
118 .collect())115 .collect())
119 }116 }
120117
162 &mut self,159 &mut self,
163 caller: caller,160 caller: caller,
164 token_id: uint256,161 token_id: uint256,
165 properties: Vec<pallet_common::eth::Property>,162 properties: Vec<eth::Property>,
166 ) -> Result<()> {163 ) -> Result<()> {
167 let caller = T::CrossAccountId::from_eth(caller);164 let caller = T::CrossAccountId::from_eth(caller);
168 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;165 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
173170
174 let properties = properties171 let properties = properties
175 .into_iter()172 .into_iter()
176 .map(pallet_common::eth::Property::try_into)173 .map(eth::Property::try_into)
177 .collect::<Result<Vec<_>>>()?;174 .collect::<Result<Vec<_>>>()?;
178175
179 <Pallet<T>>::set_token_properties(176 <Pallet<T>>::set_token_properties(
788 /// Returns the owner (in cross format) of the token.785 /// Returns the owner (in cross format) of the token.
789 ///786 ///
790 /// @param tokenId Id for the token.787 /// @param tokenId Id for the token.
791 fn cross_owner_of(&self, token_id: uint256) -> Result<pallet_common::eth::CrossAddress> {788 fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {
792 Self::token_owner(&self, token_id.try_into()?)789 Self::token_owner(&self, token_id.try_into()?)
793 .map(|o| pallet_common::eth::CrossAddress::from_sub_cross_account::<T>(&o))790 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
794 .ok_or(Error::Revert("key too large".into()))791 .ok_or(Error::Revert("key too large".into()))
795 }792 }
796793
803 &self,
804 token_id: uint256,
805 keys: Vec<string>,
806 ) -> Result<Vec<pallet_common::eth::Property>> {
807 let keys = keys800 let keys = keys
808 .into_iter()801 .into_iter()
809 .map(|key| {802 .map(|key| {
819 if keys.is_empty() { None } else { Some(keys) },812 if keys.is_empty() { None } else { Some(keys) },
820 )813 )
821 .into_iter()814 .into_iter()
822 .map(pallet_common::eth::Property::try_from)815 .map(eth::Property::try_from)
823 .collect::<Result<Vec<_>>>()816 .collect::<Result<Vec<_>>>()
824 }817 }
825 /// @notice Transfer ownership of an RFT818 /// @notice Transfer ownership of an RFT
855 fn transfer_cross(848 fn transfer_cross(
856 &mut self,849 &mut self,
857 caller: caller,850 caller: caller,
858 to: pallet_common::eth::CrossAddress,851 to: eth::CrossAddress,
859 token_id: uint256,852 token_id: uint256,
860 ) -> Result<void> {853 ) -> Result<void> {
861 let caller = T::CrossAccountId::from_eth(caller);854 let caller = T::CrossAccountId::from_eth(caller);
883 fn transfer_from_cross(876 fn transfer_from_cross(
884 &mut self,877 &mut self,
885 caller: caller,878 caller: caller,
886 from: pallet_common::eth::CrossAddress,879 from: eth::CrossAddress,
887 to: pallet_common::eth::CrossAddress,880 to: eth::CrossAddress,
888 token_id: uint256,881 token_id: uint256,
889 ) -> Result<void> {882 ) -> Result<void> {
890 let caller = T::CrossAccountId::from_eth(caller);883 let caller = T::CrossAccountId::from_eth(caller);
939 fn burn_from_cross(932 fn burn_from_cross(
940 &mut self,933 &mut self,
941 caller: caller,934 caller: caller,
942 from: pallet_common::eth::CrossAddress,935 from: eth::CrossAddress,
943 token_id: uint256,936 token_id: uint256,
944 ) -> Result<void> {937 ) -> Result<void> {
945 let caller = T::CrossAccountId::from_eth(caller);938 let caller = T::CrossAccountId::from_eth(caller);
1076 fn mint_cross(1069 fn mint_cross(
1077 &mut self,1070 &mut self,
1078 caller: caller,1071 caller: caller,
1079 to: pallet_common::eth::CrossAddress,1072 to: eth::CrossAddress,
1080 properties: Vec<pallet_common::eth::Property>,1073 properties: Vec<eth::Property>,
1081 ) -> Result<uint256> {1074 ) -> Result<uint256> {
1082 let token_id = <TokensMinted<T>>::get(self.id)1075 let token_id = <TokensMinted<T>>::get(self.id)
1083 .checked_add(1)1076 .checked_add(1)
10871080
1088 let properties = properties1081 let properties = properties
1089 .into_iter()1082 .into_iter()
1090 .map(pallet_common::eth::Property::try_into)1083 .map(eth::Property::try_into)
1091 .collect::<Result<Vec<_>>>()?1084 .collect::<Result<Vec<_>>>()?
1092 .try_into()1085 .try_into()
1093 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;1086 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;