difftreelog
feat add token_sys_properties
in: master
2 files changed
pallets/nonfungible/src/lib.rsdiffbeforeafterboth28use 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 >;126127 #[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 >;126139127 /// Used to enumerate tokens owned by account140 /// Used to enumerate tokens owned by account128 #[pallet::storage]141 #[pallet::storage]294 Ok(())307 Ok(())295 }308 }309310 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 }319320 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 }328329 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 }296336297 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));379420380 if let Some(old_spender) = old_spender {421 if let Some(old_spender) = old_spender {primitives/data-structs/src/lib.rsdiffbeforeafterboth104pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;104pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;105pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;105pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;106107pub const MAX_SYSTEM_PROPERTY_VALUE_LENGTH: u32 = 2048;106108107pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;109pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;108pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;110pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;654 }656 }655}657}658659pub type BoundedBytes<S> = BoundedVec<u8, S>;660661pub type SysPropertyValue = BoundedBytes<ConstU32<MAX_SYSTEM_PROPERTY_VALUE_LENGTH>>;656662657pub type PropertyKey = BoundedVec<u8, ConstU32<MAX_PROPERTY_KEY_LENGTH>>;663pub type PropertyKey = BoundedBytes<ConstU32<MAX_PROPERTY_KEY_LENGTH>>;658pub type PropertyValue = BoundedVec<u8, ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;664pub type PropertyValue = BoundedBytes<ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;659665660#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]666#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]661#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]667#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]715 EmptyPropertyKey,721 EmptyPropertyKey,716}722}717723718#[derive(Clone, Copy)]724#[derive(Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq, Clone, Copy)]719pub enum PropertyScope {725pub enum PropertyScope {720 None,726 None,721 Rmrk,727 Rmrk,