git.delta.rocks / unique-network / refs/commits / a7c09a369ee4

difftreelog

Add appropriate errors for properties

Daniel Shiposha2022-05-05parent: #cc9cedd.patch.diff
in: master

3 files changed

modifiedpallets/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,
+		}
+	}
+}
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -265,6 +265,8 @@
 
 		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
 			properties.try_set_property(property.clone())
+		}).map_err(|e| -> CommonError::<T> {
+			e.into()
 		})?;
 
 		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
660 PropertyLimitReached,660 PropertyLimitReached,
661}661}
662
663impl From<PropertiesError> for DispatchError {
664 fn from(error: PropertiesError) -> Self {
665 match error {
666 PropertiesError::NoSpaceForProperty => DispatchError::Other("no space for property"),
667 PropertiesError::PropertyLimitReached => {
668 DispatchError::Other("property key limit reached")
669 }
670 }
671 }
672}
673662
674pub type PropertiesMap =663pub type PropertiesMap =
675 BoundedBTreeMap<PropertyKey, PropertyValue, ConstU32<MAX_PROPERTIES_PER_ITEM>>;664 BoundedBTreeMap<PropertyKey, PropertyValue, ConstU32<MAX_PROPERTIES_PER_ITEM>>;