difftreelog
Add appropriate errors for properties
in: master
3 files changed
pallets/common/src/lib.rsdiffbeforeafterboth366 /// Tried to store more data than allowed in collection field366 /// Tried to store more data than allowed in collection field367 CollectionFieldSizeExceeded,367 CollectionFieldSizeExceeded,368369 NoSpaceForProperty,370371 PropertyLimitReached,368 }372 }369373370 #[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 );656663657 let token_props_permissions: PropertiesPermissionMap = data664 let token_props_permissions: PropertiesPermissionMap = data660 .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 })?;664673665 CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);674 CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);666675745 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 })?;748760749 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));761 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));750762811 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 })?;815829816 Self::deposit_event(Event::PropertyPermissionSet(830 Self::deposit_event(Event::PropertyPermissionSet(817 collection.id,831 collection.id,1134 }1148 }1135}1149}11501151impl<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}11361159pallets/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.rsdiffbeforeafterboth660 PropertyLimitReached,660 PropertyLimitReached,661}661}662663impl 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}673662674pub type PropertiesMap =663pub type PropertiesMap =675 BoundedBTreeMap<PropertyKey, PropertyValue, ConstU32<MAX_PROPERTIES_PER_ITEM>>;664 BoundedBTreeMap<PropertyKey, PropertyValue, ConstU32<MAX_PROPERTIES_PER_ITEM>>;