difftreelog
Add change_property_permissions
in: master
10 files changed
pallets/common/src/lib.rsdiffbeforeafterboth36 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;294294295 TokenPropertySet(CollectionId, TokenId, Property),295 TokenPropertySet(CollectionId, TokenId, Property),296297 PropertyPermissionSet(CollectionId, PropertyKeyPermission),296 }298 }297299298 #[pallet::error]300 #[pallet::error]741 |properties| properties.try_change_property(property.clone())743 |properties| properties.try_change_property(property.clone())742 )?;744 )?;743745744 <Pallet<T>>::deposit_event(Event::CollectionPropertySet(collection.id, property));746 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));745747746 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: PropertyKeyPermission765 permission: PropertyPermission,766 ) -> DispatchResult {767 ) -> DispatchResult {767 collection.check_is_owner_or_admin(sender)?;768 collection.check_is_owner_or_admin(sender)?;769770 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 }768775769 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)?;781782 Self::deposit_event(Event::PropertyPermissionSet(collection.id, property_permission));773783774 Ok(())784 Ok(())775 }785 }786787 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 }795796 Ok(())797 }776798777 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,pallets/fungible/src/common.rsdiffbeforeafterboth21use 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,};252526use 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 }6061 fn change_property_permissions(amount: u32) -> Weight {62 <SelfWeightOf<T>>::change_property_permissions(amount)63 }606461 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 }256257 fn change_property_permissions(258 &self,259 _sender: &T::CrossAccountId,260 _property_permissions: Vec<PropertyKeyPermission>,261 ) -> DispatchResultWithPostInfo {262 fail!(<Error<T>>::PropertiesNotAllowed)263 }252264253 fn set_variable_metadata(265 fn set_variable_metadata(254 &self,266 &self,pallets/fungible/src/weights.rsdiffbeforeafterboth37 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 083 }84 }8586 fn change_property_permissions(amount: u32) -> Weight {87 // Error88 089 }849085 // 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 0151 }157 }158159 fn change_property_permissions(amount: u32) -> Weight {160 // Error161 0162 }152163153 // Storage: Fungible Balance (r:2 w:2)164 // Storage: Fungible Balance (r:2 w:2)154 fn transfer() -> Weight {165 fn transfer() -> Weight {pallets/nonfungible/src/common.rsdiffbeforeafterboth181819use 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 }6061 fn change_property_permissions(amount: u32) -> Weight {62 <SelfWeightOf<T>>::change_property_permissions(amount)63 }606461 fn transfer() -> Weight {65 fn transfer() -> Weight {62 <SelfWeightOf<T>>::transfer()66 <SelfWeightOf<T>>::transfer()176 )180 )177 }181 }182183 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);189190 with_weight(191 <Pallet<T>>::change_property_permissions(self, sender, property_permissions),192 weight193 )194 }178195179 fn burn_item(196 fn burn_item(180 &self,197 &self,pallets/nonfungible/src/lib.rsdiffbeforeafterboth21use 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 }327328 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 }326339327 pub fn transfer(340 pub fn transfer(328 collection: &NonfungibleHandle<T>,341 collection: &NonfungibleHandle<T>,pallets/nonfungible/src/weights.rsdiffbeforeafterboth38 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 }106107 fn change_property_permissions(amount: u32) -> Weight {108 // TODO calculate appropriate weight109 (50_000_000 as Weight).saturating_mul(amount as Weight)110 }105111106 // 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 }211212 fn change_property_permissions(amount: u32) -> Weight {213 // TODO calculate appropriate weight214 (50_000_000 as Weight).saturating_mul(amount as Weight)215 }205216206 // 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)pallets/refungible/src/common.rsdiffbeforeafterboth20use 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 }7677 fn change_property_permissions(amount: u32) -> Weight {78 <SelfWeightOf<T>>::change_property_permissions(amount)79 }768077 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 }275276 fn change_property_permissions(277 &self,278 _sender: &T::CrossAccountId,279 _property_permissions: Vec<PropertyKeyPermission>,280 ) -> DispatchResultWithPostInfo {281 fail!(<Error<T>>::PropertiesNotAllowed)282 }271283272 fn set_variable_metadata(284 fn set_variable_metadata(273 &self,285 &self,pallets/refungible/src/weights.rsdiffbeforeafterboth40 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 0143 }144 }145146 fn change_property_permissions(amount: u32) -> Weight {147 // Error148 0149 }144150145 // 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 0322 }328 }329330 fn change_property_permissions(amount: u32) -> Weight {331 // Error332 0333 }323334324 // 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 {pallets/unique/src/lib.rsdiffbeforeafterboth39 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 }725726 #[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);734735 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);736737 dispatch_call::<T, _>(collection_id, |d| d.change_property_permissions(&sender, property_permissions))738 }725739726 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]740 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]727 #[transactional]741 #[transactional]runtime/common/src/weights.rsdiffbeforeafterboth62 dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))62 dispatch_weight::<T>() + max_weight_of!(change_token_properties(amount))63 }63 }6465 fn change_property_permissions(amount: u32) -> Weight {66 dispatch_weight::<T>() + max_weight_of!(change_property_permissions(amount))67 }646865 fn transfer() -> Weight {69 fn transfer() -> Weight {66 dispatch_weight::<T>() + max_weight_of!(transfer())70 dispatch_weight::<T>() + max_weight_of!(transfer())