From cc9cedd6dbfefdc7d09854790e9be9f07dc7b326 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Wed, 04 May 2022 13:41:43 +0000 Subject: [PATCH] Add extrinsic: delete collection property --- --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -292,6 +292,8 @@ CollectionPropertySet(CollectionId, Property), + CollectionPropertyDeleted(CollectionId, PropertyKey), + TokenPropertySet(CollectionId, TokenId, Property), TokenPropertyDeleted(CollectionId, TokenId, PropertyKey), @@ -761,6 +763,34 @@ Ok(()) } + pub fn delete_collection_property( + collection: &CollectionHandle, + sender: &T::CrossAccountId, + property_key: PropertyKey, + ) -> DispatchResult { + collection.check_is_owner_or_admin(sender)?; + + CollectionProperties::::mutate(collection.id, |properties| { + properties.remove_property(&property_key); + }); + + Self::deposit_event(Event::CollectionPropertyDeleted(collection.id, property_key)); + + Ok(()) + } + + pub fn delete_collection_properties( + collection: &CollectionHandle, + sender: &T::CrossAccountId, + property_keys: Vec, + ) -> DispatchResult { + for key in property_keys { + Self::delete_collection_property(collection, sender, key)?; + } + + Ok(()) + } + pub fn set_property_permission( collection: &CollectionHandle, sender: &T::CrossAccountId, @@ -956,6 +986,7 @@ fn create_multiple_items_ex(cost: &CreateItemExData) -> Weight; fn burn_item() -> Weight; fn set_collection_properties(amount: u32) -> Weight; + fn delete_collection_properties(amount: u32) -> Weight; fn set_token_properties(amount: u32) -> Weight; fn delete_token_properties(amount: u32) -> Weight; fn set_property_permissions(amount: u32) -> Weight; @@ -998,6 +1029,11 @@ sender: T::CrossAccountId, properties: Vec, ) -> DispatchResultWithPostInfo; + fn delete_collection_properties( + &self, + sender: &T::CrossAccountId, + property_keys: Vec, + ) -> DispatchResultWithPostInfo; fn set_token_properties( &self, sender: T::CrossAccountId, --- a/pallets/fungible/src/common.rs +++ b/pallets/fungible/src/common.rs @@ -54,6 +54,10 @@ >::set_collection_properties(amount) } + fn delete_collection_properties(amount: u32) -> Weight { + >::delete_collection_properties(amount) + } + fn set_token_properties(amount: u32) -> Weight { >::set_token_properties(amount) } @@ -249,6 +253,14 @@ fail!(>::PropertiesNotAllowed) } + fn delete_collection_properties( + &self, + _sender: &T::CrossAccountId, + _property_keys: Vec, + ) -> DispatchResultWithPostInfo { + fail!(>::PropertiesNotAllowed) + } + fn set_token_properties( &self, _sender: T::CrossAccountId, --- a/pallets/fungible/src/weights.rs +++ b/pallets/fungible/src/weights.rs @@ -36,6 +36,7 @@ fn create_multiple_items_ex(b: u32, ) -> Weight; fn burn_item() -> Weight; fn set_collection_properties(amount: u32) -> Weight; + fn delete_collection_properties(amount: u32) -> Weight; fn set_token_properties(amount: u32) -> Weight; fn delete_token_properties(amount: u32) -> Weight; fn set_property_permissions(amount: u32) -> Weight; @@ -79,6 +80,11 @@ 0 } + fn delete_collection_properties(_amount: u32) -> Weight { + // Error + 0 + } + fn set_token_properties(_amount: u32) -> Weight { // Error 0 @@ -157,6 +163,11 @@ 0 } + fn delete_collection_properties(_amount: u32) -> Weight { + // Error + 0 + } + fn set_token_properties(_amount: u32) -> Weight { // Error 0 --- a/pallets/nonfungible/src/common.rs +++ b/pallets/nonfungible/src/common.rs @@ -55,6 +55,10 @@ >::set_collection_properties(amount) } + fn delete_collection_properties(amount: u32) -> Weight { + >::delete_collection_properties(amount) + } + fn set_token_properties(amount: u32) -> Weight { >::set_token_properties(amount) } @@ -171,6 +175,19 @@ ) } + fn delete_collection_properties( + &self, + sender: &T::CrossAccountId, + property_keys: Vec, + ) -> DispatchResultWithPostInfo { + let weight = >::delete_collection_properties(property_keys.len() as u32); + + with_weight( + >::delete_collection_properties(self, &sender, property_keys), + weight + ) + } + fn set_token_properties( &self, sender: T::CrossAccountId, --- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -366,6 +366,14 @@ >::set_collection_properties(collection, sender, properties) } + pub fn delete_collection_properties( + collection: &CollectionHandle, + sender: &T::CrossAccountId, + property_keys: Vec, + ) -> DispatchResult { + >::delete_collection_properties(collection, sender, property_keys) + } + pub fn set_property_permissions( collection: &CollectionHandle, sender: &T::CrossAccountId, --- a/pallets/nonfungible/src/weights.rs +++ b/pallets/nonfungible/src/weights.rs @@ -37,6 +37,7 @@ fn create_multiple_items_ex(b: u32, ) -> Weight; fn burn_item() -> Weight; fn set_collection_properties(amount: u32) -> Weight; + fn delete_collection_properties(amount: u32) -> Weight; fn set_token_properties(amount: u32) -> Weight; fn delete_token_properties(amount: u32) -> Weight; fn set_property_permissions(amount: u32) -> Weight; @@ -100,6 +101,11 @@ (50_000_000 as Weight).saturating_mul(amount as Weight) } + fn delete_collection_properties(amount: u32) -> Weight { + // TODO calculate appropriate weight + (50_000_000 as Weight).saturating_mul(amount as Weight) + } + fn set_token_properties(amount: u32) -> Weight { // TODO calculate appropriate weight (50_000_000 as Weight).saturating_mul(amount as Weight) @@ -210,6 +216,11 @@ (50_000_000 as Weight).saturating_mul(amount as Weight) } + fn delete_collection_properties(amount: u32) -> Weight { + // TODO calculate appropriate weight + (50_000_000 as Weight).saturating_mul(amount as Weight) + } + fn set_token_properties(amount: u32) -> Weight { // TODO calculate appropriate weight (50_000_000 as Weight).saturating_mul(amount as Weight) --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -70,6 +70,10 @@ >::set_collection_properties(amount) } + fn delete_collection_properties(amount: u32) -> Weight { + >::delete_collection_properties(amount) + } + fn set_token_properties(amount: u32) -> Weight { >::set_token_properties(amount) } @@ -268,6 +272,14 @@ fail!(>::PropertiesNotAllowed) } + fn delete_collection_properties( + &self, + _sender: &T::CrossAccountId, + _property_keys: Vec, + ) -> DispatchResultWithPostInfo { + fail!(>::PropertiesNotAllowed) + } + fn set_token_properties( &self, _sender: T::CrossAccountId, --- a/pallets/refungible/src/weights.rs +++ b/pallets/refungible/src/weights.rs @@ -39,6 +39,7 @@ fn burn_item_partial() -> Weight; fn burn_item_fully() -> Weight; fn set_collection_properties(amount: u32) -> Weight; + fn delete_collection_properties(amount: u32) -> Weight; fn set_token_properties(amount: u32) -> Weight; fn delete_token_properties(amount: u32) -> Weight; fn set_property_permissions(amount: u32) -> Weight; @@ -139,6 +140,11 @@ 0 } + fn delete_collection_properties(_amount: u32) -> Weight { + // Error + 0 + } + fn set_token_properties(_amount: u32) -> Weight { // Error 0 @@ -328,6 +334,11 @@ 0 } + fn delete_collection_properties(_amount: u32) -> Weight { + // Error + 0 + } + fn set_token_properties(_amount: u32) -> Weight { // Error 0 --- a/pallets/unique/src/lib.rs +++ b/pallets/unique/src/lib.rs @@ -708,6 +708,20 @@ dispatch_call::(collection_id, |d| d.set_collection_properties(sender, properties)) } + #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)] + #[transactional] + pub fn delete_collection_properties( + origin, + collection_id: CollectionId, + property_keys: Vec, + ) -> DispatchResultWithPostInfo { + ensure!(!property_keys.is_empty(), Error::::EmptyArgument); + + let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); + + dispatch_call::(collection_id, |d| d.delete_collection_properties(&sender, property_keys)) + } + #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)] #[transactional] pub fn set_token_properties( @@ -723,19 +737,19 @@ dispatch_call::(collection_id, |d| d.set_token_properties(sender, token_id, properties)) } - #[weight = T::CommonWeightInfo::delete_token_properties(properties.len() as u32)] + #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)] #[transactional] pub fn delete_token_properties( origin, collection_id: CollectionId, token_id: TokenId, - properties: Vec + property_keys: Vec ) -> DispatchResultWithPostInfo { - ensure!(!properties.is_empty(), Error::::EmptyArgument); + ensure!(!property_keys.is_empty(), Error::::EmptyArgument); let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?); - dispatch_call::(collection_id, |d| d.delete_token_properties(sender, token_id, properties)) + dispatch_call::(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys)) } #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)] --- a/runtime/common/src/weights.rs +++ b/runtime/common/src/weights.rs @@ -58,6 +58,10 @@ dispatch_weight::() + max_weight_of!(set_collection_properties(amount)) } + fn delete_collection_properties(amount: u32) -> Weight { + dispatch_weight::() + max_weight_of!(delete_collection_properties(amount)) + } + fn set_token_properties(amount: u32) -> Weight { dispatch_weight::() + max_weight_of!(set_token_properties(amount)) } -- gitstuff