git.delta.rocks / unique-network / refs/commits / aa3d2ae73e39

difftreelog

Add extrinsic: delete token property

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

12 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
294294
295 TokenPropertySet(CollectionId, TokenId, Property),295 TokenPropertySet(CollectionId, TokenId, Property),
296
297 TokenPropertyDeleted(CollectionId, TokenId, PropertyKey),
296298
297 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)?;
740742
741 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 })?;
745746
746 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));747 Self::deposit_event(Event::CollectionPropertySet(collection.id, property));
747748
950 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,
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, PropertyKeyPermission,};24use up_data_structs::{CustomDataLimit, Property, PropertyKey, 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>>::set_token_properties(amount)58 <SelfWeightOf<T>>::set_token_properties(amount)
59 }59 }
60
61 fn delete_token_properties(amount: u32) -> Weight {
62 <SelfWeightOf<T>>::delete_token_properties(amount)
63 }
6064
61 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 }
268
269 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 }
264277
265 fn set_variable_metadata(278 fn set_variable_metadata(
266 &self,279 &self,
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
37 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 }
7576
76 fn set_collection_properties(amount: u32) -> Weight {77 fn set_collection_properties(_amount: u32) -> Weight {
77 // Error78 // Error
78 079 0
79 }80 }
8081
81 fn set_token_properties(amount: u32) -> Weight {82 fn set_token_properties(_amount: u32) -> Weight {
82 // Error83 // Error
83 084 0
84 }85 }
86
87 fn delete_token_properties(_amount: u32) -> Weight {
88 // Error
89 0
90 }
8591
86 fn set_property_permissions(amount: u32) -> Weight {92 fn set_property_permissions(_amount: u32) -> Weight {
87 // Error93 // Error
88 094 0
89 }95 }
146 .saturating_add(RocksDbWeight::get().writes(2 as Weight))152 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
147 }153 }
148154
149 fn set_collection_properties(amount: u32) -> Weight {155 fn set_collection_properties(_amount: u32) -> Weight {
150 // Error156 // Error
151 0157 0
152 }158 }
153159
154 fn set_token_properties(amount: u32) -> Weight {160 fn set_token_properties(_amount: u32) -> Weight {
155 // Error161 // Error
156 0162 0
157 }163 }
164
165 fn delete_token_properties(_amount: u32) -> Weight {
166 // Error
167 0
168 }
158169
159 fn set_property_permissions(amount: u32) -> Weight {170 fn set_property_permissions(_amount: u32) -> Weight {
160 // Error171 // Error
161 0172 0
162 }173 }
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
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, 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 }
61
62 fn delete_token_properties(amount: u32) -> Weight {
63 <SelfWeightOf<T>>::delete_token_properties(amount)
64 }
6065
61 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 }
187
188 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);
195
196 with_weight(
197 <Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),
198 weight,
199 )
200 }
182201
183 fn set_property_permissions(202 fn set_property_permissions(
184 &self,203 &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 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);
268
269 let token_data = <TokenData<T>>::get((collection.id, token_id))
270 .ok_or(<CommonError<T>>::TokenNotFound)?;
271
272 let check_token_owner = || -> DispatchResult {
273 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);
274 Ok(())
275 };
276
277 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();
280
281 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 }
293265
294 <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 }
291
292 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)?;
299
300 <TokenProperties<T>>::mutate((collection.id, token_id), |properties| {
301 properties.remove_property(&property_key);
302 });
303
304 <PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
305 collection.id,
306 token_id,
307 property_key,
308 ));
309
310 Ok(())
311 }
312
313 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);
323
324 let token_data = <TokenData<T>>::get((collection.id, token_id))
325 .ok_or(<CommonError<T>>::TokenNotFound)?;
326
327 let check_token_owner = || -> DispatchResult {
328 ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);
329 Ok(())
330 };
331
332 let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))
333 .get_property(property_key)
334 .is_some();
335
336 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 }
347
348 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 }
357
358 Ok(())
359 }
319360
320 pub fn set_collection_properties(361 pub fn set_collection_properties(
321 collection: &NonfungibleHandle<T>,362 collection: &NonfungibleHandle<T>,
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
38 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 }
107
108 fn delete_token_properties(amount: u32) -> Weight {
109 // TODO calculate appropriate weight
110 (50_000_000 as Weight).saturating_mul(amount as Weight)
111 }
106112
107 fn set_property_permissions(amount: u32) -> Weight {113 fn set_property_permissions(amount: u32) -> Weight {
108 // TODO calculate appropriate weight114 // TODO calculate appropriate weight
209 (50_000_000 as Weight).saturating_mul(amount as Weight)215 (50_000_000 as Weight).saturating_mul(amount as Weight)
210 }216 }
217
218 fn delete_token_properties(amount: u32) -> Weight {
219 // TODO calculate appropriate weight
220 (50_000_000 as Weight).saturating_mul(amount as Weight)
221 }
211222
212 fn set_property_permissions(amount: u32) -> Weight {223 fn set_property_permissions(amount: u32) -> Weight {
213 // TODO calculate appropriate weight224 // TODO calculate appropriate weight
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, 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 }
76
77 fn delete_token_properties(amount: u32) -> Weight {
78 <SelfWeightOf<T>>::delete_token_properties(amount)
79 }
7680
77 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 }
287
288 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 }
283296
284 fn set_variable_metadata(297 fn set_variable_metadata(
285 &self,298 &self,
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
40 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 }
135136
136 fn set_collection_properties(amount: u32) -> Weight {137 fn set_collection_properties(_amount: u32) -> Weight {
137 // Error138 // Error
138 0139 0
139 }140 }
140141
141 fn set_token_properties(amount: u32) -> Weight {142 fn set_token_properties(_amount: u32) -> Weight {
142 // Error143 // Error
143 0144 0
144 }145 }
146
147 fn delete_token_properties(_amount: u32) -> Weight {
148 // Error
149 0
150 }
145151
146 fn set_property_permissions(amount: u32) -> Weight {152 fn set_property_permissions(_amount: u32) -> Weight {
147 // Error153 // Error
148 0154 0
149 }155 }
317 .saturating_add(RocksDbWeight::get().writes(6 as Weight))323 .saturating_add(RocksDbWeight::get().writes(6 as Weight))
318 }324 }
319325
320 fn set_collection_properties(amount: u32) -> Weight {326 fn set_collection_properties(_amount: u32) -> Weight {
321 // Error327 // Error
322 0328 0
323 }329 }
324330
325 fn set_token_properties(amount: u32) -> Weight {331 fn set_token_properties(_amount: u32) -> Weight {
326 // Error332 // Error
327 0333 0
328 }334 }
335
336 fn delete_token_properties(_amount: u32) -> Weight {
337 // Error
338 0
339 }
329340
330 fn set_property_permissions(amount: u32) -> Weight {341 fn set_property_permissions(_amount: u32) -> Weight {
331 // Error342 // Error
332 0343 0
333 }344 }
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, 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 }
725
726 #[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);
735
736 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
737
738 dispatch_call::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, properties))
739 }
725740
726 #[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]
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
720 Ok(())720 Ok(())
721 }721 }
722
723 pub fn remove_property(&mut self, key: &PropertyKey) {
724 let property = self.map.get(key);
725
726 if let Some(value) = property {
727 let value_len = value.len() as u32;
728
729 self.map.remove(key);
730 self.consumed_space -= value_len;
731 }
732 }
722733
723 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)
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
17#![cfg_attr(not(feature = "std"), no_std)]17#![cfg_attr(not(feature = "std"), no_std)]
1818
19use 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;
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
62 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))62 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
63 }63 }
64
65 fn delete_token_properties(amount: u32) -> Weight {
66 dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))
67 }
6468
65 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))