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

difftreelog

Add extrinsic: delete collection property

Daniel Shiposha2022-05-04parent: #aa3d2ae.patch.diff
in: master

10 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
292292
293 CollectionPropertySet(CollectionId, Property),293 CollectionPropertySet(CollectionId, Property),
294
295 CollectionPropertyDeleted(CollectionId, PropertyKey),
294296
295 TokenPropertySet(CollectionId, TokenId, Property),297 TokenPropertySet(CollectionId, TokenId, Property),
296298
761 Ok(())763 Ok(())
762 }764 }
765
766 pub fn delete_collection_property(
767 collection: &CollectionHandle<T>,
768 sender: &T::CrossAccountId,
769 property_key: PropertyKey,
770 ) -> DispatchResult {
771 collection.check_is_owner_or_admin(sender)?;
772
773 CollectionProperties::<T>::mutate(collection.id, |properties| {
774 properties.remove_property(&property_key);
775 });
776
777 Self::deposit_event(Event::CollectionPropertyDeleted(collection.id, property_key));
778
779 Ok(())
780 }
781
782 pub fn delete_collection_properties(
783 collection: &CollectionHandle<T>,
784 sender: &T::CrossAccountId,
785 property_keys: Vec<PropertyKey>,
786 ) -> DispatchResult {
787 for key in property_keys {
788 Self::delete_collection_property(collection, sender, key)?;
789 }
790
791 Ok(())
792 }
763793
764 pub fn set_property_permission(794 pub fn set_property_permission(
765 collection: &CollectionHandle<T>,795 collection: &CollectionHandle<T>,
956 fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;986 fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
957 fn burn_item() -> Weight;987 fn burn_item() -> Weight;
958 fn set_collection_properties(amount: u32) -> Weight;988 fn set_collection_properties(amount: u32) -> Weight;
989 fn delete_collection_properties(amount: u32) -> Weight;
959 fn set_token_properties(amount: u32) -> Weight;990 fn set_token_properties(amount: u32) -> Weight;
960 fn delete_token_properties(amount: u32) -> Weight;991 fn delete_token_properties(amount: u32) -> Weight;
961 fn set_property_permissions(amount: u32) -> Weight;992 fn set_property_permissions(amount: u32) -> Weight;
998 sender: T::CrossAccountId,1029 sender: T::CrossAccountId,
999 properties: Vec<Property>,1030 properties: Vec<Property>,
1000 ) -> DispatchResultWithPostInfo;1031 ) -> DispatchResultWithPostInfo;
1032 fn delete_collection_properties(
1033 &self,
1034 sender: &T::CrossAccountId,
1035 property_keys: Vec<PropertyKey>,
1036 ) -> DispatchResultWithPostInfo;
1001 fn set_token_properties(1037 fn set_token_properties(
1002 &self,1038 &self,
1003 sender: T::CrossAccountId,1039 sender: T::CrossAccountId,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -54,6 +54,10 @@
 		<SelfWeightOf<T>>::set_collection_properties(amount)
 	}
 
+	fn delete_collection_properties(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::delete_collection_properties(amount)
+	}
+
 	fn set_token_properties(amount: u32) -> Weight {
 		<SelfWeightOf<T>>::set_token_properties(amount)
 	}
@@ -249,6 +253,14 @@
 		fail!(<Error<T>>::PropertiesNotAllowed)
 	}
 
+	fn delete_collection_properties(
+		&self,
+		_sender: &T::CrossAccountId,
+		_property_keys: Vec<PropertyKey>,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
 	fn set_token_properties(
 		&self,
 		_sender: T::CrossAccountId,
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
--- 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
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -55,6 +55,10 @@
 		<SelfWeightOf<T>>::set_collection_properties(amount)
 	}
 
+	fn delete_collection_properties(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::delete_collection_properties(amount)
+	}
+
 	fn set_token_properties(amount: u32) -> Weight {
 		<SelfWeightOf<T>>::set_token_properties(amount)
 	}
@@ -171,6 +175,19 @@
 		)
 	}
 
+	fn delete_collection_properties(
+		&self,
+		sender: &T::CrossAccountId,
+		property_keys: Vec<PropertyKey>,
+	) -> DispatchResultWithPostInfo {
+		let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);
+
+		with_weight(
+			<Pallet<T>>::delete_collection_properties(self, &sender, property_keys),
+			weight
+		)
+	}
+
 	fn set_token_properties(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -366,6 +366,14 @@
 		<PalletCommon<T>>::set_collection_properties(collection, sender, properties)
 	}
 
+	pub fn delete_collection_properties(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		property_keys: Vec<PropertyKey>,
+	) -> DispatchResult {
+		<PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
+	}
+
 	pub fn set_property_permissions(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- 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)
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -70,6 +70,10 @@
 		<SelfWeightOf<T>>::set_collection_properties(amount)
 	}
 
+	fn delete_collection_properties(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::delete_collection_properties(amount)
+	}
+
 	fn set_token_properties(amount: u32) -> Weight {
 		<SelfWeightOf<T>>::set_token_properties(amount)
 	}
@@ -268,6 +272,14 @@
 		fail!(<Error<T>>::PropertiesNotAllowed)
 	}
 
+	fn delete_collection_properties(
+		&self,
+		_sender: &T::CrossAccountId,
+		_property_keys: Vec<PropertyKey>,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
 	fn set_token_properties(
 		&self,
 		_sender: T::CrossAccountId,
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
--- 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
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -708,6 +708,20 @@
 			dispatch_call::<T, _>(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<PropertyKey>,
+		) -> DispatchResultWithPostInfo {
+			ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);
+
+			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+			dispatch_call::<T, _>(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::<T, _>(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<PropertyKey>
+			property_keys: Vec<PropertyKey>
 		) -> DispatchResultWithPostInfo {
-			ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
+			ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);
 
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 
-			dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, properties))
+			dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys))
 		}
 
 		#[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -58,6 +58,10 @@
 		dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))
 	}
 
+	fn delete_collection_properties(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))
+	}
+
 	fn set_token_properties(amount: u32) -> Weight {
 		dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
 	}