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

difftreelog

feat add token_sys_properties

Daniel Shiposha2022-06-15parent: #2115a19.patch.diff
in: master

2 files changed

modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
28use up_data_structs::{28use up_data_structs::{
29 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,29 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
30 mapping::TokenAddressMapping, budget::Budget, Property, PropertyPermission, PropertyKey,30 mapping::TokenAddressMapping, budget::Budget, Property, PropertyPermission, PropertyKey,
31 PropertyKeyPermission, Properties, PropertyScope, TrySetProperty, TokenChild,31 PropertyKeyPermission, Properties, PropertyScope, TrySetProperty, TokenChild, SysPropertyValue,
32};32};
33use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};33use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
34use pallet_common::{34use pallet_common::{
124 OnEmpty = up_data_structs::TokenProperties,124 OnEmpty = up_data_structs::TokenProperties,
125 >;125 >;
126
127 #[pallet::storage]
128 #[pallet::getter(fn token_sys_property)]
129 pub type TokenSysProperties<T: Config> = StorageNMap<
130 Key = (
131 Key<Twox64Concat, CollectionId>,
132 Key<Twox64Concat, TokenId>,
133 Key<Twox64Concat, PropertyScope>,
134 Key<Twox64Concat, PropertyKey>,
135 ),
136 Value = SysPropertyValue,
137 QueryKind = OptionQuery,
138 >;
126139
127 /// Used to enumerate tokens owned by account140 /// Used to enumerate tokens owned by account
128 #[pallet::storage]141 #[pallet::storage]
294 Ok(())307 Ok(())
295 }308 }
309
310 pub fn try_mutate_token_sys_property<R, E>(
311 collection_id: CollectionId,
312 token_id: TokenId,
313 scope: PropertyScope,
314 key: PropertyKey,
315 f: impl FnOnce(&mut Option<SysPropertyValue>) -> Result<R, E>,
316 ) -> Result<R, E> {
317 <TokenSysProperties<T>>::try_mutate((collection_id, token_id, scope, key), f)
318 }
319
320 pub fn remove_token_sys_property(
321 collection_id: CollectionId,
322 token_id: TokenId,
323 scope: PropertyScope,
324 key: PropertyKey,
325 ) {
326 <TokenSysProperties<T>>::remove((collection_id, token_id, scope, key));
327 }
328
329 pub fn iterate_token_sys_properties(
330 collection_id: CollectionId,
331 token_id: TokenId,
332 scope: PropertyScope,
333 ) -> impl Iterator<Item = (PropertyKey, SysPropertyValue)> {
334 <TokenSysProperties<T>>::iter_prefix((collection_id, token_id, scope))
335 }
296336
297 pub fn current_token_id(collection_id: CollectionId) -> TokenId {337 pub fn current_token_id(collection_id: CollectionId) -> TokenId {
298 TokenId(<TokensMinted<T>>::get(collection_id))338 TokenId(<TokensMinted<T>>::get(collection_id))
375 <TokensBurnt<T>>::insert(collection.id, burnt);415 <TokensBurnt<T>>::insert(collection.id, burnt);
376 <TokenData<T>>::remove((collection.id, token));416 <TokenData<T>>::remove((collection.id, token));
377 <TokenProperties<T>>::remove((collection.id, token));417 <TokenProperties<T>>::remove((collection.id, token));
418 <TokenSysProperties<T>>::remove_prefix((collection.id, token), None);
378 let old_spender = <Allowance<T>>::take((collection.id, token));419 let old_spender = <Allowance<T>>::take((collection.id, token));
379420
380 if let Some(old_spender) = old_spender {421 if let Some(old_spender) = old_spender {
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -104,6 +104,8 @@
 pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;
 pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;
 
+pub const MAX_SYSTEM_PROPERTY_VALUE_LENGTH: u32 = 2048;
+
 pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;
 pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;
 
@@ -654,8 +656,12 @@
 	}
 }
 
-pub type PropertyKey = BoundedVec<u8, ConstU32<MAX_PROPERTY_KEY_LENGTH>>;
-pub type PropertyValue = BoundedVec<u8, ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;
+pub type BoundedBytes<S> = BoundedVec<u8, S>;
+
+pub type SysPropertyValue = BoundedBytes<ConstU32<MAX_SYSTEM_PROPERTY_VALUE_LENGTH>>;
+
+pub type PropertyKey = BoundedBytes<ConstU32<MAX_PROPERTY_KEY_LENGTH>>;
+pub type PropertyValue = BoundedBytes<ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;
 
 #[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
@@ -715,7 +721,7 @@
 	EmptyPropertyKey,
 }
 
-#[derive(Clone, Copy)]
+#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq, Clone, Copy)]
 pub enum PropertyScope {
 	None,
 	Rmrk,