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
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -170,7 +170,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")?;
@@ -796,7 +797,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<_>>>()
 	}
@@ -1054,7 +1055,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/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
173173
174 let properties = properties174 let properties = properties
175 .into_iter()175 .into_iter()
176 .map(|pallet_common::eth::Property { key, value }| {176 .map(|property| {
177 let (key, value) = property.take_key_value();
177 let key = <Vec<u8>>::from(key)178 let key = <Vec<u8>>::from(key)
178 .try_into()179 .try_into()
179 .map_err(|_| "key too large")?;180 .map_err(|_| "key too large")?;
180181
181 let value = value.0.try_into().map_err(|_| "value too large")?;182 let value = value.0.try_into().map_err(|_| "value too large")?;
182183
183 Ok(Property { key, value })184 Ok(Property { key, value })
184 })185 })
185 .collect::<Result<Vec<_>>>()?;186 .collect::<Result<Vec<_>>>()?;
186187
187 <Pallet<T>>::set_token_properties(188 <Pallet<T>>::set_token_properties(
831 let key = string::from_utf8(p.key.to_vec())832 let key = string::from_utf8(p.key.to_vec())
832 .map_err(|e| Error::Revert(alloc::format!("{}", e)))?;833 .map_err(|e| Error::Revert(alloc::format!("{}", e)))?;
833 let value = bytes(p.value.to_vec());834 let value = bytes(p.value.to_vec());
834 Ok(pallet_common::eth::Property { key, value })835 Ok(pallet_common::eth::Property::new(key, value))
835 })836 })
836 .collect::<Result<Vec<_>>>()837 .collect::<Result<Vec<_>>>()
837 }838 }
11001101
1101 let properties = properties1102 let properties = properties
1102 .into_iter()1103 .into_iter()
1103 .map(|pallet_common::eth::Property { key, value }| {1104 .map(|property| {
1105 let (key, value) = property.take_key_value();
1104 let key = <Vec<u8>>::from(key)1106 let key = <Vec<u8>>::from(key)
1105 .try_into()1107 .try_into()
1106 .map_err(|_| "key too large")?;1108 .map_err(|_| "key too large")?;
11071109
1108 let value = value.0.try_into().map_err(|_| "value too large")?;1110 let value = value.0.try_into().map_err(|_| "value too large")?;
11091111
1110 Ok(Property { key, value })1112 Ok(Property { key, value })
1111 })1113 })
1112 .collect::<Result<Vec<_>>>()?1114 .collect::<Result<Vec<_>>>()?
1113 .try_into()1115 .try_into()
1114 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;1116 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;
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;
 }