difftreelog
Add extrinsic: delete token property
in: master
12 files changed
pallets/common/src/lib.rsdiffbeforeafterboth294294295 TokenPropertySet(CollectionId, TokenId, Property),295 TokenPropertySet(CollectionId, TokenId, Property),296297 TokenPropertyDeleted(CollectionId, TokenId, PropertyKey),296298297 PropertyPermissionSet(CollectionId, PropertyKeyPermission),299 PropertyPermissionSet(CollectionId, PropertyKeyPermission),298 }300 }738 ) -> DispatchResult {740 ) -> DispatchResult {739 collection.check_is_owner_or_admin(sender)?;741 collection.check_is_owner_or_admin(sender)?;740742741 CollectionProperties::<T>::try_mutate(743 CollectionProperties::<T>::try_mutate(collection.id, |properties| {742 collection.id,743 |properties| properties.try_set_property(property.clone())744 properties.try_set_property(property.clone())744 )?;745 })?;745746746 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));747 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));747748950 fn burn_item() -> Weight;957 fn burn_item() -> Weight;951 fn set_collection_properties(amount: u32) -> Weight;958 fn set_collection_properties(amount: u32) -> Weight;952 fn set_token_properties(amount: u32) -> Weight;959 fn set_token_properties(amount: u32) -> Weight;960 fn delete_token_properties(amount: u32) -> Weight;953 fn set_property_permissions(amount: u32) -> Weight;961 fn set_property_permissions(amount: u32) -> Weight;954 fn transfer() -> Weight;962 fn transfer() -> Weight;955 fn approve() -> Weight;963 fn approve() -> Weight;996 token_id: TokenId,1004 token_id: TokenId,997 property: Vec<Property>,1005 property: Vec<Property>,998 ) -> DispatchResultWithPostInfo;1006 ) -> DispatchResultWithPostInfo;1007 fn delete_token_properties(1008 &self,1009 sender: T::CrossAccountId,1010 token_id: TokenId,1011 property_keys: Vec<PropertyKey>,1012 ) -> DispatchResultWithPostInfo;999 fn set_property_permissions(1013 fn set_property_permissions(1000 &self,1014 &self,1001 sender: &T::CrossAccountId,1015 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, PropertyKeyPermission,};24use up_data_structs::{CustomDataLimit, Property, PropertyKey, 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>>::set_token_properties(amount)58 <SelfWeightOf<T>>::set_token_properties(amount)59 }59 }6061 fn delete_token_properties(amount: u32) -> Weight {62 <SelfWeightOf<T>>::delete_token_properties(amount)63 }606461 fn set_property_permissions(amount: u32) -> Weight {65 fn set_property_permissions(amount: u32) -> Weight {62 <SelfWeightOf<T>>::set_property_permissions(amount)66 <SelfWeightOf<T>>::set_property_permissions(amount)262 fail!(<Error<T>>::PropertiesNotAllowed)266 fail!(<Error<T>>::PropertiesNotAllowed)263 }267 }268269 fn delete_token_properties(270 &self,271 _sender: T::CrossAccountId,272 _token_id: TokenId,273 _property_keys: Vec<PropertyKey>,274 ) -> DispatchResultWithPostInfo {275 fail!(<Error<T>>::PropertiesNotAllowed)276 }264277265 fn set_variable_metadata(278 fn set_variable_metadata(266 &self,279 &self,pallets/fungible/src/weights.rsdiffbeforeafterboth37 fn burn_item() -> Weight;37 fn burn_item() -> Weight;38 fn set_collection_properties(amount: u32) -> Weight;38 fn set_collection_properties(amount: u32) -> Weight;39 fn set_token_properties(amount: u32) -> Weight;39 fn set_token_properties(amount: u32) -> Weight;40 fn delete_token_properties(amount: u32) -> Weight;40 fn set_property_permissions(amount: u32) -> Weight;41 fn set_property_permissions(amount: u32) -> Weight;41 fn transfer() -> Weight;42 fn transfer() -> Weight;42 fn approve() -> Weight;43 fn approve() -> Weight;73 .saturating_add(T::DbWeight::get().writes(2 as Weight))74 .saturating_add(T::DbWeight::get().writes(2 as Weight))74 }75 }757676 fn set_collection_properties(amount: u32) -> Weight {77 fn set_collection_properties(_amount: u32) -> Weight {77 // Error78 // Error78 079 079 }80 }808181 fn set_token_properties(amount: u32) -> Weight {82 fn set_token_properties(_amount: u32) -> Weight {82 // Error83 // Error83 084 084 }85 }8687 fn delete_token_properties(_amount: u32) -> Weight {88 // Error89 090 }859186 fn set_property_permissions(amount: u32) -> Weight {92 fn set_property_permissions(_amount: u32) -> Weight {87 // Error93 // Error88 094 089 }95 }146 .saturating_add(RocksDbWeight::get().writes(2 as Weight))152 .saturating_add(RocksDbWeight::get().writes(2 as Weight))147 }153 }148154149 fn set_collection_properties(amount: u32) -> Weight {155 fn set_collection_properties(_amount: u32) -> Weight {150 // Error156 // Error151 0157 0152 }158 }153159154 fn set_token_properties(amount: u32) -> Weight {160 fn set_token_properties(_amount: u32) -> Weight {155 // Error161 // Error156 0162 0157 }163 }164165 fn delete_token_properties(_amount: u32) -> Weight {166 // Error167 0168 }158169159 fn set_property_permissions(amount: u32) -> Weight {170 fn set_property_permissions(_amount: u32) -> Weight {160 // Error171 // Error161 0172 0162 }173 }pallets/nonfungible/src/common.rsdiffbeforeafterboth19use 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, PropertyKeyPermission,21 TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,22 PropertyKey, PropertyKeyPermission,22};23};23use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};24use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};24use sp_runtime::DispatchError;25use sp_runtime::DispatchError;58 <SelfWeightOf<T>>::set_token_properties(amount)59 <SelfWeightOf<T>>::set_token_properties(amount)59 }60 }6162 fn delete_token_properties(amount: u32) -> Weight {63 <SelfWeightOf<T>>::delete_token_properties(amount)64 }606561 fn set_property_permissions(amount: u32) -> Weight {66 fn set_property_permissions(amount: u32) -> Weight {62 <SelfWeightOf<T>>::set_property_permissions(amount)67 <SelfWeightOf<T>>::set_property_permissions(amount)180 )185 )181 }186 }187188 fn delete_token_properties(189 &self,190 sender: T::CrossAccountId,191 token_id: TokenId,192 property_keys: Vec<PropertyKey>,193 ) -> DispatchResultWithPostInfo {194 let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);195196 with_weight(197 <Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),198 weight,199 )200 }182201183 fn set_property_permissions(202 fn set_property_permissions(184 &self,203 &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 PropertyKey, PropertyKeyPermission,25};25};26use pallet_evm::account::CrossAccountId;26use pallet_evm::account::CrossAccountId;27use pallet_common::{27use pallet_common::{261 token_id: TokenId,261 token_id: TokenId,262 property: Property,262 property: Property,263 ) -> DispatchResult {263 ) -> DispatchResult {264 let permission = <PalletCommon<T>>::property_permission(collection.id)265 .get(&property.key)266 .map(|p| p.clone())267 .unwrap_or(PropertyPermission::None);268269 let token_data = <TokenData<T>>::get((collection.id, token_id))270 .ok_or(<CommonError<T>>::TokenNotFound)?;271272 let check_token_owner = || -> DispatchResult {273 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);274 Ok(())275 };276277 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))264 Self::check_token_change_permission(collection, sender, token_id, &property.key)?;278 .get_property(&property.key)279 .is_some();280281 match (permission, is_property_exists) {282 (PropertyPermission::AdminConst, false) => {283 collection.check_is_owner_or_admin(sender)?284 }285 (PropertyPermission::Admin, _) => collection.check_is_owner_or_admin(sender)?,286 (PropertyPermission::ItemOwnerConst, false) => check_token_owner()?,287 (PropertyPermission::ItemOwner, _) => check_token_owner()?,288 (PropertyPermission::ItemOwnerOrAdmin, _) => {289 check_token_owner().or(collection.check_is_owner_or_admin(sender))?;290 }291 _ => return Err(<CommonError<T>>::NoPermission.into()),292 }293265294 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {266 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {295 properties.try_set_property(property.clone())267 properties.try_set_property(property.clone())317 Ok(())289 Ok(())318 }290 }291292 pub fn delete_token_property(293 collection: &NonfungibleHandle<T>,294 sender: &T::CrossAccountId,295 token_id: TokenId,296 property_key: PropertyKey,297 ) -> DispatchResult {298 Self::check_token_change_permission(collection, sender, token_id, &property_key)?;299300 <TokenProperties<T>>::mutate((collection.id, token_id), |properties| {301 properties.remove_property(&property_key);302 });303304 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(305 collection.id,306 token_id,307 property_key,308 ));309310 Ok(())311 }312313 fn check_token_change_permission(314 collection: &NonfungibleHandle<T>,315 sender: &T::CrossAccountId,316 token_id: TokenId,317 property_key: &PropertyKey,318 ) -> DispatchResult {319 let permission = <PalletCommon<T>>::property_permission(collection.id)320 .get(property_key)321 .map(|p| p.clone())322 .unwrap_or(PropertyPermission::None);323324 let token_data = <TokenData<T>>::get((collection.id, token_id))325 .ok_or(<CommonError<T>>::TokenNotFound)?;326327 let check_token_owner = || -> DispatchResult {328 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);329 Ok(())330 };331332 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))333 .get_property(property_key)334 .is_some();335336 match (permission, is_property_exists) {337 (PropertyPermission::AdminConst, false) => collection.check_is_owner_or_admin(sender),338 (PropertyPermission::Admin, _) => collection.check_is_owner_or_admin(sender),339 (PropertyPermission::ItemOwnerConst, false) => check_token_owner(),340 (PropertyPermission::ItemOwner, _) => check_token_owner(),341 (PropertyPermission::ItemOwnerOrAdmin, _) => {342 check_token_owner().or(collection.check_is_owner_or_admin(sender))343 }344 _ => Err(<CommonError<T>>::NoPermission.into()),345 }346 }347348 pub fn delete_token_properties(349 collection: &NonfungibleHandle<T>,350 sender: &T::CrossAccountId,351 token_id: TokenId,352 property_keys: Vec<PropertyKey>,353 ) -> DispatchResult {354 for key in property_keys {355 Self::delete_token_property(collection, sender, token_id, key)?;356 }357358 Ok(())359 }319360320 pub fn set_collection_properties(361 pub fn set_collection_properties(321 collection: &NonfungibleHandle<T>,362 collection: &NonfungibleHandle<T>,pallets/nonfungible/src/weights.rsdiffbeforeafterboth38 fn burn_item() -> Weight;38 fn burn_item() -> Weight;39 fn set_collection_properties(amount: u32) -> Weight;39 fn set_collection_properties(amount: u32) -> Weight;40 fn set_token_properties(amount: u32) -> Weight;40 fn set_token_properties(amount: u32) -> Weight;41 fn delete_token_properties(amount: u32) -> Weight;41 fn set_property_permissions(amount: u32) -> Weight;42 fn set_property_permissions(amount: u32) -> Weight;42 fn transfer() -> Weight;43 fn transfer() -> Weight;43 fn approve() -> Weight;44 fn approve() -> Weight;104 (50_000_000 as Weight).saturating_mul(amount as Weight)105 (50_000_000 as Weight).saturating_mul(amount as Weight)105 }106 }107108 fn delete_token_properties(amount: u32) -> Weight {109 // TODO calculate appropriate weight110 (50_000_000 as Weight).saturating_mul(amount as Weight)111 }106112107 fn set_property_permissions(amount: u32) -> Weight {113 fn set_property_permissions(amount: u32) -> Weight {108 // TODO calculate appropriate weight114 // TODO calculate appropriate weight209 (50_000_000 as Weight).saturating_mul(amount as Weight)215 (50_000_000 as Weight).saturating_mul(amount as Weight)210 }216 }217218 fn delete_token_properties(amount: u32) -> Weight {219 // TODO calculate appropriate weight220 (50_000_000 as Weight).saturating_mul(amount as Weight)221 }211222212 fn set_property_permissions(amount: u32) -> Weight {223 fn set_property_permissions(amount: u32) -> Weight {213 // TODO calculate appropriate weight224 // TODO calculate appropriate weightpallets/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, PropertyKeyPermission,23 budget::Budget, Property, PropertyKey, 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>>::set_token_properties(amount)74 <SelfWeightOf<T>>::set_token_properties(amount)75 }75 }7677 fn delete_token_properties(amount: u32) -> Weight {78 <SelfWeightOf<T>>::delete_token_properties(amount)79 }768077 fn set_property_permissions(amount: u32) -> Weight {81 fn set_property_permissions(amount: u32) -> Weight {78 <SelfWeightOf<T>>::set_property_permissions(amount)82 <SelfWeightOf<T>>::set_property_permissions(amount)281 fail!(<Error<T>>::PropertiesNotAllowed)285 fail!(<Error<T>>::PropertiesNotAllowed)282 }286 }287288 fn delete_token_properties(289 &self,290 _sender: T::CrossAccountId,291 _token_id: TokenId,292 _property_keys: Vec<PropertyKey>,293 ) -> DispatchResultWithPostInfo {294 fail!(<Error<T>>::PropertiesNotAllowed)295 }283296284 fn set_variable_metadata(297 fn set_variable_metadata(285 &self,298 &self,pallets/refungible/src/weights.rsdiffbeforeafterboth40 fn burn_item_fully() -> Weight;40 fn burn_item_fully() -> Weight;41 fn set_collection_properties(amount: u32) -> Weight;41 fn set_collection_properties(amount: u32) -> Weight;42 fn set_token_properties(amount: u32) -> Weight;42 fn set_token_properties(amount: u32) -> Weight;43 fn delete_token_properties(amount: u32) -> Weight;43 fn set_property_permissions(amount: u32) -> Weight;44 fn set_property_permissions(amount: u32) -> Weight;44 fn transfer_normal() -> Weight;45 fn transfer_normal() -> Weight;45 fn transfer_creating() -> Weight;46 fn transfer_creating() -> Weight;133 .saturating_add(T::DbWeight::get().writes(6 as Weight))134 .saturating_add(T::DbWeight::get().writes(6 as Weight))134 }135 }135136136 fn set_collection_properties(amount: u32) -> Weight {137 fn set_collection_properties(_amount: u32) -> Weight {137 // Error138 // Error138 0139 0139 }140 }140141141 fn set_token_properties(amount: u32) -> Weight {142 fn set_token_properties(_amount: u32) -> Weight {142 // Error143 // Error143 0144 0144 }145 }146147 fn delete_token_properties(_amount: u32) -> Weight {148 // Error149 0150 }145151146 fn set_property_permissions(amount: u32) -> Weight {152 fn set_property_permissions(_amount: u32) -> Weight {147 // Error153 // Error148 0154 0149 }155 }317 .saturating_add(RocksDbWeight::get().writes(6 as Weight))323 .saturating_add(RocksDbWeight::get().writes(6 as Weight))318 }324 }319325320 fn set_collection_properties(amount: u32) -> Weight {326 fn set_collection_properties(_amount: u32) -> Weight {321 // Error327 // Error322 0328 0323 }329 }324330325 fn set_token_properties(amount: u32) -> Weight {331 fn set_token_properties(_amount: u32) -> Weight {326 // Error332 // Error327 0333 0328 }334 }335336 fn delete_token_properties(_amount: u32) -> Weight {337 // Error338 0339 }329340330 fn set_property_permissions(amount: u32) -> Weight {341 fn set_property_permissions(_amount: u32) -> Weight {331 // Error342 // Error332 0343 0333 }344 }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, PropertyKeyPermission,42 CreateItemExData, budget, CollectionField, Property, PropertyKey, 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.set_token_properties(sender, token_id, properties))723 dispatch_call::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties))724 }724 }725726 #[weight = T::CommonWeightInfo::delete_token_properties(properties.len() as u32)]727 #[transactional]728 pub fn delete_token_properties(729 origin,730 collection_id: CollectionId,731 token_id: TokenId,732 properties: Vec<PropertyKey>733 ) -> DispatchResultWithPostInfo {734 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);735736 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);737738 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, properties))739 }725740726 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]741 #[weight = T::CommonWeightInfo::set_property_permissions(property_permissions.len() as u32)]727 #[transactional]742 #[transactional]primitives/data-structs/src/lib.rsdiffbeforeafterboth720 Ok(())720 Ok(())721 }721 }722723 pub fn remove_property(&mut self, key: &PropertyKey) {724 let property = self.map.get(key);725726 if let Some(value) = property {727 let value_len = value.len() as u32;728729 self.map.remove(key);730 self.consumed_space -= value_len;731 }732 }722733723 pub fn get_property(&self, key: &PropertyKey) -> Option<&PropertyValue> {734 pub fn get_property(&self, key: &PropertyKey) -> Option<&PropertyValue> {724 self.map.get(key)735 self.map.get(key)primitives/rpc/src/lib.rsdiffbeforeafterboth17#![cfg_attr(not(feature = "std"), no_std)]17#![cfg_attr(not(feature = "std"), no_std)]181819use up_data_structs::{19use up_data_structs::{CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits};20 CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,21};22use sp_std::vec::Vec;20use sp_std::vec::Vec;23use codec::Decode;21use codec::Decode;runtime/common/src/weights.rsdiffbeforeafterboth62 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))62 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))63 }63 }6465 fn delete_token_properties(amount: u32) -> Weight {66 dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))67 }646865 fn set_property_permissions(amount: u32) -> Weight {69 fn set_property_permissions(amount: u32) -> Weight {66 dispatch_weight::<T>() + max_weight_of!(set_property_permissions(amount))70 dispatch_weight::<T>() + max_weight_of!(set_property_permissions(amount))