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
--- 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<T: Config> = StorageNMap<
+		Key = (
+			Key<Twox64Concat, CollectionId>,
+			Key<Twox64Concat, TokenId>,
+			Key<Twox64Concat, PropertyScope>,
+			Key<Twox64Concat, PropertyKey>,
+		),
+		Value = SysPropertyValue,
+		QueryKind = OptionQuery,
+	>;
+
 	/// Used to enumerate tokens owned by account
 	#[pallet::storage]
 	pub type Owned<T: Config> = StorageNMap<
@@ -294,6 +307,33 @@
 		Ok(())
 	}
 
+	pub fn try_mutate_token_sys_property<R, E>(
+		collection_id: CollectionId,
+		token_id: TokenId,
+		scope: PropertyScope,
+		key: PropertyKey,
+		f: impl FnOnce(&mut Option<SysPropertyValue>) -> Result<R, E>,
+	) -> Result<R, E> {
+		<TokenSysProperties<T>>::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,
+	) {
+		<TokenSysProperties<T>>::remove((collection_id, token_id, scope, key));
+	}
+
+	pub fn iterate_token_sys_properties(
+		collection_id: CollectionId,
+		token_id: TokenId,
+		scope: PropertyScope,
+	) -> impl Iterator<Item = (PropertyKey, SysPropertyValue)> {
+		<TokenSysProperties<T>>::iter_prefix((collection_id, token_id, scope))
+	}
+
 	pub fn current_token_id(collection_id: CollectionId) -> TokenId {
 		TokenId(<TokensMinted<T>>::get(collection_id))
 	}
@@ -375,6 +415,7 @@
 		<TokensBurnt<T>>::insert(collection.id, burnt);
 		<TokenData<T>>::remove((collection.id, token));
 		<TokenProperties<T>>::remove((collection.id, token));
+		<TokenSysProperties<T>>::remove_prefix((collection.id, token), None);
 		let old_spender = <Allowance<T>>::take((collection.id, token));
 
 		if let Some(old_spender) = old_spender {
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
104pub 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;
106
107pub const MAX_SYSTEM_PROPERTY_VALUE_LENGTH: u32 = 2048;
106108
107pub 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}
658
659pub type BoundedBytes<S> = BoundedVec<u8, S>;
660
661pub type SysPropertyValue = BoundedBytes<ConstU32<MAX_SYSTEM_PROPERTY_VALUE_LENGTH>>;
656662
657pub 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>>;
659665
660#[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}
717723
718#[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,