difftreelog
fix use OptionQuery for TokenProperties
in: master
9 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth172 fail!(<pallet_common::Error<T>>::UnsupportedOperation);172 fail!(<pallet_common::Error<T>>::UnsupportedOperation);173 }173 }174174175 fn get_token_properties_map(&self, _token_id: TokenId) -> up_data_structs::TokenProperties {175 fn get_token_properties_raw(176 &self,177 _token_id: TokenId,178 ) -> Option<up_data_structs::TokenProperties> {176 // No token properties are defined on fungibles179 // No token properties are defined on fungibles177 up_data_structs::TokenProperties::new()180 None178 }181 }179182180 fn set_token_properties_map(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {183 fn set_token_properties_raw(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {181 // No token properties are defined on fungibles184 // No token properties are defined on fungibles182 }185 }183184 fn properties_exist(&self, _token: TokenId) -> bool {185 // No token properties are defined on fungibles186 false187 }188186189 fn set_token_property_permissions(187 fn set_token_property_permissions(190 &self,188 &self,pallets/common/src/lib.rsdiffbeforeafterboth2098 /// Get token properties raw map.2098 /// Get token properties raw map.2099 ///2099 ///2100 /// * `token_id` - The token which properties are needed.2100 /// * `token_id` - The token which properties are needed.2101 fn get_token_properties_map(&self, token_id: TokenId) -> TokenProperties;2101 fn get_token_properties_raw(&self, token_id: TokenId) -> Option<TokenProperties>;210221022103 /// Set token properties raw map.2103 /// Set token properties raw map.2104 ///2104 ///2105 /// * `token_id` - The token for which the properties are being set.2105 /// * `token_id` - The token for which the properties are being set.2106 /// * `map` - The raw map containing the token's properties.2106 /// * `map` - The raw map containing the token's properties.2107 fn set_token_properties_map(&self, token_id: TokenId, map: TokenProperties);2107 fn set_token_properties_raw(&self, token_id: TokenId, map: TokenProperties);21082109 /// Whether the given token has properties.2110 ///2111 /// * `token_id` - The token in question.2112 fn properties_exist(&self, token: TokenId) -> bool;211321082114 /// Set token property permissions.2109 /// Set token property permissions.2115 ///2110 ///2590 <PalletEvm<T>>::deposit_log(log);2585 <PalletEvm<T>>::deposit_log(log);259125862592 self.collection2587 self.collection2593 .set_token_properties_map(token_id, stored_properties.into_inner());2588 .set_token_properties_raw(token_id, stored_properties.into_inner());2594 }2589 }259525902596 Ok(())2591 Ok(())2624 true2619 true2625 },2620 },2626 get_properties: |token_id| {2621 get_properties: |token_id| {2627 debug_assert!(!collection.properties_exist(token_id));2622 debug_assert!(collection.get_token_properties_raw(token_id).is_none());2628 TokenProperties::new()2623 TokenProperties::new()2629 },2624 },2630 _phantom: PhantomData,2625 _phantom: PhantomData,2686 is_collection_admin: LazyValue::new(|| collection.is_owner_or_admin(sender)),2681 is_collection_admin: LazyValue::new(|| collection.is_owner_or_admin(sender)),2687 property_permissions: LazyValue::new(|| <Pallet<T>>::property_permissions(collection.id)),2682 property_permissions: LazyValue::new(|| <Pallet<T>>::property_permissions(collection.id)),2688 check_token_exist: |token_id| collection.token_exists(token_id),2683 check_token_exist: |token_id| collection.token_exists(token_id),2689 get_properties: |token_id| collection.get_token_properties_map(token_id),2684 get_properties: |token_id| {2685 collection2686 .get_token_properties_raw(token_id)2687 .unwrap_or_default()2688 },2690 _phantom: PhantomData,2689 _phantom: PhantomData,2691 }2690 }2692}2691}pallets/fungible/src/common.rsdiffbeforeafterboth364 fail!(<Error<T>>::SettingPropertiesNotAllowed)364 fail!(<Error<T>>::SettingPropertiesNotAllowed)365 }365 }366366367 fn get_token_properties_map(&self, _token_id: TokenId) -> up_data_structs::TokenProperties {367 fn get_token_properties_raw(368 &self,369 _token_id: TokenId,370 ) -> Option<up_data_structs::TokenProperties> {368 // No token properties are defined on fungibles371 // No token properties are defined on fungibles369 up_data_structs::TokenProperties::new()372 None370 }373 }371374372 fn set_token_properties_map(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {375 fn set_token_properties_raw(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {373 // No token properties are defined on fungibles376 // No token properties are defined on fungibles374 }377 }375376 fn properties_exist(&self, _token: TokenId) -> bool {377 // No token properties are defined on fungibles378 false379 }380378381 fn check_nesting(379 fn check_nesting(382 &self,380 &self,pallets/nonfungible/src/common.rsdiffbeforeafterboth265 )265 )266 }266 }267267268 fn get_token_properties_map(&self, token_id: TokenId) -> up_data_structs::TokenProperties {268 fn get_token_properties_raw(269 &self,270 token_id: TokenId,271 ) -> Option<up_data_structs::TokenProperties> {269 <TokenProperties<T>>::get((self.id, token_id))272 <TokenProperties<T>>::get((self.id, token_id))270 }273 }271274272 fn set_token_properties_map(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {275 fn set_token_properties_raw(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {273 <TokenProperties<T>>::set((self.id, token_id), map)276 <TokenProperties<T>>::insert((self.id, token_id), map)274 }277 }275278276 fn set_token_property_permissions(279 fn set_token_property_permissions(287 )290 )288 }291 }289290 fn properties_exist(&self, token: TokenId) -> bool {291 <TokenProperties<T>>::contains_key((self.id, token))292 }293292294 fn burn_item(293 fn burn_item(295 &self,294 &self,482 }481 }483482484 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {483 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {485 <Pallet<T>>::token_properties((self.id, token_id))484 <Pallet<T>>::token_properties((self.id, token_id))?486 .get(key)485 .get(key)487 .cloned()486 .cloned()488 }487 }489488490 fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {489 fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {491 let properties = <Pallet<T>>::token_properties((self.id, token_id));490 let Some(properties) = <Pallet<T>>::token_properties((self.id, token_id)) else {491 return vec![];492 };492493493 keys.map(|keys| {494 keys.map(|keys| {494 keys.into_iter()495 keys.into_iter()pallets/nonfungible/src/erc.rsdiffbeforeafterboth273 .map_err(|_| "key too long")?;273 .map_err(|_| "key too long")?;274274275 let props = <TokenProperties<T>>::get((self.id, token_id));275 let props =276 <TokenProperties<T>>::get((self.id, token_id)).ok_or("Token properties not found")?;276 let prop = props.get(&key).ok_or("key not found")?;277 let prop = props.get(&key).ok_or("key not found")?;277278278 Ok(prop.to_vec().into())279 Ok(prop.to_vec().into())pallets/nonfungible/src/lib.rsdiffbeforeafterboth102use up_data_structs::{102use up_data_structs::{103 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,103 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,104 mapping::TokenAddressMapping, budget::Budget, Property, PropertyKey, PropertyValue,104 mapping::TokenAddressMapping, budget::Budget, Property, PropertyKey, PropertyValue,105 PropertyKeyPermission, PropertyScope, TrySetProperty, TokenChild, AuxPropertyValue,105 PropertyKeyPermission, PropertyScope, TokenChild, AuxPropertyValue, PropertiesPermissionMap,106 PropertiesPermissionMap, TokenProperties as TokenPropertiesT,106 TokenProperties as TokenPropertiesT,107};107};108use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};108use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};201 pub type TokenProperties<T: Config> = StorageNMap<201 pub type TokenProperties<T: Config> = StorageNMap<202 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),202 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),203 Value = TokenPropertiesT,203 Value = TokenPropertiesT,204 QueryKind = ValueQuery,204 QueryKind = OptionQuery,205 >;205 >;206206207 /// Custom data of a token that is serialized to bytes,207 /// Custom data of a token that is serialized to bytes,342 <TokenData<T>>::contains_key((collection.id, token))342 <TokenData<T>>::contains_key((collection.id, token))343 }343 }344345 /// Set the token property with the scope.346 ///347 /// - `property`: Contains key-value pair.348 pub fn set_scoped_token_property(349 collection_id: CollectionId,350 token_id: TokenId,351 scope: PropertyScope,352 property: Property,353 ) -> DispatchResult {354 TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {355 properties.try_scoped_set(scope, property.key, property.value)356 })357 .map_err(<CommonError<T>>::from)?;358359 Ok(())360 }361362 /// Batch operation to set multiple properties with the same scope.363 pub fn set_scoped_token_properties(364 collection_id: CollectionId,365 token_id: TokenId,366 scope: PropertyScope,367 properties: impl Iterator<Item = Property>,368 ) -> DispatchResult {369 TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {370 stored_properties.try_scoped_set_from_iter(scope, properties)371 })372 .map_err(<CommonError<T>>::from)?;373374 Ok(())375 }376344377 /// Add or edit auxiliary data for the property.345 /// Add or edit auxiliary data for the property.378 ///346 ///139413621395 pub fn repair_item(collection: &NonfungibleHandle<T>, token: TokenId) -> DispatchResult {1363 pub fn repair_item(collection: &NonfungibleHandle<T>, token: TokenId) -> DispatchResult {1396 <TokenProperties<T>>::mutate((collection.id, token), |properties| {1364 <TokenProperties<T>>::mutate((collection.id, token), |properties| {1365 if let Some(properties) = properties {1397 properties.recompute_consumed_space();1366 properties.recompute_consumed_space();1398 });1367 }1368 });139913691400 Ok(())1370 Ok(())pallets/refungible/src/common.rsdiffbeforeafterboth435 )435 )436 }436 }437437438 fn get_token_properties_map(&self, token_id: TokenId) -> up_data_structs::TokenProperties {438 fn get_token_properties_raw(439 &self,440 token_id: TokenId,441 ) -> Option<up_data_structs::TokenProperties> {439 <TokenProperties<T>>::get((self.id, token_id))442 <TokenProperties<T>>::get((self.id, token_id))440 }443 }441444442 fn set_token_properties_map(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {445 fn set_token_properties_raw(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {443 <TokenProperties<T>>::set((self.id, token_id), map)446 <TokenProperties<T>>::insert((self.id, token_id), map)444 }447 }445446 fn properties_exist(&self, token: TokenId) -> bool {447 <TokenProperties<T>>::contains_key((self.id, token))448 }449448450 fn check_nesting(449 fn check_nesting(451 &self,450 &self,514 }513 }515514516 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {515 fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {517 <Pallet<T>>::token_properties((self.id, token_id))516 <Pallet<T>>::token_properties((self.id, token_id))?518 .get(key)517 .get(key)519 .cloned()518 .cloned()520 }519 }521520522 fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {521 fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {523 let properties = <Pallet<T>>::token_properties((self.id, token_id));522 let Some(properties) = <Pallet<T>>::token_properties((self.id, token_id)) else {523 return vec![];524 };524525525 keys.map(|keys| {526 keys.map(|keys| {526 keys.into_iter()527 keys.into_iter()pallets/refungible/src/erc.rsdiffbeforeafterboth284 .map_err(|_| "key too long")?;284 .map_err(|_| "key too long")?;285285286 let props = <TokenProperties<T>>::get((self.id, token_id));286 let props =287 <TokenProperties<T>>::get((self.id, token_id)).ok_or("Token properties not found")?;287 let prop = props.get(&key).ok_or("key not found")?;288 let prop = props.get(&key).ok_or("key not found")?;288289289 Ok(prop.to_vec().into())290 Ok(prop.to_vec().into())pallets/refungible/src/lib.rsdiffbeforeafterboth106use up_data_structs::{106use up_data_structs::{107 AccessMode, budget::Budget, CollectionId, CreateCollectionData, mapping::TokenAddressMapping,107 AccessMode, budget::Budget, CollectionId, CreateCollectionData, mapping::TokenAddressMapping,108 MAX_REFUNGIBLE_PIECES, Property, PropertyKey, PropertyKeyPermission, PropertyScope,108 MAX_REFUNGIBLE_PIECES, Property, PropertyKey, PropertyKeyPermission, PropertyScope,109 PropertyValue, TokenId, TrySetProperty, PropertiesPermissionMap,109 PropertyValue, TokenId, PropertiesPermissionMap, CreateRefungibleExMultipleOwners,110 CreateRefungibleExMultipleOwners, TokenOwnerError, TokenProperties as TokenPropertiesT,110 TokenOwnerError, TokenProperties as TokenPropertiesT,111};111};112112175 pub type TokenProperties<T: Config> = StorageNMap<175 pub type TokenProperties<T: Config> = StorageNMap<176 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),176 Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),177 Value = TokenPropertiesT,177 Value = TokenPropertiesT,178 QueryKind = ValueQuery,178 QueryKind = OptionQuery,179 >;179 >;180180181 /// Total amount of pieces for token181 /// Total amount of pieces for token294 <TotalSupply<T>>::contains_key((collection.id, token))294 <TotalSupply<T>>::contains_key((collection.id, token))295 }295 }296297 pub fn set_scoped_token_property(298 collection_id: CollectionId,299 token_id: TokenId,300 scope: PropertyScope,301 property: Property,302 ) -> DispatchResult {303 TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {304 properties.try_scoped_set(scope, property.key, property.value)305 })306 .map_err(<CommonError<T>>::from)?;307308 Ok(())309 }310311 pub fn set_scoped_token_properties(312 collection_id: CollectionId,313 token_id: TokenId,314 scope: PropertyScope,315 properties: impl Iterator<Item = Property>,316 ) -> DispatchResult {317 TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {318 stored_properties.try_scoped_set_from_iter(scope, properties)319 })320 .map_err(<CommonError<T>>::from)?;321322 Ok(())323 }324}296}325297326// unchecked calls skips any permission checks298// unchecked calls skips any permission checks142613981427 pub fn repair_item(collection: &RefungibleHandle<T>, token: TokenId) -> DispatchResult {1399 pub fn repair_item(collection: &RefungibleHandle<T>, token: TokenId) -> DispatchResult {1428 <TokenProperties<T>>::mutate((collection.id, token), |properties| {1400 <TokenProperties<T>>::mutate((collection.id, token), |properties| {1401 if let Some(properties) = properties {1429 properties.recompute_consumed_space();1402 properties.recompute_consumed_space();1430 });1403 }1404 });143114051432 Ok(())1406 Ok(())