From b057c89fce5175a51b7142adbddb9db4fadda7f0 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Thu, 22 Dec 2022 11:43:27 +0000 Subject: [PATCH] fix: PR --- --- a/pallets/common/src/erc.rs +++ b/pallets/common/src/erc.rs @@ -285,11 +285,11 @@ let limits = &self.collection.limits; Ok(vec![ - eth::CollectionLimit::from_opt_int( + eth::CollectionLimit::new( eth::CollectionLimitField::AccountTokenOwnership, limits.account_token_ownership_limit, ), - eth::CollectionLimit::from_opt_int( + eth::CollectionLimit::new( eth::CollectionLimitField::SponsoredDataSize, limits.sponsored_data_size, ), @@ -297,7 +297,7 @@ .sponsored_data_rate_limit .and_then(|limit| { if let SponsoringRateLimit::Blocks(blocks) = limit { - Some(eth::CollectionLimit::from_int( + Some(eth::CollectionLimit::new::( eth::CollectionLimitField::SponsoredDataRateLimit, blocks, )) @@ -305,31 +305,28 @@ None } }) - .unwrap_or(eth::CollectionLimit::from_int( + .unwrap_or(eth::CollectionLimit::new::( eth::CollectionLimitField::SponsoredDataRateLimit, Default::default(), )), - eth::CollectionLimit::from_opt_int( - eth::CollectionLimitField::TokenLimit, - limits.token_limit, - ), - eth::CollectionLimit::from_opt_int( + eth::CollectionLimit::new(eth::CollectionLimitField::TokenLimit, limits.token_limit), + eth::CollectionLimit::new( eth::CollectionLimitField::SponsorTransferTimeout, limits.sponsor_transfer_timeout, ), - eth::CollectionLimit::from_opt_int( + eth::CollectionLimit::new( eth::CollectionLimitField::SponsorApproveTimeout, limits.sponsor_approve_timeout, ), - eth::CollectionLimit::from_opt_bool( + eth::CollectionLimit::new( eth::CollectionLimitField::OwnerCanTransfer, limits.owner_can_transfer, ), - eth::CollectionLimit::from_opt_bool( + eth::CollectionLimit::new( eth::CollectionLimitField::OwnerCanDestroy, limits.owner_can_destroy, ), - eth::CollectionLimit::from_opt_bool( + eth::CollectionLimit::new( eth::CollectionLimitField::TransferEnabled, limits.transfers_enabled, ), --- a/pallets/common/src/eth.rs +++ b/pallets/common/src/eth.rs @@ -97,17 +97,23 @@ } } +impl From for OptionUint { + fn from(value: bool) -> Self { + Self { + status: true, + value: if value { + uint256::from(1) + } else { + Default::default() + }, + } + } +} + impl From> for OptionUint { fn from(value: Option) -> Self { match value { - Some(value) => Self { - status: true, - value: if value { - uint256::from(1) - } else { - Default::default() - }, - }, + Some(value) => Self::from(value), None => Self { status: false, value: Default::default(), @@ -241,30 +247,16 @@ } impl CollectionLimit { - /// Make [`CollectionLimit`] from [`CollectionLimitField`] and int value. - pub fn from_int(field: CollectionLimitField, value: u32) -> Self { - Self { - field, - value: value.into(), - } - } - - /// Make [`CollectionLimit`] from [`CollectionLimitField`] and optional int value. - pub fn from_opt_int(field: CollectionLimitField, value: Option) -> Self { - Self { - field, - value: value.into(), - } - } - - /// Make [`CollectionLimit`] from [`CollectionLimitField`] and bool value. - pub fn from_opt_bool(field: CollectionLimitField, value: Option) -> Self { + /// Create [`CollectionLimit`] from field and value. + pub fn new(field: CollectionLimitField, value: T) -> Self + where + OptionUint: From, + { Self { field, value: value.into(), } } - /// Whether the field contains a value. pub fn has_value(&self) -> bool { self.value.status -- gitstuff