From d57f26081f53742b885bf64dd74745e38ccde478 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Wed, 18 May 2022 16:19:23 +0000 Subject: [PATCH] feat: add scoped properties adding to pallet common --- --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -64,6 +64,7 @@ PropertyKeyPermission, TokenData, TrySetProperty, + PropertyScope, // RMRK RmrkCollectionInfo, RmrkInstanceInfo, @@ -689,18 +690,14 @@ let mut collection_properties = up_data_structs::CollectionProperties::get(); collection_properties - .try_set_from_iter(data.properties.into_iter().map(|p| (p.key, p.value))) + .try_set_from_iter(data.properties.into_iter()) .map_err(>::from)?; CollectionProperties::::insert(id, collection_properties); let mut token_props_permissions = PropertiesPermissionMap::new(); token_props_permissions - .try_set_from_iter( - data.token_property_permissions - .into_iter() - .map(|property| (property.key, property.permission)), - ) + .try_set_from_iter(data.token_property_permissions.into_iter()) .map_err(>::from)?; CollectionPropertyPermissions::::insert(id, token_props_permissions); @@ -788,6 +785,33 @@ Ok(()) } + pub fn set_scoped_collection_property( + collection: &CollectionHandle, + scope: PropertyScope, + property: Property, + ) -> DispatchResult { + CollectionProperties::::try_mutate(collection.id, |properties| { + properties.try_scoped_set(scope, property.key, property.value) + }) + .map_err(>::from)?; + + Ok(()) + } + + #[transactional] + pub fn set_scoped_collection_properties( + collection: &CollectionHandle, + scope: PropertyScope, + properties: impl Iterator, + ) -> DispatchResult { + CollectionProperties::::try_mutate(collection.id, |stored_properties| { + stored_properties.try_scoped_set_from_iter(scope, properties) + }) + .map_err(>::from)?; + + Ok(()) + } + #[transactional] pub fn set_collection_properties( collection: &CollectionHandle, -- gitstuff