difftreelog
feat add properties scopes
in: master
3 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -37,7 +37,7 @@
CUSTOM_DATA_LIMIT, CollectionLimits, CreateCollectionData, SponsorshipState, CreateItemExData,
SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField, PhantomType,
Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
- PropertiesError, PropertyKeyPermission, TokenData, TrySet,
+ PropertiesError, PropertyKeyPermission, TokenData, TrySetProperty,
};
pub use pallet::*;
use sp_core::H160;
@@ -346,8 +346,8 @@
/// Tried to store more property keys than allowed
PropertyLimitReached,
- /// Unable to read array of unbounded keys
- UnableToReadUnboundedKeys,
+ /// Property key is too long
+ PropertyKeyIsTooLong,
/// Only ASCII letters, digits, and '_', '-' are allowed
InvalidCharacterInPropertyKey,
@@ -838,7 +838,7 @@
keys.into_iter()
.map(|key| -> Result<PropertyKey, DispatchError> {
key.try_into()
- .map_err(|_| <Error<T>>::UnableToReadUnboundedKeys.into())
+ .map_err(|_| <Error<T>>::PropertyKeyIsTooLong.into())
})
.collect::<Result<Vec<PropertyKey>, DispatchError>>()
}
@@ -1181,6 +1181,7 @@
PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,
PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,
PropertiesError::InvalidCharacterInPropertyKey => Self::InvalidCharacterInPropertyKey,
+ PropertiesError::PropertyKeyIsTooLong => Self::PropertyKeyIsTooLong,
PropertiesError::EmptyPropertyKey => Self::EmptyPropertyKey,
}
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth22use up_data_structs::{22use up_data_structs::{23 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,23 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,24 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,24 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,25 PropertyKey, PropertyKeyPermission, Properties, TrySet,25 PropertyKey, PropertyKeyPermission, Properties, TrySetProperty,26};26};27use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};27use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};28use pallet_common::{28use pallet_common::{primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -649,24 +649,65 @@
NoSpaceForProperty,
PropertyLimitReached,
InvalidCharacterInPropertyKey,
+ PropertyKeyIsTooLong,
EmptyPropertyKey,
}
-pub trait TrySet: Sized {
+#[derive(Clone, Copy)]
+pub enum PropertyScope {
+ None,
+ Rmrk,
+}
+
+impl PropertyScope {
+ fn apply(self, key: PropertyKey) -> Result<PropertyKey, PropertiesError> {
+ let scope_str: &[u8] = match self {
+ Self::None => return Ok(key),
+ Self::Rmrk => b"rmrk",
+ };
+
+ [scope_str, b":", key.as_slice()]
+ .concat()
+ .try_into()
+ .map_err(|_| PropertiesError::PropertyKeyIsTooLong)
+ }
+}
+
+pub trait TrySetProperty: Sized {
type Value;
- fn try_set(&mut self, key: PropertyKey, value: Self::Value) -> Result<(), PropertiesError>;
+ fn try_scoped_set(
+ &mut self,
+ scope: PropertyScope,
+ key: PropertyKey,
+ value: Self::Value
+ ) -> Result<(), PropertiesError>;
- fn try_set_from_iter<I>(&mut self, iter: I) -> Result<(), PropertiesError>
+ fn try_scoped_set_from_iter<I>(
+ &mut self,
+ scope: PropertyScope,
+ iter: I
+ ) -> Result<(), PropertiesError>
where
- I: Iterator<Item = (PropertyKey, Self::Value)>,
+ I: Iterator<Item=(PropertyKey, Self::Value)>
{
for (key, value) in iter {
- self.try_set(key, value)?;
+ self.try_scoped_set(scope, key, value)?;
}
Ok(())
}
+
+ fn try_set(&mut self, key: PropertyKey, value: Self::Value) -> Result<(), PropertiesError> {
+ self.try_scoped_set(PropertyScope::None, key, value)
+ }
+
+ fn try_set_from_iter<I>(&mut self, iter: I) -> Result<(), PropertiesError>
+ where
+ I: Iterator<Item = (PropertyKey, Self::Value)>,
+ {
+ self.try_scoped_set_from_iter(PropertyScope::None, iter)
+ }
}
#[derive(Encode, Decode, TypeInfo, Derivative, Clone, PartialEq, MaxEncodedLen)]
@@ -713,12 +754,18 @@
}
}
-impl<Value> TrySet for PropertiesMap<Value> {
+impl<Value> TrySetProperty for PropertiesMap<Value> {
type Value = Value;
- fn try_set(&mut self, key: PropertyKey, value: Self::Value) -> Result<(), PropertiesError> {
+ fn try_scoped_set(
+ &mut self,
+ scope: PropertyScope,
+ key: PropertyKey,
+ value: Self::Value
+ ) -> Result<(), PropertiesError> {
Self::check_property_key(&key)?;
+ let key = scope.apply(key)?;
self.0
.try_insert(key, value)
.map_err(|_| PropertiesError::PropertyLimitReached)?;
@@ -765,17 +812,22 @@
}
}
-impl TrySet for Properties {
+impl TrySetProperty for Properties {
type Value = PropertyValue;
- fn try_set(&mut self, key: PropertyKey, value: Self::Value) -> Result<(), PropertiesError> {
+ fn try_scoped_set(
+ &mut self,
+ scope: PropertyScope,
+ key: PropertyKey,
+ value: Self::Value
+ ) -> Result<(), PropertiesError> {
let value_len = value.len();
if self.consumed_space as usize + value_len > self.space_limit as usize {
return Err(PropertiesError::NoSpaceForProperty);
}
- self.map.try_set(key, value)?;
+ self.map.try_scoped_set(scope, key, value)?;
self.consumed_space += value_len as u32;