git.delta.rocks / unique-network / refs/commits / 73d9a3eafd0e

difftreelog

CORE-410 Set collection properties for exist collection

Trubnikov Sergey2022-06-28parent: #c4e0a12.patch.diff
in: master

3 files changed

modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -298,46 +298,72 @@
 
 	fn set_collection_properties(
 		&self,
-		_sender: T::CrossAccountId,
-		_property: Vec<Property>,
+		sender: T::CrossAccountId,
+		properties: Vec<Property>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::SettingPropertiesNotAllowed)
+		let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);
+
+		with_weight(
+			<Pallet<T>>::set_collection_properties(self, &sender, properties),
+			weight,
+		)
 	}
 
 	fn delete_collection_properties(
 		&self,
-		_sender: &T::CrossAccountId,
-		_property_keys: Vec<PropertyKey>,
+		sender: &T::CrossAccountId,
+		property_keys: Vec<PropertyKey>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::SettingPropertiesNotAllowed)
+		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,
-		_token_id: TokenId,
-		_property: Vec<Property>,
+		sender: T::CrossAccountId,
+		token_id: TokenId,
+		properties: Vec<Property>,
 		_nesting_budget: &dyn Budget,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::SettingPropertiesNotAllowed)
+		let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);
+
+		with_weight(
+			<Pallet<T>>::set_token_properties(self, &sender, token_id, properties, false),
+			weight,
+		)
 	}
 
 	fn set_token_property_permissions(
 		&self,
-		_sender: &T::CrossAccountId,
-		_property_permissions: Vec<PropertyKeyPermission>,
+		sender: &T::CrossAccountId,
+		property_permissions: Vec<PropertyKeyPermission>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::SettingPropertiesNotAllowed)
+		let weight =
+			<CommonWeights<T>>::set_token_property_permissions(property_permissions.len() as u32);
+
+		with_weight(
+			<Pallet<T>>::set_token_property_permissions(self, sender, property_permissions),
+			weight,
+		)
 	}
 
 	fn delete_token_properties(
 		&self,
-		_sender: T::CrossAccountId,
-		_token_id: TokenId,
-		_property_keys: Vec<PropertyKey>,
+		sender: T::CrossAccountId,
+		token_id: TokenId,
+		property_keys: Vec<PropertyKey>,
 		_nesting_budget: &dyn Budget,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::SettingPropertiesNotAllowed)
+		let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);
+
+		with_weight(
+			<Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),
+			weight,
+		)
 	}
 
 	fn check_nesting(
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
91use up_data_structs::{91use up_data_structs::{
92 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,92 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,
93 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,93 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,
94 Property, PropertyScope, TrySetProperty, PropertyKey, PropertyPermission94 Property, PropertyScope, TrySetProperty, PropertyKey, PropertyPermission, PropertyKeyPermission
95};95};
96use pallet_evm::account::CrossAccountId;96use pallet_evm::account::CrossAccountId;
97use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, CommonCollectionOperations as _};97use pallet_common::{Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, CommonCollectionOperations as _};
1065 <TotalSupply<T>>::try_get((collection_id, token_id)).ok()1065 <TotalSupply<T>>::try_get((collection_id, token_id)).ok()
1066 }1066 }
1067
1068 pub fn set_collection_properties(
1069 collection: &RefungibleHandle<T>,
1070 sender: &T::CrossAccountId,
1071 properties: Vec<Property>,
1072 ) -> DispatchResult {
1073 <PalletCommon<T>>::set_collection_properties(collection, sender, properties)
1074 }
1075
1076 pub fn delete_collection_properties(
1077 collection: &RefungibleHandle<T>,
1078 sender: &T::CrossAccountId,
1079 property_keys: Vec<PropertyKey>,
1080 ) -> DispatchResult {
1081 <PalletCommon<T>>::delete_collection_properties(collection, sender, property_keys)
1082 }
1083
1084 pub fn set_token_property_permissions(
1085 collection: &RefungibleHandle<T>,
1086 sender: &T::CrossAccountId,
1087 property_permissions: Vec<PropertyKeyPermission>,
1088 ) -> DispatchResult {
1089 <PalletCommon<T>>::set_token_property_permissions(collection, sender, property_permissions)
1090 }
1067}1091}
10681092
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -212,17 +212,20 @@
     });
   });
 
-  it.only('Set properties for exist collection', async () => {
+  it('Set properties for exist collection', async () => {
     await usingApi(async api => {
       const collectionId = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},
       });
 
-      const properties = [{key: 'key1', value: 'val1'}];
-      // await expect(executeTransaction(
-      //   api, 
-      //   alice, 
-      //   api.tx.unique.setCollectionProperties(collectionId, properties), 
-      // )).to.not.be.rejected;
+      const properties = [
+        {key: 'key1', value: 'val1'},
+        {key: 'key2', value: 'val2'},
+      ];
+      await expect(executeTransaction(
+        api, 
+        alice, 
+        api.tx.unique.setCollectionProperties(collectionId, properties), 
+      )).to.not.be.rejected;
 
       const propertyPermissions = [
         {key: 'key1', permission: {collectionAdmin: true, mutable: false, tokenOwner: true}},