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

difftreelog

refactor eth::Property

Trubnikov Sergey2022-12-21parent: #99fddf0.patch.diff
in: master

13 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -33,9 +33,7 @@
 use alloc::format;
 
 use crate::{
-	Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
-	eth::{CollectionLimitField as EvmCollectionLimits, self},
-	weights::WeightInfo,
+	Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf, eth, weights::WeightInfo,
 };
 
 /// Events for ethereum collection helper.
@@ -125,7 +123,8 @@
 
 		let properties = properties
 			.into_iter()
-			.map(|eth::Property { key, value }| {
+			.map(|property| {
+				let (key, value) = property.take_key_value();
 				let key = <Vec<u8>>::from(key)
 					.try_into()
 					.map_err(|_| "key too large")?;
@@ -215,7 +214,7 @@
 				let key =
 					string::from_utf8(p.key.into()).map_err(|e| Error::Revert(format!("{}", e)))?;
 				let value = bytes(p.value.to_vec());
-				Ok(eth::Property { key, value })
+				Ok(eth::Property::new(key, value))
 			})
 			.collect::<Result<Vec<_>>>()?;
 		Ok(properties)
@@ -302,11 +301,11 @@
 
 		Ok(vec![
 			eth::CollectionLimit::from_opt_int(
-				EvmCollectionLimits::AccountTokenOwnership,
+				eth::CollectionLimitField::AccountTokenOwnership,
 				limits.account_token_ownership_limit,
 			),
 			eth::CollectionLimit::from_opt_int(
-				EvmCollectionLimits::SponsoredDataSize,
+				eth::CollectionLimitField::SponsoredDataSize,
 				limits.sponsored_data_size,
 			),
 			limits
@@ -314,7 +313,7 @@
 				.and_then(|limit| {
 					if let SponsoringRateLimit::Blocks(blocks) = limit {
 						Some(eth::CollectionLimit::from_int(
-							EvmCollectionLimits::SponsoredDataRateLimit,
+							eth::CollectionLimitField::SponsoredDataRateLimit,
 							blocks,
 						))
 					} else {
@@ -322,28 +321,31 @@
 					}
 				})
 				.unwrap_or(eth::CollectionLimit::from_int(
-					EvmCollectionLimits::SponsoredDataRateLimit,
+					eth::CollectionLimitField::SponsoredDataRateLimit,
 					Default::default(),
 				)),
-			eth::CollectionLimit::from_opt_int(EvmCollectionLimits::TokenLimit, limits.token_limit),
 			eth::CollectionLimit::from_opt_int(
-				EvmCollectionLimits::SponsorTransferTimeout,
+				eth::CollectionLimitField::TokenLimit,
+				limits.token_limit,
+			),
+			eth::CollectionLimit::from_opt_int(
+				eth::CollectionLimitField::SponsorTransferTimeout,
 				limits.sponsor_transfer_timeout,
 			),
 			eth::CollectionLimit::from_opt_int(
-				EvmCollectionLimits::SponsorApproveTimeout,
+				eth::CollectionLimitField::SponsorApproveTimeout,
 				limits.sponsor_approve_timeout,
 			),
 			eth::CollectionLimit::from_opt_bool(
-				EvmCollectionLimits::OwnerCanTransfer,
+				eth::CollectionLimitField::OwnerCanTransfer,
 				limits.owner_can_transfer,
 			),
 			eth::CollectionLimit::from_opt_bool(
-				EvmCollectionLimits::OwnerCanDestroy,
+				eth::CollectionLimitField::OwnerCanDestroy,
 				limits.owner_can_destroy,
 			),
 			eth::CollectionLimit::from_opt_bool(
-				EvmCollectionLimits::TransferEnabled,
+				eth::CollectionLimitField::TransferEnabled,
 				limits.transfers_enabled,
 			),
 		])
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -171,10 +171,18 @@
 /// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 #[derive(Debug, Default, AbiCoder)]
 pub struct Property {
-	/// Property key.
-	pub key: evm_coder::types::string,
-	/// Property value.
-	pub value: evm_coder::types::bytes,
+	key: evm_coder::types::string,
+	value: evm_coder::types::bytes,
+}
+
+impl Property {
+	pub fn new(key: evm_coder::types::string, value: evm_coder::types::bytes) -> Self {
+		Self { key, value }
+	}
+
+	pub fn take_key_value(self) -> (evm_coder::types::string, evm_coder::types::bytes) {
+		(self.key, self.value)
+	}
 }
 
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) fields representation for EVM.
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -499,9 +499,7 @@
 
 /// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 struct Property {
-	/// @dev Property key.
 	string key;
-	/// @dev Property value.
 	bytes value;
 }
 
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
170170
171 let properties = properties171 let properties = properties
172 .into_iter()172 .into_iter()
173 .map(|pallet_common::eth::Property { key, value }| {173 .map(|property| {
174 let (key, value) = property.take_key_value();
174 let key = <Vec<u8>>::from(key)175 let key = <Vec<u8>>::from(key)
175 .try_into()176 .try_into()
176 .map_err(|_| "key too large")?;177 .map_err(|_| "key too large")?;
177178
178 let value = value.0.try_into().map_err(|_| "value too large")?;179 let value = value.0.try_into().map_err(|_| "value too large")?;
179180
180 Ok(Property { key, value })181 Ok(Property { key, value })
181 })182 })
182 .collect::<Result<Vec<_>>>()?;183 .collect::<Result<Vec<_>>>()?;
183184
184 <Pallet<T>>::set_token_properties(185 <Pallet<T>>::set_token_properties(
796 let key = string::from_utf8(p.key.to_vec())797 let key = string::from_utf8(p.key.to_vec())
797 .map_err(|e| Error::Revert(alloc::format!("{}", e)))?;798 .map_err(|e| Error::Revert(alloc::format!("{}", e)))?;
798 let value = bytes(p.value.to_vec());799 let value = bytes(p.value.to_vec());
799 Ok(pallet_common::eth::Property { key, value })800 Ok(pallet_common::eth::Property::new(key, value))
800 })801 })
801 .collect::<Result<Vec<_>>>()802 .collect::<Result<Vec<_>>>()
802 }803 }
10541055
1055 let properties = properties1056 let properties = properties
1056 .into_iter()1057 .into_iter()
1057 .map(|pallet_common::eth::Property { key, value }| {1058 .map(|property| {
1059 let (key, value) = property.take_key_value();
1058 let key = <Vec<u8>>::from(key)1060 let key = <Vec<u8>>::from(key)
1059 .try_into()1061 .try_into()
1060 .map_err(|_| "key too large")?;1062 .map_err(|_| "key too large")?;
10611063
1062 let value = value.0.try_into().map_err(|_| "value too large")?;1064 let value = value.0.try_into().map_err(|_| "value too large")?;
10631065
1064 Ok(Property { key, value })1066 Ok(Property { key, value })
1065 })1067 })
1066 .collect::<Result<Vec<_>>>()?1068 .collect::<Result<Vec<_>>>()?
1067 .try_into()1069 .try_into()
1068 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;1070 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -129,9 +129,7 @@
 
 /// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 struct Property {
