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
265265
266 <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 })?;
269271
270 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(272 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
271 collection.id,273 collection.id,
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>>;