git.delta.rocks / unique-network / refs/commits / 9322aa344eaa

difftreelog

Add properties extrinsics

Daniel Shiposha2022-04-29parent: #b699923.patch.diff
in: master

10 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -736,7 +736,24 @@
 	) -> DispatchResult {
 		collection.check_is_owner_or_admin(sender)?;
 
-		CollectionProperties::<T>::get(collection.id).try_change_property(property)?;
+		CollectionProperties::<T>::try_mutate(
+			collection.id,
+			|properties| properties.try_change_property(property.clone())
+		)?;
+
+		<Pallet<T>>::deposit_event(Event::CollectionPropertySet(collection.id, property));
+
+		Ok(())
+	}
+
+	pub fn change_collection_properties(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		properties: Vec<Property>,
+	) -> DispatchResult {
+		for property in properties {
+			Self::change_collection_property(collection, sender, property)?;
+		}
 
 		Ok(())
 	}
@@ -909,7 +926,8 @@
 	fn create_multiple_items(amount: u32) -> Weight;
 	fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
 	fn burn_item() -> Weight;
-	fn set_property() -> Weight;
+	fn change_collection_properties(amount: u32) -> Weight;
+	fn change_token_properties(amount: u32) -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -945,17 +963,17 @@
 		amount: u128,
 	) -> DispatchResultWithPostInfo;
 
-	fn change_collection_property(
+	fn change_collection_properties(
 		&self,
 		sender: T::CrossAccountId,
-		property: Property,
+		properties: Vec<Property>,
 	) -> DispatchResultWithPostInfo;
 
-	fn change_token_property(
+	fn change_token_properties(
 		&self,
 		sender: T::CrossAccountId,
 		token_id: TokenId,
-		property: Property,
+		property: Vec<Property>,
 	) -> DispatchResultWithPostInfo;
 
 	fn transfer(
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
50 <SelfWeightOf<T>>::burn_item()50 <SelfWeightOf<T>>::burn_item()
51 }51 }
52
53 fn change_collection_properties(amount: u32) -> Weight {
54 <SelfWeightOf<T>>::change_collection_properties(amount)
55 }
5256
53 fn set_property() -> Weight {57 fn change_token_properties(amount: u32) -> Weight {
54 <SelfWeightOf<T>>::set_property()58 <SelfWeightOf<T>>::change_token_properties(amount)
55 }59 }
5660
57 fn transfer() -> Weight {61 fn transfer() -> Weight {
229 )233 )
230 }234 }
231235
232 fn change_collection_property(236 fn change_collection_properties(
233 &self,237 &self,
234 _sender: T::CrossAccountId,238 _sender: T::CrossAccountId,
235 _property: Property,239 _property: Vec<Property>,
236 ) -> DispatchResultWithPostInfo {240 ) -> DispatchResultWithPostInfo {
237 fail!(<Error<T>>::PropertiesNotAllowed)241 fail!(<Error<T>>::PropertiesNotAllowed)
238 }242 }
239243
240 fn change_token_property(244 fn change_token_properties(
241 &self,245 &self,
242 _sender: T::CrossAccountId,246 _sender: T::CrossAccountId,
243 _token_id: TokenId,247 _token_id: TokenId,
244 _property: Property,248 _property: Vec<Property>,
245 ) -> DispatchResultWithPostInfo {249 ) -> DispatchResultWithPostInfo {
246 fail!(<Error<T>>::PropertiesNotAllowed)250 fail!(<Error<T>>::PropertiesNotAllowed)
247 }251 }
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -35,7 +35,8 @@
 	fn create_item() -> Weight;
 	fn create_multiple_items_ex(b: u32, ) -> Weight;
 	fn burn_item() -> Weight;
-	fn set_property() -> Weight;
+	fn change_collection_properties(amount: u32) -> Weight;
+	fn change_token_properties(amount: u32) -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -71,11 +72,16 @@
 			.saturating_add(T::DbWeight::get().writes(2 as Weight))
 	}
 
