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
3434
35use crate::{35use crate::{
36 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,36 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf, eth, weights::WeightInfo,
37 eth::{CollectionLimitField as EvmCollectionLimits, self},
38 weights::WeightInfo,
39};37};
4038
125123
126 let properties = properties124 let properties = properties
127 .into_iter()125 .into_iter()
128 .map(|eth::Property { key, value }| {126 .map(|property| {
127 let (key, value) = property.take_key_value();
129 let key = <Vec<u8>>::from(key)128 let key = <Vec<u8>>::from(key)
130 .try_into()129 .try_into()
131 .map_err(|_| "key too large")?;130 .map_err(|_| "key too large")?;
132131
133 let value = value.0.try_into().map_err(|_| "value too large")?;132 let value = value.0.try_into().map_err(|_| "value too large")?;
134133
135 Ok(Property { key, value })134 Ok(Property { key, value })
136 })135 })
137 .collect::<Result<Vec<_>>>()?;136 .collect::<Result<Vec<_>>>()?;
138137
139 <Pallet<T>>::set_collection_properties(self, &caller, properties)138 <Pallet<T>>::set_collection_properties(self, &caller, properties)
215 let key =214 let key =
216 string::from_utf8(p.key.into()).map_err(|e| Error::Revert(format!("{}", e)))?;215 string::from_utf8(p.key.into()).map_err(|e| Error::Revert(format!("{}", e)))?;
217 let value = bytes(p.value.to_vec());216 let value = bytes(p.value.to_vec());
218 Ok(eth::Property { key, value })217 Ok(eth::Property::new(key, value))
219 })218 })
220 .collect::<Result<Vec<_>>>()?;219 .collect::<Result<Vec<_>>>()?;
221 Ok(properties)220 Ok(properties)
302301
303 Ok(vec![302 Ok(vec![
304 eth::CollectionLimit::from_opt_int(303 eth::CollectionLimit::from_opt_int(
305 EvmCollectionLimits::AccountTokenOwnership,304 eth::CollectionLimitField::AccountTokenOwnership,
306 limits.account_token_ownership_limit,305 limits.account_token_ownership_limit,
307 ),306 ),
308 eth::CollectionLimit::from_opt_int(307 eth::CollectionLimit::from_opt_int(
309 EvmCollectionLimits::SponsoredDataSize,308 eth::CollectionLimitField::SponsoredDataSize,
310 limits.sponsored_data_size,309 limits.sponsored_data_size,
311 ),310 ),
312 limits311 limits
313 .sponsored_data_rate_limit312 .sponsored_data_rate_limit
314 .and_then(|limit| {313 .and_then(|limit| {
315 if let SponsoringRateLimit::Blocks(blocks) = limit {314 if let SponsoringRateLimit::Blocks(blocks) = limit {
316 Some(eth::CollectionLimit::from_int(315 Some(eth::CollectionLimit::from_int(
317 EvmCollectionLimits::SponsoredDataRateLimit,316 eth::CollectionLimitField::SponsoredDataRateLimit,
318 blocks,317 blocks,
319 ))318 ))
320 } else {319 } else {
321 None320 None
322 }321 }
323 })322 })
324 .unwrap_or(eth::CollectionLimit::from_int(323 .unwrap_or(eth::CollectionLimit::from_int(
325 EvmCollectionLimits::SponsoredDataRateLimit,324 eth::CollectionLimitField::SponsoredDataRateLimit,
326 Default::default(),325 Default::default(),
327 )),326 )),
328 eth::CollectionLimit::from_opt_int(EvmCollectionLimits::TokenLimit, limits.token_limit),327 eth::CollectionLimit::from_opt_int(
328 eth::CollectionLimitField::TokenLimit,
329 limits.token_limit,
330 ),
329 eth::CollectionLimit::from_opt_int(331 eth::CollectionLimit::from_opt_int(
330 EvmCollectionLimits::SponsorTransferTimeout,332 eth::CollectionLimitField::SponsorTransferTimeout,
331 limits.sponsor_transfer_timeout,333 limits.sponsor_transfer_timeout,
332 ),334 ),
333 eth::CollectionLimit::from_opt_int(335 eth::CollectionLimit::from_opt_int(
334 EvmCollectionLimits::SponsorApproveTimeout,336 eth::CollectionLimitField::SponsorApproveTimeout,
335 limits.sponsor_approve_timeout,337 limits.sponsor_approve_timeout,
336 ),338 ),
337 eth::CollectionLimit::from_opt_bool(339 eth::CollectionLimit::from_opt_bool(
338 EvmCollectionLimits::OwnerCanTransfer,340 eth::CollectionLimitField::OwnerCanTransfer,
339 limits.owner_can_transfer,341 limits.owner_can_transfer,
340 ),342 ),
341 eth::CollectionLimit::from_opt_bool(343 eth::CollectionLimit::from_opt_bool(
342 EvmCollectionLimits::OwnerCanDestroy,344 eth::CollectionLimitField::OwnerCanDestroy,
343 limits.owner_can_destroy,345 limits.owner_can_destroy,
344 ),346 ),
345 eth::CollectionLimit::from_opt_bool(347 eth::CollectionLimit::from_opt_bool(
346 EvmCollectionLimits::TransferEnabled,348 eth::CollectionLimitField::TransferEnabled,
347 limits.transfers_enabled,349 limits.transfers_enabled,
348 ),350 ),
349 ])351 ])
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
--- 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;
 }