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

difftreelog

feat add scoped properties adding to pallet common

Daniel Shiposha2022-05-18parent: #96e846e.patch.diff
in: master

1 file changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
64 PropertyKeyPermission,64 PropertyKeyPermission,
65 TokenData,65 TokenData,
66 TrySetProperty,66 TrySetProperty,
67 PropertyScope,
67 // RMRK68 // RMRK
68 RmrkCollectionInfo,69 RmrkCollectionInfo,
69 RmrkInstanceInfo,70 RmrkInstanceInfo,
689690
690 let mut collection_properties = up_data_structs::CollectionProperties::get();691 let mut collection_properties = up_data_structs::CollectionProperties::get();
691 collection_properties692 collection_properties
692 .try_set_from_iter(data.properties.into_iter().map(|p| (p.key, p.value)))693 .try_set_from_iter(data.properties.into_iter())
693 .map_err(<Error<T>>::from)?;694 .map_err(<Error<T>>::from)?;
694695
695 CollectionProperties::<T>::insert(id, collection_properties);696 CollectionProperties::<T>::insert(id, collection_properties);
696697
697 let mut token_props_permissions = PropertiesPermissionMap::new();698 let mut token_props_permissions = PropertiesPermissionMap::new();
698 token_props_permissions699 token_props_permissions
699 .try_set_from_iter(700 .try_set_from_iter(data.token_property_permissions.into_iter())
700 data.token_property_permissions
701 .into_iter()
702 .map(|property| (property.key, property.permission)),
703 )
704 .map_err(<Error<T>>::from)?;701 .map_err(<Error<T>>::from)?;
705702
788 Ok(())785 Ok(())
789 }786 }
787
788 pub fn set_scoped_collection_property(
789 collection: &CollectionHandle<T>,
790 scope: PropertyScope,
791 property: Property,
792 ) -> DispatchResult {
793 CollectionProperties::<T>::try_mutate(collection.id, |properties| {
794 properties.try_scoped_set(scope, property.key, property.value)
795 })
796 .map_err(<Error<T>>::from)?;
797
798 Ok(())
799 }
800
801 #[transactional]
802 pub fn set_scoped_collection_properties(
803 collection: &CollectionHandle<T>,
804 scope: PropertyScope,
805 properties: impl Iterator<Item=Property>,
806 ) -> DispatchResult {
807 CollectionProperties::<T>::try_mutate(collection.id, |stored_properties| {
808 stored_properties.try_scoped_set_from_iter(scope, properties)
809 })
810 .map_err(<Error<T>>::from)?;
811
812 Ok(())
813 }
790814
791 #[transactional]815 #[transactional]
792 pub fn set_collection_properties(816 pub fn set_collection_properties(