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
366 /// Tried to store more data than allowed in collection field366 /// Tried to store more data than allowed in collection field
367 CollectionFieldSizeExceeded,367 CollectionFieldSizeExceeded,
368
369 NoSpaceForProperty,
370
371 PropertyLimitReached,
368 }372 }
369373
370 #[pallet::storage]374 #[pallet::storage]
652 CollectionProperties::<T>::insert(656 CollectionProperties::<T>::insert(
653 id,657 id,
654 Properties::from_collection_props_vec(data.properties)?,658 Properties::from_collection_props_vec(data.properties)
659 .map_err(|e| -> Error::<T> {
660 e.into()
661 })?,
655 );662 );
656663
657 let token_props_permissions: PropertiesPermissionMap = data664 let token_props_permissions: PropertiesPermissionMap = data
660 .map(|property| (property.key, property.permission))667 .map(|property| (property.key, property.permission))
661 .collect::<BTreeMap<_, _>>()668 .collect::<BTreeMap<_, _>>()
662 .try_into()669 .try_into()
663 .map_err(|_| PropertiesError::PropertyLimitReached)?;670 .map_err(|_| -> Error::<T> {
671 PropertiesError::PropertyLimitReached.into()
672 })?;
664673
665 CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);674 CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);
666675
745 CollectionProperties::<T>::try_mutate(collection.id, |properties| {754 CollectionProperties::<T>::try_mutate(collection.id, |properties| {
746 properties.try_set_property(property.clone())755 properties.try_set_property(property.clone())
747 })?;756 })
757 .map_err(|e| -> Error::<T> {
758 e.into()
759 })?;
748760
749 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));761 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));
750762
811 let property_permission = property_permission.clone();823 let property_permission = property_permission.clone();
812 permissions.try_insert(property_permission.key, property_permission.permission)824 permissions.try_insert(property_permission.key, property_permission.permission)
813 })825 })
814 .map_err(|_| PropertiesError::PropertyLimitReached)?;826 .map_err(|_| -> Error::<T> {
827 PropertiesError::PropertyLimitReached.into()
828 })?;
815829
816 Self::deposit_event(Event::PropertyPermissionSet(830 Self::deposit_event(Event::PropertyPermissionSet(
817 collection.id,831 collection.id,
1134 }1148 }
1135}1149}
1150
1151impl<T: Config> From<PropertiesError> for Error<T> {
1152 fn from(error: PropertiesError) -> Self {
1153 match error {
1154 PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,
1155 PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,
1156 }
1157 }
1158}
11361159
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
--- 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 =