-	/// @dev Property key.
 	string key;
-	/// @dev Property value.
 	bytes value;
 }
 
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -173,7 +173,8 @@
 
 		let properties = properties
 			.into_iter()
-			.map(|pallet_common::eth::Property { key, value }| {
+			.map(|property| {
+				let (key, value) = property.take_key_value();
 				let key = <Vec<u8>>::from(key)
 					.try_into()
 					.map_err(|_| "key too large")?;
@@ -831,7 +832,7 @@
 			let key = string::from_utf8(p.key.to_vec())
 				.map_err(|e| Error::Revert(alloc::format!("{}", e)))?;
 			let value = bytes(p.value.to_vec());
-			Ok(pallet_common::eth::Property { key, value })
+			Ok(pallet_common::eth::Property::new(key, value))
 		})
 		.collect::<Result<Vec<_>>>()
 	}
@@ -1100,7 +1101,8 @@
 
 		let properties = properties
 			.into_iter()
-			.map(|pallet_common::eth::Property { key, value }| {
+			.map(|property| {
+				let (key, value) = property.take_key_value();
 				let key = <Vec<u8>>::from(key)
 					.try_into()
 					.map_err(|_| "key too large")?;
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -129,9 +129,7 @@
 
 /// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 struct Property {
-	/// @dev Property key.
 	string key;
-	/// @dev Property value.
 	bytes value;
 }
 
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -341,9 +341,7 @@
 
 /// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 struct Property {
-	/// @dev Property key.
 	string key;
-	/// @dev Property value.
 	bytes value;
 }
 
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -82,9 +82,7 @@
 
 /// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 struct Property {
-	/// @dev Property key.
 	string key;
-	/// @dev Property value.
 	bytes value;
 }
 
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -82,9 +82,7 @@
 
 /// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
 struct Property {
-	/// @dev Property key.
 	string key;
-	/// @dev Property value.
 	bytes value;
 }