difftreelog
refactor eth::Property
in: master
13 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -33,9 +33,7 @@
use alloc::format;
use crate::{
- Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
- eth::{CollectionLimitField as EvmCollectionLimits, self},
- weights::WeightInfo,
+ Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf, eth, weights::WeightInfo,
};
/// Events for ethereum collection helper.
@@ -125,7 +123,8 @@
let properties = properties
.into_iter()
- .map(|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")?;
@@ -215,7 +214,7 @@
let key =
string::from_utf8(p.key.into()).map_err(|e| Error::Revert(format!("{}", e)))?;
let value = bytes(p.value.to_vec());
- Ok(eth::Property { key, value })
+ Ok(eth::Property::new(key, value))
})
.collect::<Result<Vec<_>>>()?;
Ok(properties)
@@ -302,11 +301,11 @@
Ok(vec![
eth::CollectionLimit::from_opt_int(
- EvmCollectionLimits::AccountTokenOwnership,
+ eth::CollectionLimitField::AccountTokenOwnership,
limits.account_token_ownership_limit,
),
eth::CollectionLimit::from_opt_int(
- EvmCollectionLimits::SponsoredDataSize,
+ eth::CollectionLimitField::SponsoredDataSize,
limits.sponsored_data_size,
),
limits
@@ -314,7 +313,7 @@
.and_then(|limit| {
if let SponsoringRateLimit::Blocks(blocks) = limit {
Some(eth::CollectionLimit::from_int(
- EvmCollectionLimits::SponsoredDataRateLimit,
+ eth::CollectionLimitField::SponsoredDataRateLimit,
blocks,
))
} else {
@@ -322,28 +321,31 @@
}
})
.unwrap_or(eth::CollectionLimit::from_int(
- EvmCollectionLimits::SponsoredDataRateLimit,
+ eth::CollectionLimitField::SponsoredDataRateLimit,
Default::default(),
)),
- eth::CollectionLimit::from_opt_int(EvmCollectionLimits::TokenLimit, limits.token_limit),
eth::CollectionLimit::from_opt_int(
- EvmCollectionLimits::SponsorTransferTimeout,
+ eth::CollectionLimitField::TokenLimit,
+ limits.token_limit,
+ ),
+ eth::CollectionLimit::from_opt_int(
+ eth::CollectionLimitField::SponsorTransferTimeout,
limits.sponsor_transfer_timeout,
),
eth::CollectionLimit::from_opt_int(
- EvmCollectionLimits::SponsorApproveTimeout,
+ eth::CollectionLimitField::SponsorApproveTimeout,
limits.sponsor_approve_timeout,
),
eth::CollectionLimit::from_opt_bool(
- EvmCollectionLimits::OwnerCanTransfer,
+ eth::CollectionLimitField::OwnerCanTransfer,
limits.owner_can_transfer,
),
eth::CollectionLimit::from_opt_bool(
- EvmCollectionLimits::OwnerCanDestroy,
+ eth::CollectionLimitField::OwnerCanDestroy,
limits.owner_can_destroy,
),
eth::CollectionLimit::from_opt_bool(
- EvmCollectionLimits::TransferEnabled,
+ eth::CollectionLimitField::TransferEnabled,
limits.transfers_enabled,
),
])
pallets/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.
pallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/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;
}
pallets/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")?;
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/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;
}
pallets/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")?;
pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/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;
}
tests/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;
}
tests/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;
}
tests/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;
}