-	fn set_property() -> Weight {
+	fn change_collection_properties(amount: u32) -> Weight {
 		// Error
 		0
 	}
 
+	fn change_token_properties(amount: u32) -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Fungible Balance (r:2 w:2)
 	fn transfer() -> Weight {
 		(17_713_000 as Weight)
@@ -134,7 +140,12 @@
 			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
 	}
 
-	fn set_property() -> Weight {
+	fn change_collection_properties(amount: u32) -> Weight {
+		// Error
+		0
+	}
+
+	fn change_token_properties(amount: u32) -> Weight {
 		// Error
 		0
 	}
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -50,8 +50,12 @@
 		<SelfWeightOf<T>>::burn_item()
 	}
 
-	fn set_property() -> Weight {
-		<SelfWeightOf<T>>::set_property()
+	fn change_collection_properties(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::change_collection_properties(amount)
+	}
+
+	fn change_token_properties(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::change_token_properties(amount)
 	}
 
 	fn transfer() -> Weight {
@@ -145,6 +149,33 @@
 		)
 	}
 
+	fn change_collection_properties(
+		&self,
+		sender: T::CrossAccountId,
+		properties: Vec<Property>,
+	) -> DispatchResultWithPostInfo {
+		let weight = <CommonWeights<T>>::change_collection_properties(properties.len() as u32);
+
+		with_weight(
+			<Pallet<T>>::change_collection_properties(self, &sender, properties),
+			weight
+		)
+	}
+
+	fn change_token_properties(
+		&self,
+		sender: T::CrossAccountId,
+		token_id: TokenId,
+		properties: Vec<Property>,
+	) -> DispatchResultWithPostInfo {
+		let weight = <CommonWeights<T>>::change_token_properties(properties.len() as u32);
+
+		with_weight(
+			<Pallet<T>>::change_token_properties(self, &sender, token_id, properties),
+			weight
+		)
+	}
+
 	fn burn_item(
 		&self,
 		sender: T::CrossAccountId,
@@ -239,32 +270,6 @@
 		} else {
 			Ok(().into())
 		}
-	}
-
-	fn change_collection_property(
-		&self,
-		sender: T::CrossAccountId,
-		property: Property,
-	) -> DispatchResultWithPostInfo {
-		// let token_id = None;
-		with_weight(
-			// <Pallet<T>>::change_property(self, &sender, token_id, property),
-			Ok(()),
-			<CommonWeights<T>>::set_property(),
-		)
-	}
-
-	fn change_token_property(
-		&self,
-		sender: T::CrossAccountId,
-		token_id: TokenId,
-		property: Property,
-	) -> DispatchResultWithPostInfo {
-		with_weight(
-			// <Pallet<T>>::change_property(self, &sender, Some(token_id), property),
-			Ok(()),
-			<CommonWeights<T>>::set_property(),
-		)
 	}
 
 	fn set_variable_metadata(
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -265,12 +265,11 @@
 			.map(|p| p.clone())
 			.unwrap_or(PropertyPermission::None);
 
-		let check_token_owner = || -> DispatchResult {
-			let token_data = <TokenData<T>>::get((collection.id, token_id))
-				.ok_or(<CommonError<T>>::TokenNotFound)?;
+		let token_data = <TokenData<T>>::get((collection.id, token_id))
+			.ok_or(<CommonError<T>>::TokenNotFound)?;
 
+		let check_token_owner = || -> DispatchResult {
 			ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);
-
 			Ok(())
 		};
 
@@ -304,6 +303,27 @@
 		Ok(())
 	}
 
+	pub fn change_token_properties(
+		collection: &NonfungibleHandle<T>,
+		sender: &T::CrossAccountId,
+		token_id: TokenId,
+		properties: Vec<Property>,
+	) -> DispatchResult {
+		for property in properties {
+			Self::change_token_property(collection, sender, token_id, property)?;
+		}
+
+		Ok(())
+	}
+
+	pub fn change_collection_properties(
+		collection: &NonfungibleHandle<T>,
+		sender: &T::CrossAccountId,
+		properties: Vec<Property>,
+	) -> DispatchResult {
+		<PalletCommon<T>>::change_collection_properties(collection, sender, properties)
+	}
+
 	pub fn transfer(
 		collection: &NonfungibleHandle<T>,
 		from: &T::CrossAccountId,
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -36,7 +36,8 @@
 	fn create_multiple_items(b: u32, ) -> Weight;
 	fn create_multiple_items_ex(b: u32, ) -> Weight;
 	fn burn_item() -> Weight;
-	fn set_property() -> Weight;
+	fn change_collection_properties(amount: u32) -> Weight;
+	fn change_token_properties(amount: u32) -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -92,11 +93,16 @@
 			.saturating_add(T::DbWeight::get().writes(4 as Weight))
 	}
 
