git.delta.rocks / unique-network / refs/commits / 72d79654f12f

difftreelog

misk: Change custom OptionUint to Option<uint256>

Trubnikov Sergey2023-01-10parent: #b841d63.patch.diff
in: master

14 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -284,6 +284,11 @@
 	fn collection_limits(&self) -> Result<Vec<eth::CollectionLimit>> {
 		let limits = &self.collection.limits;
 
+		let convert_value_from_bool = |ob: Option<bool>| match ob {
+			Some(b) => Some(b as u32),
+			None => None,
+		};
+
 		Ok(vec![
 			eth::CollectionLimit::new(
 				eth::CollectionLimitField::AccountTokenOwnership,
@@ -297,15 +302,15 @@
 				.sponsored_data_rate_limit
 				.and_then(|limit| {
 					if let SponsoringRateLimit::Blocks(blocks) = limit {
-						Some(eth::CollectionLimit::new::<u32>(
+						Some(eth::CollectionLimit::new(
 							eth::CollectionLimitField::SponsoredDataRateLimit,
-							blocks,
+							Some(blocks),
 						))
 					} else {
 						None
 					}
 				})
-				.unwrap_or(eth::CollectionLimit::new::<u32>(
+				.unwrap_or(eth::CollectionLimit::new(
 					eth::CollectionLimitField::SponsoredDataRateLimit,
 					Default::default(),
 				)),
@@ -320,15 +325,15 @@
 			),
 			eth::CollectionLimit::new(
 				eth::CollectionLimitField::OwnerCanTransfer,
-				limits.owner_can_transfer,
+				convert_value_from_bool(limits.owner_can_transfer),
 			),
 			eth::CollectionLimit::new(
 				eth::CollectionLimitField::OwnerCanDestroy,
-				limits.owner_can_destroy,
+				convert_value_from_bool(limits.owner_can_destroy),
 			),
 			eth::CollectionLimit::new(
 				eth::CollectionLimitField::TransferEnabled,
-				limits.transfers_enabled,
+				convert_value_from_bool(limits.transfers_enabled),
 			),
 		])
 	}
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
66 T::CrossAccountId::from_sub(account_id)66 T::CrossAccountId::from_sub(account_id)
67}67}
68
69/// Ethereum representation of Optional value with uint256.
70#[derive(Debug, Default, AbiCoder)]
71pub struct OptionUint {
72 status: bool,
73 value: uint256,
74}
75
76impl From<u32> for OptionUint {
77 fn from(value: u32) -> Self {
78 Self {
79 status: true,
80 value: uint256::from(value),
81 }
82 }
83}
84
85impl From<Option<u32>> for OptionUint {
86 fn from(value: Option<u32>) -> Self {
87 match value {
88 Some(value) => Self {
89 status: true,
90 value: value.into(),
91 },
92 None => Self {
93 status: false,
94 value: Default::default(),
95 },
96 }
97 }
98}
99
100impl From<bool> for OptionUint {
101 fn from(value: bool) -> Self {
102 Self {
103 status: true,
104 value: if value {
105 uint256::from(1)
106 } else {
107 Default::default()
108 },
109 }
110 }
111}
112
113impl From<Option<bool>> for OptionUint {
114 fn from(value: Option<bool>) -> Self {
115 match value {
116 Some(value) => Self::from(value),
117 None => Self {
118 status: false,
119 value: Default::default(),
120 },
121 }
122 }
123}
12468
125/// Ethereum representation of Optional value with CrossAddress.69/// Ethereum representation of Optional value with CrossAddress.
126#[derive(Debug, Default, AbiCoder)]70#[derive(Debug, Default, AbiCoder)]
252#[derive(Debug, Default, AbiCoder)]196#[derive(Debug, Default, AbiCoder)]
253pub struct CollectionLimit {197pub struct CollectionLimit {
254 field: CollectionLimitField,198 field: CollectionLimitField,
255 value: OptionUint,199 value: Option<uint256>,
256}200}
257201
258impl CollectionLimit {202impl CollectionLimit {
259 /// Create [`CollectionLimit`] from field and value.203 /// Create [`CollectionLimit`] from field and value.
260 pub fn new<T>(field: CollectionLimitField, value: T) -> Self204 pub fn new(field: CollectionLimitField, value: Option<u32>) -> Self {
261 where
262 OptionUint: From<T>,
263 {
264 Self {205 Self {
265 field,206 field,
266 value: value.into(),207 value: match value {
208 Some(value) => Some(value.into()),
209 None => None,
210 },
267 }211 }
268 }212 }
269 /// Whether the field contains a value.213 /// Whether the field contains a value.
270 pub fn has_value(&self) -> bool {214 pub fn has_value(&self) -> bool {
271 self.value.status215 self.value.is_some()
272 }216 }
273}217}
274218
275impl TryInto<up_data_structs::CollectionLimits> for CollectionLimit {219impl TryInto<up_data_structs::CollectionLimits> for CollectionLimit {
276 type Error = evm_coder::execution::Error;220 type Error = evm_coder::execution::Error;
277221
278 fn try_into(self) -> Result<up_data_structs::CollectionLimits, Self::Error> {222 fn try_into(self) -> Result<up_data_structs::CollectionLimits, Self::Error> {
279 let value = self.value.value.try_into().map_err(|error| {223 let value = self
224 .value
225 .ok_or::<Self::Error>("can't convert `None` value to boolean".into())?;
226 let value = Some(value.try_into().map_err(|error| {
280 Self::Error::Revert(format!(227 Self::Error::Revert(format!(
281 "can't convert value to u32 \"{}\" because: \"{error}\"",228 "can't convert value to u32 \"{}\" because: \"{error}\"",
282 self.value.value229 value
283 ))230 ))
284 })?;231 })?);
285232
286 let convert_value_to_bool = || match value {233 let convert_value_to_bool = || match value {
287 0 => Ok(false),234 Some(value) => match value {
235 0 => Ok(Some(false)),
288 1 => Ok(true),236 1 => Ok(Some(true)),
289 _ => {237 _ => {
290 return Err(Self::Error::Revert(format!(238 return Err(Self::Error::Revert(format!(
291 "can't convert value to boolean \"{value}\""239 "can't convert value to boolean \"{value}\""
292 )))240 )))
293 }241 }
242 },
243 None => Ok(None),
294 };244 };
295245
296 let mut limits = up_data_structs::CollectionLimits::default();246 let mut limits = up_data_structs::CollectionLimits::default();
297 match self.field {247 match self.field {
298 CollectionLimitField::AccountTokenOwnership => {248 CollectionLimitField::AccountTokenOwnership => {
299 limits.account_token_ownership_limit = Some(value);249 limits.account_token_ownership_limit = value;
300 }250 }
301 CollectionLimitField::SponsoredDataSize => {251 CollectionLimitField::SponsoredDataSize => {
302 limits.sponsored_data_size = Some(value);252 limits.sponsored_data_size = value;
303 }253 }
304 CollectionLimitField::SponsoredDataRateLimit => {254 CollectionLimitField::SponsoredDataRateLimit => {
305 limits.sponsored_data_rate_limit =255 limits.sponsored_data_rate_limit = match value {
306 Some(up_data_structs::SponsoringRateLimit::Blocks(value));256 Some(value) => Some(up_data_structs::SponsoringRateLimit::Blocks(value)),
257 None => None,
258 };
307 }259 }
308 CollectionLimitField::TokenLimit => {260 CollectionLimitField::TokenLimit => {
309 limits.token_limit = Some(value);261 limits.token_limit = value;
310 }262 }
311 CollectionLimitField::SponsorTransferTimeout => {263 CollectionLimitField::SponsorTransferTimeout => {
312 limits.sponsor_transfer_timeout = Some(value);264 limits.sponsor_transfer_timeout = value;
313 }265 }
314 CollectionLimitField::SponsorApproveTimeout => {266 CollectionLimitField::SponsorApproveTimeout => {
315 limits.sponsor_approve_timeout = Some(value);267 limits.sponsor_approve_timeout = value;
316 }268 }
317 CollectionLimitField::OwnerCanTransfer => {269 CollectionLimitField::OwnerCanTransfer => {
318 limits.owner_can_transfer = Some(convert_value_to_bool()?);270 limits.owner_can_transfer = convert_value_to_bool()?;
319 }271 }
320 CollectionLimitField::OwnerCanDestroy => {272 CollectionLimitField::OwnerCanDestroy => {
321 limits.owner_can_destroy = Some(convert_value_to_bool()?);273 limits.owner_can_destroy = convert_value_to_bool()?;
322 }274 }
323 CollectionLimitField::TransferEnabled => {275 CollectionLimitField::TransferEnabled => {
324 limits.transfers_enabled = Some(convert_value_to_bool()?);276 limits.transfers_enabled = convert_value_to_bool()?;
325 }277 }
326 };278 };
327 Ok(limits)279 Ok(limits)
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
@@ -466,12 +466,14 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	OptionUint value;
+	Option_uint256 value;
 }
 
-/// Ethereum representation of Optional value with uint256.
-struct OptionUint {
+/// Optional value
+struct Option_uint256 {
+	/// Shows the status of accessibility of value
 	bool status;
+	/// Actual value if `status` is true
 	uint256 value;
 }
 
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
@@ -608,12 +608,14 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	OptionUint value;
+	Option_uint256 value;
 }
 
-/// Ethereum representation of Optional value with uint256.
-struct OptionUint {
+/// Optional value
+struct Option_uint256 {
+	/// Shows the status of accessibility of value
 	bool status;
+	/// Actual value if `status` is true
 	uint256 value;
 }
 
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
@@ -608,12 +608,14 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	OptionUint value;
+	Option_uint256 value;
 }
 
-/// Ethereum representation of Optional value with uint256.
-struct OptionUint {
+/// Optional value
+struct Option_uint256 {
+	/// Shows the status of accessibility of value
 	bool status;
+	/// Actual value if `status` is true
 	uint256 value;
 }
 
modifiedtests/src/eth/abi/fungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/fungible.json
+++ b/tests/src/eth/abi/fungible.json
@@ -222,7 +222,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct OptionUint",
+            "internalType": "struct Option_uint256",
             "name": "value",
             "type": "tuple"
           }
@@ -508,7 +508,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct OptionUint",
+            "internalType": "struct Option_uint256",
             "name": "value",
             "type": "tuple"
           }
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -252,7 +252,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct OptionUint",
+            "internalType": "struct Option_uint256",
             "name": "value",
             "type": "tuple"
           }
@@ -670,7 +670,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct OptionUint",
+            "internalType": "struct Option_uint256",
             "name": "value",
             "type": "tuple"
           }
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -234,7 +234,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct OptionUint",
+            "internalType": "struct Option_uint256",
             "name": "value",
             "type": "tuple"
           }
@@ -652,7 +652,7 @@
               { "internalType": "bool", "name": "status", "type": "bool" },
               { "internalType": "uint256", "name": "value", "type": "uint256" }
             ],
-            "internalType": "struct OptionUint",
+            "internalType": "struct Option_uint256",
             "name": "value",
             "type": "tuple"
           }
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -308,12 +308,14 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	OptionUint value;
+	Option_uint256 value;
 }
 
-/// Ethereum representation of Optional value with uint256.
-struct OptionUint {
+/// Optional value
+struct Option_uint256 {
+	/// Shows the status of accessibility of value
 	bool status;
+	/// Actual value if `status` is true
 	uint256 value;
 }
 
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -408,12 +408,14 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	OptionUint value;
+	Option_uint256 value;
 }
 
-/// Ethereum representation of Optional value with uint256.
-struct OptionUint {
+/// Optional value
+struct Option_uint256 {
+	/// Shows the status of accessibility of value
 	bool status;
+	/// Actual value if `status` is true
 	uint256 value;
 }
 
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -408,12 +408,14 @@
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
 struct CollectionLimit {
 	CollectionLimitField field;
-	OptionUint value;
+	Option_uint256 value;
 }
 
-/// Ethereum representation of Optional value with uint256.
-struct OptionUint {
+/// Optional value
+struct Option_uint256 {
+	/// Shows the status of accessibility of value
 	bool status;
+	/// Actual value if `status` is true
 	uint256 value;
 }