git.delta.rocks / unique-network / refs/commits / 117d4ce3143f

difftreelog

Add change_property_permissions

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

10 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
36 CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,36 CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,
37 CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,37 CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,
38 PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,38 PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
39 PropertiesError,39 PropertiesError, PropertyKeyPermission,
40};40};
41pub use pallet::*;41pub use pallet::*;
42use sp_core::H160;42use sp_core::H160;
294294
295 TokenPropertySet(CollectionId, TokenId, Property),295 TokenPropertySet(CollectionId, TokenId, Property),
296
297 PropertyPermissionSet(CollectionId, PropertyKeyPermission),
296 }298 }
297299
298 #[pallet::error]300 #[pallet::error]
741 |properties| properties.try_change_property(property.clone())743 |properties| properties.try_change_property(property.clone())
742 )?;744 )?;
743745
744 <Pallet<T>>::deposit_event(Event::CollectionPropertySet(collection.id, property));746 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));
745747
746 Ok(())748 Ok(())
747 }749 }
761 pub fn change_property_permission(763 pub fn change_property_permission(
762 collection: &CollectionHandle<T>,764 collection: &CollectionHandle<T>,
763 sender: &T::CrossAccountId,765 sender: &T::CrossAccountId,
764 property_key: PropertyKey,766 property_permission: PropertyKeyPermission
765 permission: PropertyPermission,
766 ) -> DispatchResult {767 ) -> DispatchResult {
767 collection.check_is_owner_or_admin(sender)?;768 collection.check_is_owner_or_admin(sender)?;
769
770 let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);
771 let current_permission = all_permissions.get(&property_permission.key);
772 if matches![current_permission, Some(PropertyPermission::AdminConst | PropertyPermission::ItemOwnerConst)] {
773 return Err(<Error<T>>::NoPermission.into());
774 }
768775
769 CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {776 CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {
777 let property_permission = property_permission.clone();
770 permissions.try_insert(property_key, permission)778 permissions.try_insert(property_permission.key, property_permission.permission)
771 })779 })
772 .map_err(|_| PropertiesError::PropertyLimitReached)?;780 .map_err(|_| PropertiesError::PropertyLimitReached)?;
781
782 Self::deposit_event(Event::PropertyPermissionSet(collection.id, property_permission));
773783
774 Ok(())784 Ok(())
775 }785 }
786
787 pub fn change_property_permissions(
788 collection: &CollectionHandle<T>,
789 sender: &T::CrossAccountId,
790 property_permissions: Vec<PropertyKeyPermission>
791 ) -> DispatchResult {
792 for prop_pemission in property_permissions {
793 Self::change_property_permission(collection, sender, prop_pemission)?;
794 }
795
796 Ok(())
797 }
776798
777 fn set_field_raw(799 fn set_field_raw(
778 collection_id: CollectionId,800 collection_id: CollectionId,
928 fn burn_item() -> Weight;950 fn burn_item() -> Weight;
929 fn change_collection_properties(amount: u32) -> Weight;951 fn change_collection_properties(amount: u32) -> Weight;
930 fn change_token_properties(amount: u32) -> Weight;952 fn change_token_properties(amount: u32) -> Weight;
953 fn change_property_permissions(amount: u32) -> Weight;
931 fn transfer() -> Weight;954 fn transfer() -> Weight;
932 fn approve() -> Weight;955 fn approve() -> Weight;
933 fn transfer_from() -> Weight;956 fn transfer_from() -> Weight;
975 token_id: TokenId,996 token_id: TokenId,
976 property: Vec<Property>,997 property: Vec<Property>,
977 ) -> DispatchResultWithPostInfo;998 ) -> DispatchResultWithPostInfo;
978999 fn change_property_permissions(
1000 &self,
1001 sender: &T::CrossAccountId,
1002 property_permissions: Vec<PropertyKeyPermission>,
1003 ) -> DispatchResultWithPostInfo;
979 fn transfer(1004 fn transfer(
980 &self,1005 &self,
981 sender: T::CrossAccountId,1006 sender: T::CrossAccountId,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};21use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
22use sp_runtime::ArithmeticError;22use sp_runtime::ArithmeticError;
23use sp_std::{vec::Vec, vec};23use sp_std::{vec::Vec, vec};
24use up_data_structs::{CustomDataLimit, Property};24use up_data_structs::{CustomDataLimit, Property, PropertyKeyPermission,};
2525
26use crate::{26use crate::{
27 Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,27 Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
58 <SelfWeightOf<T>>::change_token_properties(amount)58 <SelfWeightOf<T>>::change_token_properties(amount)
59 }59 }
60
61 fn change_property_permissions(amount: u32) -> Weight {
62 <SelfWeightOf<T>>::change_property_permissions(amount)
63 }
6064
61 fn transfer() -> Weight {65 fn transfer() -> Weight {
62 <SelfWeightOf<T>>::transfer()66 <SelfWeightOf<T>>::transfer()
250 fail!(<Error<T>>::PropertiesNotAllowed)254 fail!(<Error<T>>::PropertiesNotAllowed)
251 }255 }
256
257 fn change_property_permissions(
258 &self,
259 _sender: &T::CrossAccountId,
260 _property_permissions: Vec<PropertyKeyPermission>,
261 ) -> DispatchResultWithPostInfo {
262 fail!(<Error<T>>::PropertiesNotAllowed)
263 }
252264
253 fn set_variable_metadata(265 fn set_variable_metadata(
254 &self,266 &self,
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
37 fn burn_item() -> Weight;37 fn burn_item() -> Weight;
38 fn change_collection_properties(amount: u32) -> Weight;38 fn change_collection_properties(amount: u32) -> Weight;
39 fn change_token_properties(amount: u32) -> Weight;39 fn change_token_properties(amount: u32) -> Weight;
40 fn change_property_permissions(amount: u32) -> Weight;
40 fn transfer() -> Weight;41 fn transfer() -> Weight;
41 fn approve() -> Weight;42 fn approve() -> Weight;
42 fn transfer_from() -> Weight;43 fn transfer_from() -> Weight;
82 083 0
83 }84 }
85
86 fn change_property_permissions(amount: u32) -> Weight {
87 // Error
88 0
89 }
8490
85 // Storage: Fungible Balance (r:2 w:2)91 // Storage: Fungible Balance (r:2 w:2)
86 fn transfer() -> Weight {92 fn transfer() -> Weight {
150 0156 0
151 }157 }
158
159 fn change_property_permissions(amount: u32) -> Weight {
160 // Error
161 0
162 }
152163
153 // Storage: Fungible Balance (r:2 w:2)164 // Storage: Fungible Balance (r:2 w:2)
154 fn transfer() -> Weight {165 fn transfer() -> Weight {
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
1818
19use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};19use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
20use up_data_structs::{20use up_data_structs::{
21 TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,21 TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property, PropertyKeyPermission,
22};22};
23use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};23use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
24use sp_runtime::DispatchError;24use sp_runtime::DispatchError;
58 <SelfWeightOf<T>>::change_token_properties(amount)58 <SelfWeightOf<T>>::change_token_properties(amount)
59 }59 }
60
61 fn change_property_permissions(amount: u32) -> Weight {
62 <SelfWeightOf<T>>::change_property_permissions(amount)
63 }
6064
61 fn transfer() -> Weight {65 fn transfer() -> Weight {
62 <SelfWeightOf<T>>::transfer()66 <SelfWeightOf<T>>::transfer()
176 )180 )
177 }181 }
182
183 fn change_property_permissions(
184 &self,
185 sender: &T::CrossAccountId,
186 property_permissions: Vec<PropertyKeyPermission>,
187 ) -> DispatchResultWithPostInfo {
188 let weight = <CommonWeights<T>>::change_property_permissions(property_permissions.len() as u32);
189
190 with_weight(
191 <Pallet<T>>::change_property_permissions(self, sender, property_permissions),
192 weight
193 )
194 }
178195
179 fn burn_item(196 fn burn_item(
180 &self,197 &self,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
21use up_data_structs::{21use up_data_structs::{
22 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,22 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
23 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,23 mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
24 PropertyKeyPermission,
24};25};
25use pallet_evm::account::CrossAccountId;26use pallet_evm::account::CrossAccountId;
26use pallet_common::{27use pallet_common::{
324 <PalletCommon<T>>::change_collection_properties(collection, sender, properties)325 <PalletCommon<T>>::change_collection_properties(collection, sender, properties)
325 }326 }
327
328 pub fn change_property_permissions(
329 collection: &CollectionHandle<T>,
330 sender: &T::CrossAccountId,
331 property_permissions: Vec<PropertyKeyPermission>
332 ) -> DispatchResult {
333 <PalletCommon<T>>::change_property_permissions(
334 collection,
335 sender,
336 property_permissions,
337 )
338 }
326339
327 pub fn transfer(340 pub fn transfer(
328 collection: &NonfungibleHandle<T>,341 collection: &NonfungibleHandle<T>,
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
38 fn burn_item() -> Weight;38 fn burn_item() -> Weight;
39 fn change_collection_properties(amount: u32) -> Weight;39 fn change_collection_properties(amount: u32) -> Weight;
40 fn change_token_properties(amount: u32) -> Weight;40 fn change_token_properties(amount: u32) -> Weight;
41 fn change_property_permissions(amount: u32) -> Weight;
41 fn transfer() -> Weight;42 fn transfer() -> Weight;
42 fn approve() -> Weight;43 fn approve() -> Weight;
43 fn transfer_from() -> Weight;44 fn transfer_from() -> Weight;
103 (50_000_000 as Weight).saturating_mul(amount as Weight)104 (50_000_000 as Weight).saturating_mul(amount as Weight)
104 }105 }
106
107 fn change_property_permissions(amount: u32) -> Weight {
108 // TODO calculate appropriate weight
109 (50_000_000 as Weight).saturating_mul(amount as Weight)
110 }
105111
106 // Storage: Nonfungible TokenData (r:1 w:1)112 // Storage: Nonfungible TokenData (r:1 w:1)
107 // Storage: Nonfungible AccountBalance (r:2 w:2)113 // Storage: Nonfungible AccountBalance (r:2 w:2)
203 (50_000_000 as Weight).saturating_mul(amount as Weight)209 (50_000_000 as Weight).saturating_mul(amount as Weight)
204 }210 }
211
212 fn change_property_permissions(amount: u32) -> Weight {
213 // TODO calculate appropriate weight
214 (50_000_000 as Weight).saturating_mul(amount as Weight)
215 }
205216
206 // Storage: Nonfungible TokenData (r:1 w:1)217 // Storage: Nonfungible TokenData (r:1 w:1)
207 // Storage: Nonfungible AccountBalance (r:2 w:2)218 // Storage: Nonfungible AccountBalance (r:2 w:2)
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};
21use up_data_structs::{21use up_data_structs::{
22 CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,22 CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,
23 budget::Budget, Property,23 budget::Budget, Property, PropertyKeyPermission,
24};24};
25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
26use sp_runtime::DispatchError;26use sp_runtime::DispatchError;
74 <SelfWeightOf<T>>::change_token_properties(amount)74 <SelfWeightOf<T>>::change_token_properties(amount)
75 }75 }
76
77 fn change_property_permissions(amount: u32) -> Weight {
78 <SelfWeightOf<T>>::change_property_permissions(amount)
79 }
7680
77 fn transfer() -> Weight {81 fn transfer() -> Weight {
78 max_weight_of!(82 max_weight_of!(
269 fail!(<Error<T>>::PropertiesNotAllowed)273 fail!(<Error<T>>::PropertiesNotAllowed)
270 }274 }
275
276 fn change_property_permissions(
277 &self,
278 _sender: &T::CrossAccountId,
279 _property_permissions: Vec<PropertyKeyPermission>,
280 ) -> DispatchResultWithPostInfo {
281 fail!(<Error<T>>::PropertiesNotAllowed)
282 }
271283
272 fn set_variable_metadata(284 fn set_variable_metadata(
273 &self,285 &self,
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
40 fn burn_item_fully() -> Weight;40 fn burn_item_fully() -> Weight;
41 fn change_collection_properties(amount: u32) -> Weight;41 fn change_collection_properties(amount: u32) -> Weight;
42 fn change_token_properties(amount: u32) -> Weight;42 fn change_token_properties(amount: u32) -> Weight;
43 fn change_property_permissions(amount: u32) -> Weight;
43 fn transfer_normal() -> Weight;44 fn transfer_normal() -> Weight;
44 fn transfer_creating() -> Weight;45 fn transfer_creating() -> Weight;
45 fn transfer_removing() -> Weight;46 fn transfer_removing() -> Weight;
142 0143 0
143 }144 }
145
146 fn change_property_permissions(amount: u32) -> Weight {
147 // Error
148 0
149 }
144150
145 // Storage: Refungible Balance (r:2 w:2)151 // Storage: Refungible Balance (r:2 w:2)
146 fn transfer_normal() -> Weight {152 fn transfer_normal() -> Weight {
321 0327 0
322 }328 }
329
330 fn change_property_permissions(amount: u32) -> Weight {
331 // Error
332 0
333 }
323334
324 // Storage: Refungible Balance (r:2 w:2)335 // Storage: Refungible Balance (r:2 w:2)
325 fn transfer_normal() -> Weight {336 fn transfer_normal() -> Weight {
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,
41 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,41 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,
42 CreateItemExData, budget, CollectionField, Property,42 CreateItemExData, budget, CollectionField, Property, PropertyKeyPermission,
43};43};
44use pallet_evm::account::CrossAccountId;44use pallet_evm::account::CrossAccountId;
45use pallet_common::{45use pallet_common::{
723 dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))723 dispatch_call::<T, _>(collection_id, |d| d.change_token_properties(sender, token_id, properties))
724 }724 }
725
726 #[weight = T::CommonWeightInfo::change_property_permissions(property_permissions.len() as u32)]
727 #[transactional]
728 pub fn change_property_permissions(
729 origin,
730 collection_id: CollectionId,
731 property_permissions: Vec<PropertyKeyPermission>,
732 ) -> DispatchResultWithPostInfo {
733 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);
734
735 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
736
737 dispatch_call::<T, _>(collection_id, |d| d.change_property_permissions(&sender, property_permissions))
738 }
725739
726 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]740 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]
727 #[transactional]741 #[transactional]
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
62 dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))62 dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))
63 }63 }
64
65 fn change_property_permissions(amount: u32) -> Weight {
66 dispatch_weight::<T>() + max_weight_of!(change_property_permissions(amount))
67 }
6468
65 fn transfer() -> Weight {69 fn transfer() -> Weight {
66 dispatch_weight::<T>() + max_weight_of!(transfer())70 dispatch_weight::<T>() + max_weight_of!(transfer())