difftreelog
Add appropriate errors for properties
in: master
3 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -365,6 +365,10 @@
/// Tried to store more data than allowed in collection field
CollectionFieldSizeExceeded,
+
+ NoSpaceForProperty,
+
+ PropertyLimitReached,
}
#[pallet::storage]
@@ -651,7 +655,10 @@
CollectionProperties::<T>::insert(
id,
- Properties::from_collection_props_vec(data.properties)?,
+ Properties::from_collection_props_vec(data.properties)
+ .map_err(|e| -> Error::<T> {
+ e.into()
+ })?,
);
let token_props_permissions: PropertiesPermissionMap = data
@@ -660,7 +667,9 @@
.map(|property| (property.key, property.permission))
.collect::<BTreeMap<_, _>>()
.try_into()
- .map_err(|_| PropertiesError::PropertyLimitReached)?;
+ .map_err(|_| -> Error::<T> {
+ PropertiesError::PropertyLimitReached.into()
+ })?;
CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);
@@ -744,6 +753,9 @@
CollectionProperties::<T>::try_mutate(collection.id, |properties| {
properties.try_set_property(property.clone())
+ })
+ .map_err(|e| -> Error::<T> {
+ e.into()
})?;
Self::deposit_event(Event::CollectionPropertySet(collection.id, property));
@@ -811,7 +823,9 @@
let property_permission = property_permission.clone();
permissions.try_insert(property_permission.key, property_permission.permission)
})
- .map_err(|_| PropertiesError::PropertyLimitReached)?;
+ .map_err(|_| -> Error::<T> {
+ PropertiesError::PropertyLimitReached.into()
+ })?;
Self::deposit_event(Event::PropertyPermissionSet(
collection.id,
@@ -1133,3 +1147,12 @@
Err(error) => Err(DispatchErrorWithPostInfo { post_info, error }),
}
}
+
+impl<T: Config> From<PropertiesError> for Error<T> {
+ fn from(error: PropertiesError) -> Self {
+ match error {
+ PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,
+ PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,
+ }
+ }
+}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth265265266 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {266 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {267 properties.try_set_property(property.clone())267 properties.try_set_property(property.clone())268 })?;268 }).map_err(|e| -> CommonError::<T> {269 e.into()270 })?;269271270 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(272 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(271 collection.id,273 collection.id,primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -660,17 +660,6 @@
PropertyLimitReached,
}
-impl From<PropertiesError> for DispatchError {
- fn from(error: PropertiesError) -> Self {
- match error {
- PropertiesError::NoSpaceForProperty => DispatchError::Other("no space for property"),
- PropertiesError::PropertyLimitReached => {
- DispatchError::Other("property key limit reached")
- }
- }
- }
-}
-
pub type PropertiesMap =
BoundedBTreeMap<PropertyKey, PropertyValue, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
pub type PropertiesPermissionMap =