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
284 fn collection_limits(&self) -> Result<Vec<eth::CollectionLimit>> {284 fn collection_limits(&self) -> Result<Vec<eth::CollectionLimit>> {
285 let limits = &self.collection.limits;285 let limits = &self.collection.limits;
286
287 let convert_value_from_bool = |ob: Option<bool>| match ob {
288 Some(b) => Some(b as u32),
289 None => None,
290 };
286291
287 Ok(vec![292 Ok(vec![
288 eth::CollectionLimit::new(293 eth::CollectionLimit::new(
297 .sponsored_data_rate_limit302 .sponsored_data_rate_limit
298 .and_then(|limit| {303 .and_then(|limit| {
299 if let SponsoringRateLimit::Blocks(blocks) = limit {304 if let SponsoringRateLimit::Blocks(blocks) = limit {
300 Some(eth::CollectionLimit::new::<u32>(305 Some(eth::CollectionLimit::new(
301 eth::CollectionLimitField::SponsoredDataRateLimit,306 eth::CollectionLimitField::SponsoredDataRateLimit,
302 blocks,307 Some(blocks),
303 ))308 ))
304 } else {309 } else {
305 None310 None
306 }311 }
307 })312 })
308 .unwrap_or(eth::CollectionLimit::new::<u32>(313 .unwrap_or(eth::CollectionLimit::new(
309 eth::CollectionLimitField::SponsoredDataRateLimit,314 eth::CollectionLimitField::SponsoredDataRateLimit,
310 Default::default(),315 Default::default(),
311 )),316 )),
320 ),325 ),
321 eth::CollectionLimit::new(326 eth::CollectionLimit::new(
322 eth::CollectionLimitField::OwnerCanTransfer,327 eth::CollectionLimitField::OwnerCanTransfer,
323 limits.owner_can_transfer,328 convert_value_from_bool(limits.owner_can_transfer),
324 ),329 ),
325 eth::CollectionLimit::new(330 eth::CollectionLimit::new(
326 eth::CollectionLimitField::OwnerCanDestroy,331 eth::CollectionLimitField::OwnerCanDestroy,
327 limits.owner_can_destroy,332 convert_value_from_bool(limits.owner_can_destroy),
328 ),333 ),
329 eth::CollectionLimit::new(334 eth::CollectionLimit::new(
330 eth::CollectionLimitField::TransferEnabled,335 eth::CollectionLimitField::TransferEnabled,
331 limits.transfers_enabled,336 convert_value_from_bool(limits.transfers_enabled),
332 ),337 ),
333 ])338 ])
334 }339 }
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
466/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.466/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
467struct CollectionLimit {467struct CollectionLimit {
468 CollectionLimitField field;468 CollectionLimitField field;
469 OptionUint value;469 Option_uint256 value;
470}470}
471471
472/// Ethereum representation of Optional value with uint256.472/// Optional value
473struct OptionUint {473struct Option_uint256 {
474 /// Shows the status of accessibility of value
474 bool status;475 bool status;
476 /// Actual value if `status` is true
475 uint256 value;477 uint256 value;
476}478}
477479
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
608/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.608/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
609struct CollectionLimit {609struct CollectionLimit {
610 CollectionLimitField field;610 CollectionLimitField field;
611 OptionUint value;611 Option_uint256 value;
612}612}
613613
614/// Ethereum representation of Optional value with uint256.614/// Optional value
615struct OptionUint {615struct Option_uint256 {
616 /// Shows the status of accessibility of value
616 bool status;617 bool status;
618 /// Actual value if `status` is true
617 uint256 value;619 uint256 value;
618}620}
619621
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
608/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.608/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
609struct CollectionLimit {609struct CollectionLimit {
610 CollectionLimitField field;610 CollectionLimitField field;
611 OptionUint value;611 Option_uint256 value;
612}612}
613613
614/// Ethereum representation of Optional value with uint256.614/// Optional value
615struct OptionUint {615struct Option_uint256 {
616 /// Shows the status of accessibility of value
616 bool status;617 bool status;
618 /// Actual value if `status` is true
617 uint256 value;619 uint256 value;
618}620}
619621
modifiedtests/src/eth/abi/fungible.jsondiffbeforeafterboth
222 { "internalType": "bool", "name": "status", "type": "bool" },222 { "internalType": "bool", "name": "status", "type": "bool" },
223 { "internalType": "uint256", "name": "value", "type": "uint256" }223 { "internalType": "uint256", "name": "value", "type": "uint256" }
224 ],224 ],
225 "internalType": "struct OptionUint",225 "internalType": "struct Option_uint256",
226 "name": "value",226 "name": "value",
227 "type": "tuple"227 "type": "tuple"
228 }228 }
508 { "internalType": "bool", "name": "status", "type": "bool" },508 { "internalType": "bool", "name": "status", "type": "bool" },
509 { "internalType": "uint256", "name": "value", "type": "uint256" }509 { "internalType": "uint256", "name": "value", "type": "uint256" }
510 ],510 ],
511 "internalType": "struct OptionUint",511 "internalType": "struct Option_uint256",
512 "name": "value",512 "name": "value",
513 "type": "tuple"513 "type": "tuple"
514 }514 }
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
252 { "internalType": "bool", "name": "status", "type": "bool" },252 { "internalType": "bool", "name": "status", "type": "bool" },
253 { "internalType": "uint256", "name": "value", "type": "uint256" }253 { "internalType": "uint256", "name": "value", "type": "uint256" }
254 ],254 ],
255 "internalType": "struct OptionUint",255 "internalType": "struct Option_uint256",
256 "name": "value",256 "name": "value",
257 "type": "tuple"257 "type": "tuple"
258 }258 }
670 { "internalType": "bool", "name": "status", "type": "bool" },670 { "internalType": "bool", "name": "status", "type": "bool" },
671 { "internalType": "uint256", "name": "value", "type": "uint256" }671 { "internalType": "uint256", "name": "value", "type": "uint256" }
672 ],672 ],
673 "internalType": "struct OptionUint",673 "internalType": "struct Option_uint256",
674 "name": "value",674 "name": "value",
675 "type": "tuple"675 "type": "tuple"
676 }676 }
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
234 { "internalType": "bool", "name": "status", "type": "bool" },234 { "internalType": "bool", "name": "status", "type": "bool" },
235 { "internalType": "uint256", "name": "value", "type": "uint256" }235 { "internalType": "uint256", "name": "value", "type": "uint256" }
236 ],236 ],
237 "internalType": "struct OptionUint",237 "internalType": "struct Option_uint256",
238 "name": "value",238 "name": "value",
239 "type": "tuple"239 "type": "tuple"
240 }240 }
652 { "internalType": "bool", "name": "status", "type": "bool" },652 { "internalType": "bool", "name": "status", "type": "bool" },
653 { "internalType": "uint256", "name": "value", "type": "uint256" }653 { "internalType": "uint256", "name": "value", "type": "uint256" }
654 ],654 ],
655 "internalType": "struct OptionUint",655 "internalType": "struct Option_uint256",
656 "name": "value",656 "name": "value",
657 "type": "tuple"657 "type": "tuple"
658 }658 }
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
308/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.308/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
309struct CollectionLimit {309struct CollectionLimit {
310 CollectionLimitField field;310 CollectionLimitField field;
311 OptionUint value;311 Option_uint256 value;
312}312}
313313
314/// Ethereum representation of Optional value with uint256.314/// Optional value
315struct OptionUint {315struct Option_uint256 {
316 /// Shows the status of accessibility of value
316 bool status;317 bool status;
318 /// Actual value if `status` is true
317 uint256 value;319 uint256 value;
318}320}
319321
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
408/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.408/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
409struct CollectionLimit {409struct CollectionLimit {
410 CollectionLimitField field;410 CollectionLimitField field;
411 OptionUint value;411 Option_uint256 value;
412}412}
413413
414/// Ethereum representation of Optional value with uint256.414/// Optional value
415struct OptionUint {415struct Option_uint256 {
416 /// Shows the status of accessibility of value
416 bool status;417 bool status;
418 /// Actual value if `status` is true
417 uint256 value;419 uint256 value;
418}420}
419421
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
408/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.408/// [`CollectionLimits`](up_data_structs::CollectionLimits) field representation for EVM.
409struct CollectionLimit {409struct CollectionLimit {
410 CollectionLimitField field;410 CollectionLimitField field;
411 OptionUint value;411 Option_uint256 value;
412}412}
413413
414/// Ethereum representation of Optional value with uint256.414/// Optional value
415struct OptionUint {415struct Option_uint256 {
416 /// Shows the status of accessibility of value
416 bool status;417 bool status;
418 /// Actual value if `status` is true
417 uint256 value;419 uint256 value;
418}420}
419421