-	fn set_property() -> Weight {
+	fn change_collection_properties(amount: u32) -> Weight {
 		// TODO calculate appropriate weight
-		50_000_000 as Weight
+		(50_000_000 as Weight).saturating_mul(amount as Weight)
 	}
 
+	fn change_token_properties(amount: u32) -> Weight {
+		// TODO calculate appropriate weight
+		(50_000_000 as Weight).saturating_mul(amount as Weight)
+	}
+
 	// Storage: Nonfungible TokenData (r:1 w:1)
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Allowance (r:1 w:0)
@@ -187,9 +193,14 @@
 			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
 	}
 
-	fn set_property() -> Weight {
+	fn change_collection_properties(amount: u32) -> Weight {
+		// TODO calculate appropriate weight
+		(50_000_000 as Weight).saturating_mul(amount as Weight)
+	}
+
+	fn change_token_properties(amount: u32) -> Weight {
 		// TODO calculate appropriate weight
-		50_000_000 as Weight
+		(50_000_000 as Weight).saturating_mul(amount as Weight)
 	}
 
 	// Storage: Nonfungible TokenData (r:1 w:1)
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -66,8 +66,12 @@
 		max_weight_of!(burn_item_partial(), burn_item_fully())
 	}
 
-	fn set_property() -> Weight {
-		<SelfWeightOf<T>>::set_property()
+	fn change_collection_properties(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::change_collection_properties(amount)
+	}
+
+	fn change_token_properties(amount: u32) -> Weight {
+		<SelfWeightOf<T>>::change_token_properties(amount)
 	}
 
 	fn transfer() -> Weight {
@@ -248,19 +252,19 @@
 		)
 	}
 
-	fn change_collection_property(
+	fn change_collection_properties(
 		&self,
 		_sender: T::CrossAccountId,
-		_property: Property,
+		_property: Vec<Property>,
 	) -> DispatchResultWithPostInfo {
 		fail!(<Error<T>>::PropertiesNotAllowed)
 	}
 
-	fn change_token_property(
+	fn change_token_properties(
 		&self,
 		_sender: T::CrossAccountId,
 		_token_id: TokenId,
-		_property: Property,
+		_property: Vec<Property>,
 	) -> DispatchResultWithPostInfo {
 		fail!(<Error<T>>::PropertiesNotAllowed)
 	}
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -38,7 +38,8 @@
 	fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
 	fn burn_item_partial() -> Weight;
 	fn burn_item_fully() -> Weight;
-	fn set_property() -> Weight;
+	fn change_collection_properties(amount: u32) -> Weight;
+	fn change_token_properties(amount: u32) -> Weight;
 	fn transfer_normal() -> Weight;
 	fn transfer_creating() -> Weight;
 	fn transfer_removing() -> Weight;
@@ -131,11 +132,16 @@
 			.saturating_add(T::DbWeight::get().writes(6 as Weight))
 	}
 
-	fn set_property() -> Weight {
+	fn change_collection_properties(amount: u32) -> Weight {
 		// Error
 		0
 	}
 
+	fn change_token_properties(amount: u32) -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Refungible Balance (r:2 w:2)
 	fn transfer_normal() -> Weight {
 		(19_766_000 as Weight)
@@ -305,7 +311,12 @@
 			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
 	}
 
-	fn set_property() -> Weight {
+	fn change_collection_properties(amount: u32) -> Weight {
+		// Error
+		0
+	}
+
+	fn change_token_properties(amount: u32) -> Weight {
 		// Error
 		0
 	}
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -694,6 +694,35 @@
 			dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))
 		}
 
+		#[weight = T::CommonWeightInfo::change_collection_properties(properties.len() as u32)]
+		#[transactional]
+		pub fn change_collection_properties(
+			origin,
+			collection_id: CollectionId,
+			properties: Vec<Property>
+		) -> DispatchResultWithPostInfo {
+			ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
+
+			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+			dispatch_call::<T, _>(collection_id, |d| d.change_collection_properties(sender, properties))
+		}
+
+		#[weight = T::CommonWeightInfo::change_token_properties(properties.len() as u32)]
+		#[transactional]
+		pub fn change_token_properties(
+			origin,
+			collection_id: CollectionId,
+			token_id: TokenId,
+			properties: Vec<Property>
+		) -> DispatchResultWithPostInfo {
+			ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);
+
+			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+
+			dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))
+		}
+
 		#[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]
 		#[transactional]
 		pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -54,8 +54,12 @@
 		dispatch_weight::<T>() + max_weight_of!(burn_item())
 	}
 
-	fn set_property() -> Weight {
-		dispatch_weight::<T>() + max_weight_of!(set_property())
+	fn change_collection_properties(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(change_collection_properties(amount))
+	}
+
+	fn change_token_properties(amount: u32) -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))
 	}
 
 	fn transfer() -> Weight {