--- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -28,7 +28,7 @@ use up_data_structs::{ AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData, mapping::TokenAddressMapping, budget::Budget, Property, PropertyPermission, PropertyKey, - PropertyKeyPermission, Properties, PropertyScope, TrySetProperty, TokenChild, + PropertyKeyPermission, Properties, PropertyScope, TrySetProperty, TokenChild, SysPropertyValue, }; use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm}; use pallet_common::{ @@ -124,6 +124,19 @@ OnEmpty = up_data_structs::TokenProperties, >; + #[pallet::storage] + #[pallet::getter(fn token_sys_property)] + pub type TokenSysProperties = StorageNMap< + Key = ( + Key, + Key, + Key, + Key, + ), + Value = SysPropertyValue, + QueryKind = OptionQuery, + >; + /// Used to enumerate tokens owned by account #[pallet::storage] pub type Owned = StorageNMap< @@ -294,6 +307,33 @@ Ok(()) } + pub fn try_mutate_token_sys_property( + collection_id: CollectionId, + token_id: TokenId, + scope: PropertyScope, + key: PropertyKey, + f: impl FnOnce(&mut Option) -> Result, + ) -> Result { + >::try_mutate((collection_id, token_id, scope, key), f) + } + + pub fn remove_token_sys_property( + collection_id: CollectionId, + token_id: TokenId, + scope: PropertyScope, + key: PropertyKey, + ) { + >::remove((collection_id, token_id, scope, key)); + } + + pub fn iterate_token_sys_properties( + collection_id: CollectionId, + token_id: TokenId, + scope: PropertyScope, + ) -> impl Iterator { + >::iter_prefix((collection_id, token_id, scope)) + } + pub fn current_token_id(collection_id: CollectionId) -> TokenId { TokenId(>::get(collection_id)) } @@ -375,6 +415,7 @@ >::insert(collection.id, burnt); >::remove((collection.id, token)); >::remove((collection.id, token)); + >::remove_prefix((collection.id, token), None); let old_spender = >::take((collection.id, token)); if let Some(old_spender) = old_spender { --- 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>; -pub type PropertyValue = BoundedVec>; +pub type BoundedBytes = BoundedVec; + +pub type SysPropertyValue = BoundedBytes>; + +pub type PropertyKey = BoundedBytes>; +pub type PropertyValue = BoundedBytes>; #[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,