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
171/// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).171/// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
172#[derive(Debug, Default, AbiCoder)]172#[derive(Debug, Default, AbiCoder)]
173pub struct Property {173pub struct Property {
174 /// Property key.
175 pub key: evm_coder::types::string,174 key: evm_coder::types::string,
176 /// Property value.
177 pub value: evm_coder::types::bytes,175 value: evm_coder::types::bytes,
178}176}
177
178impl Property {
179 pub fn new(key: evm_coder::types::string, value: evm_coder::types::bytes) -> Self {
180 Self { key, value }
181 }
182
183 pub fn take_key_value(self) -> (evm_coder::types::string, evm_coder::types::bytes) {
184 (self.key, self.value)
185 }
186}
179187
180/// [`CollectionLimits`](up_data_structs::CollectionLimits) fields representation for EVM.188/// [`CollectionLimits`](up_data_structs::CollectionLimits) fields representation for EVM.
181#[derive(Debug, Default, Clone, Copy, AbiCoder)]189#[derive(Debug, Default, Clone, Copy, AbiCoder)]
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
499499
500/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).500/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
501struct Property {501struct Property {
502 /// @dev Property key.
503 string key;502 string key;
504 /// @dev Property value.
505 bytes value;503 bytes value;
506}504}
507505
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
129129
130/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).130/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
131struct Property {131struct Property {
132 /// @dev Property key.
133 string key;132 string key;
134 /// @dev Property value.
135 bytes value;133 bytes value;
136}134}
137135
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
129129
130/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).130/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
131struct Property {131struct Property {
132 /// @dev Property key.
133 string key;132 string key;
134 /// @dev Property value.
135 bytes value;133 bytes value;
136}134}
137135
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
341341
342/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).342/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
343struct Property {343struct Property {
344 /// @dev Property key.
345 string key;344 string key;
346 /// @dev Property value.
347 bytes value;345 bytes value;
348}346}
349347
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
8282
83/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).83/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
84struct Property {84struct Property {
85 /// @dev Property key.
86 string key;85 string key;
87 /// @dev Property value.
88 bytes value;86 bytes value;
89}87}
9088
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
8282
83/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).83/// @dev Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
84struct Property {84struct Property {
85 /// @dev Property key.
86 string key;85 string key;
87 /// @dev Property value.
88 bytes value;86 bytes value;
89}87}
9088