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
--- 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<T>,
+		sender: &T::CrossAccountId,
+		property_key: PropertyKey,
+	) -> DispatchResult {
+		collection.check_is_owner_or_admin(sender)?;
+
+		CollectionProperties::<T>::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<T>,
+		sender: &T::CrossAccountId,
+		property_keys: Vec<PropertyKey>,
+	) -> DispatchResult {
+		for key in property_keys {
+			Self::delete_collection_property(collection, sender, key)?;
+		}
+
+		Ok(())
+	}
+
 	pub fn set_property_permission(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
@@ -956,6 +986,7 @@
 	fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> 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<Property>,
 	) -> DispatchResultWithPostInfo;
+	fn delete_collection_properties(
+		&self,
+		sender: &T::CrossAccountId,
+		property_keys: Vec<PropertyKey>,
+	) -> DispatchResultWithPostInfo;
 	fn set_token_properties(
 		&self,
 		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
before · pallets/fungible/src/weights.rs
1// Template adopted from https://github.com/paritytech/substrate/blob/master/.maintain/frame-weight-template.hbs23//! Autogenerated weights for pallet_fungible4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-03-01, STEPS: `50`, REPEAT: 200, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 102489// Executed Command:10// target/release/unique-collator11// benchmark12// --pallet13// pallet-fungible14// --wasm-execution15// compiled16// --extrinsic17// *18// --template19// .maintain/frame-weight-template.hbs20// --steps=5021// --repeat=20022// --heap-pages=409623// --output=./pallets/fungible/src/weights.rs2425#![cfg_attr(rustfmt, rustfmt_skip)]26#![allow(unused_parens)]27#![allow(unused_imports)]28#![allow(clippy::unnecessary_cast)]2930use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};31use sp_std::marker::PhantomData;3233/// Weight functions needed for pallet_fungible.34pub trait WeightInfo {35	fn create_item() -> Weight;36	fn create_multiple_items_ex(b: u32, ) -> Weight;37	fn burn_item() -> Weight;38	fn set_collection_properties(amount: u32) -> Weight;39	fn set_token_properties(amount: u32) -> Weight;40	fn delete_token_properties(amount: u32) -> Weight;41	fn set_property_permissions(amount: u32) -> Weight;42	fn transfer() -> Weight;43	fn approve() -> Weight;44	fn transfer_from() -> Weight;45	fn burn_from() -> Weight;46}4748/// Weights for pallet_fungible using the Substrate node and recommended hardware.49pub struct SubstrateWeight<T>(PhantomData<T>);50impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {51	// Storage: Fungible TotalSupply (r:1 w:1)52	// Storage: Fungible Balance (r:1 w:1)53	fn create_item() -> Weight {54		(14_407_000 as Weight)55			.saturating_add(T::DbWeight::get().reads(2 as Weight))56			.saturating_add(T::DbWeight::get().writes(2 as Weight))57	}58	// Storage: Fungible TotalSupply (r:1 w:1)59	// Storage: Fungible Balance (r:4 w:4)60	fn create_multiple_items_ex(b: u32, ) -> Weight {61		(13_030_000 as Weight)62			// Standard Error: 1_00063			.saturating_add((3_779_000 as Weight).saturating_mul(b as Weight))64			.saturating_add(T::DbWeight::get().reads(1 as Weight))65			.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))66			.saturating_add(T::DbWeight::get().writes(1 as Weight))67			.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))68	}69	// Storage: Fungible TotalSupply (r:1 w:1)70	// Storage: Fungible Balance (r:1 w:1)71	fn burn_item() -> Weight {72		(15_565_000 as Weight)73			.saturating_add(T::DbWeight::get().reads(2 as Weight))74			.saturating_add(T::DbWeight::get().writes(2 as Weight))75	}7677	fn set_collection_properties(_amount: u32) -> Weight {78		// Error79		080	}8182	fn set_token_properties(_amount: u32) -> Weight {83		// Error84		085	}8687	fn delete_token_properties(_amount: u32) -> Weight {88		// Error89		090	}9192	fn set_property_permissions(_amount: u32) -> Weight {93		// Error94		095	}9697	// Storage: Fungible Balance (r:2 w:2)98	fn transfer() -> Weight {99		(17_713_000 as Weight)100			.saturating_add(T::DbWeight::get().reads(2 as Weight))101			.saturating_add(T::DbWeight::get().writes(2 as Weight))102	}103	// Storage: Fungible Balance (r:1 w:0)104	// Storage: Fungible Allowance (r:0 w:1)105	fn approve() -> Weight {106		(14_834_000 as Weight)107			.saturating_add(T::DbWeight::get().reads(1 as Weight))108			.saturating_add(T::DbWeight::get().writes(1 as Weight))109	}110	// Storage: Fungible Allowance (r:1 w:1)111	// Storage: Fungible Balance (r:2 w:2)112	fn transfer_from() -> Weight {113		(25_189_000 as Weight)114			.saturating_add(T::DbWeight::get().reads(3 as Weight))115			.saturating_add(T::DbWeight::get().writes(3 as Weight))116	}117	// Storage: Fungible Allowance (r:1 w:1)118	// Storage: Fungible TotalSupply (r:1 w:1)119	// Storage: Fungible Balance (r:1 w:1)120	fn burn_from() -> Weight {121		(24_065_000 as Weight)122			.saturating_add(T::DbWeight::get().reads(3 as Weight))123			.saturating_add(T::DbWeight::get().writes(3 as Weight))124	}125}126127// For backwards compatibility and tests128impl WeightInfo for () {129	// Storage: Fungible TotalSupply (r:1 w:1)130	// Storage: Fungible Balance (r:1 w:1)131	fn create_item() -> Weight {132		(14_407_000 as Weight)133			.saturating_add(RocksDbWeight::get().reads(2 as Weight))134			.saturating_add(RocksDbWeight::get().writes(2 as Weight))135	}136	// Storage: Fungible TotalSupply (r:1 w:1)137	// Storage: Fungible Balance (r:4 w:4)138	fn create_multiple_items_ex(b: u32, ) -> Weight {139		(13_030_000 as Weight)140			// Standard Error: 1_000141			.saturating_add((3_779_000 as Weight).saturating_mul(b as Weight))142			.saturating_add(RocksDbWeight::get().reads(1 as Weight))143			.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))144			.saturating_add(RocksDbWeight::get().writes(1 as Weight))145			.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(b as Weight)))146	}147	// Storage: Fungible TotalSupply (r:1 w:1)148	// Storage: Fungible Balance (r:1 w:1)149	fn burn_item() -> Weight {150		(15_565_000 as Weight)151			.saturating_add(RocksDbWeight::get().reads(2 as Weight))152			.saturating_add(RocksDbWeight::get().writes(2 as Weight))153	}154155	fn set_collection_properties(_amount: u32) -> Weight {156		// Error157		0158	}159160	fn set_token_properties(_amount: u32) -> Weight {161		// Error162		0163	}164165	fn delete_token_properties(_amount: u32) -> Weight {166		// Error167		0168	}169170	fn set_property_permissions(_amount: u32) -> Weight {171		// Error172		0173	}174175	// Storage: Fungible Balance (r:2 w:2)176	fn transfer() -> Weight {177		(17_713_000 as Weight)178			.saturating_add(RocksDbWeight::get().reads(2 as Weight))179			.saturating_add(RocksDbWeight::get().writes(2 as Weight))180	}181	// Storage: Fungible Balance (r:1 w:0)182	// Storage: Fungible Allowance (r:0 w:1)183	fn approve() -> Weight {184		(14_834_000 as Weight)185			.saturating_add(RocksDbWeight::get().reads(1 as Weight))186			.saturating_add(RocksDbWeight::get().writes(1 as Weight))187	}188	// Storage: Fungible Allowance (r:1 w:1)189	// Storage: Fungible Balance (r:2 w:2)190	fn transfer_from() -> Weight {191		(25_189_000 as Weight)192			.saturating_add(RocksDbWeight::get().reads(3 as Weight))193			.saturating_add(RocksDbWeight::get().writes(3 as Weight))194	}195	// Storage: Fungible Allowance (r:1 w:1)196	// Storage: Fungible TotalSupply (r:1 w:1)197	// Storage: Fungible Balance (r:1 w:1)198	fn burn_from() -> Weight {199		(24_065_000 as Weight)200			.saturating_add(RocksDbWeight::get().reads(3 as Weight))201			.saturating_add(RocksDbWeight::get().writes(3 as Weight))202	}203}
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))
 	}