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

difftreelog

Add first draft of Properties

Daniel Shiposha2022-04-29parent: #c01b00c.patch.diff
in: master

14 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -18,7 +18,7 @@
 
 use core::ops::{Deref, DerefMut};
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_std::vec::Vec;
+use sp_std::{vec::Vec, collections::btree_map::BTreeMap};
 use pallet_evm::account::CrossAccountId;
 use frame_support::{
 	dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},
@@ -35,7 +35,8 @@
 	FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT,
 	CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,
 	CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,
-	PhantomType,
+	PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
+	PropertiesError,
 };
 pub use pallet::*;
 use sp_core::H160;
@@ -288,6 +289,10 @@
 			T::CrossAccountId,
 			u128,
 		),
+
+		CollectionPropertySet(CollectionId, Property),
+
+		TokenPropertySet(CollectionId, TokenId, Property),
 	}
 
 	#[pallet::error]
@@ -319,7 +324,6 @@
 		CollectionLimitBoundsExceeded,
 		/// Tried to enable permissions which are only permitted to be disabled
 		OwnerPermissionsCantBeReverted,
-
 		/// Collection settings not allowing items transferring
 		TransferNotAllowed,
 		/// Account token limit exceeded per collection
@@ -372,6 +376,25 @@
 		QueryKind = OptionQuery,
 	>;
 
+	/// Collection properties
+	#[pallet::storage]
+	pub type CollectionProperties<T> = StorageMap<
+		Hasher = Blake2_128Concat,
+		Key = CollectionId,
+		Value = Properties,
+		QueryKind = ValueQuery,
+		OnEmpty = up_data_structs::CollectionProperties,
+	>;
+
+	#[pallet::storage]
+	#[pallet::getter(fn property_permission)]
+	pub type CollectionPropertyPermissions<T> = StorageMap<
+		Hasher = Blake2_128Concat,
+		Key = CollectionId,
+		Value = PropertiesPermissionMap,
+		QueryKind = ValueQuery,
+	>;
+
 	/// Large variable-size collection fields are extracted here
 	#[pallet::storage]
 	pub type CollectionData<T> = StorageNMap<
@@ -538,6 +561,7 @@
 			sponsorship,
 			limits,
 			meta_update_permission,
+			..
 		} = <CollectionById<T>>::get(collection)?;
 		Some(RpcCollection {
 			name: name.into_inner(),
@@ -615,8 +639,25 @@
 				.map(|limits| Self::clamp_limits(data.mode.clone(), &Default::default(), limits))
 				.unwrap_or_else(|| Ok(CollectionLimits::default()))?,
 			meta_update_permission: data.meta_update_permission.unwrap_or_default(),
+			// token_property_permissions: data.token_property_permissions.unwrap_or_default(),
+			// properties: Properties::from_collection_props_vec(data.properties)?
 		};
 
+		CollectionProperties::<T>::insert(
+			id,
+			Properties::from_collection_props_vec(data.properties)?,
+		);
+
+		let token_props_permissions: PropertiesPermissionMap = data
+			.token_property_permissions
+			.into_iter()
+			.map(|property| (property.key, property.permission))
+			.collect::<BTreeMap<_, _>>()
+			.try_into()
+			.map_err(|_| PropertiesError::PropertyLimitReached)?;
+
+		CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);
+
 		// Take a (non-refundable) deposit of collection creation
 		{
 			let mut imbalance =
@@ -688,6 +729,34 @@
 		Ok(())
 	}
 
+	pub fn change_collection_property(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		property: Property,
+	) -> DispatchResult {
+		collection.check_is_owner_or_admin(sender)?;
+
+		CollectionProperties::<T>::get(collection.id).try_change_property(property)?;
+
+		Ok(())
+	}
+
+	pub fn change_property_permission(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		property_key: PropertyKey,
+		permission: PropertyPermission,
+	) -> DispatchResult {
+		collection.check_is_owner_or_admin(sender)?;
+
+		CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {
+			permissions.try_insert(property_key, permission)
+		})
+		.map_err(|_| PropertiesError::PropertyLimitReached)?;
+
+		Ok(())
+	}
+
 	fn set_field_raw(
 		collection_id: CollectionId,
 		field: CollectionField,
@@ -840,6 +909,7 @@
 	fn create_multiple_items(amount: u32) -> Weight;
 	fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
 	fn burn_item() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -875,6 +945,19 @@
 		amount: u128,
 	) -> DispatchResultWithPostInfo;
 
+	fn change_collection_property(
+		&self,
+		sender: T::CrossAccountId,
+		property: Property,
+	) -> DispatchResultWithPostInfo;
+
+	fn change_token_property(
+		&self,
+		sender: T::CrossAccountId,
+		token_id: TokenId,
+		property: Property,
+	) -> DispatchResultWithPostInfo;
+
 	fn transfer(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -21,7 +21,7 @@
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::ArithmeticError;
 use sp_std::{vec::Vec, vec};
-use up_data_structs::CustomDataLimit;
+use up_data_structs::{CustomDataLimit, Property};
 
 use crate::{
 	Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
@@ -50,6 +50,10 @@
 		<SelfWeightOf<T>>::burn_item()
 	}
 
+	fn set_property() -> Weight {
+		<SelfWeightOf<T>>::set_property()
+	}
+
 	fn transfer() -> Weight {
 		<SelfWeightOf<T>>::transfer()
 	}
@@ -225,6 +229,23 @@
 		)
 	}
 
+	fn change_collection_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
+	fn change_token_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_token_id: TokenId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
 	fn set_variable_metadata(
 		&self,
 		_sender: T::CrossAccountId,
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -61,6 +61,8 @@
 		FungibleItemsDontHaveData,
 		/// Fungible token does not support nested
 		FungibleDisallowsNesting,
+		/// Item properties are not allowed
+		PropertiesNotAllowed,
 	}
 
 	#[pallet::config]
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -35,6 +35,7 @@
 	fn create_item() -> Weight;
 	fn create_multiple_items_ex(b: u32, ) -> Weight;
 	fn burn_item() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -69,6 +70,12 @@
 			.saturating_add(T::DbWeight::get().reads(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes(2 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Fungible Balance (r:2 w:2)
 	fn transfer() -> Weight {
 		(17_713_000 as Weight)
@@ -126,6 +133,12 @@
 			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Fungible Balance (r:2 w:2)
 	fn transfer() -> Weight {
 		(17_713_000 as Weight)
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -17,7 +17,9 @@
 use core::marker::PhantomData;
 
 use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
-use up_data_structs::{TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget};
+use up_data_structs::{
+	TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,
+};
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::DispatchError;
 use sp_std::vec::Vec;
@@ -48,6 +50,10 @@
 		<SelfWeightOf<T>>::burn_item()
 	}
 
+	fn set_property() -> Weight {
+		<SelfWeightOf<T>>::set_property()
+	}
+
 	fn transfer() -> Weight {
 		<SelfWeightOf<T>>::transfer()
 	}
@@ -235,6 +241,32 @@
 		}
 	}
 
+	fn change_collection_property(
+		&self,
+		sender: T::CrossAccountId,
+		property: Property,
+	) -> DispatchResultWithPostInfo {
+		// let token_id = None;
+		with_weight(
+			// <Pallet<T>>::change_property(self, &sender, token_id, property),
+			Ok(()),
+			<CommonWeights<T>>::set_property(),
+		)
+	}
+
+	fn change_token_property(
+		&self,
+		sender: T::CrossAccountId,
+		token_id: TokenId,
+		property: Property,
+	) -> DispatchResultWithPostInfo {
+		with_weight(
+			// <Pallet<T>>::change_property(self, &sender, Some(token_id), property),
+			Ok(()),
+			<CommonWeights<T>>::set_property(),
+		)
+	}
+
 	fn set_variable_metadata(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -20,7 +20,7 @@
 use frame_support::{BoundedVec, ensure, fail};
 use up_data_structs::{
 	AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
-	mapping::TokenAddressMapping, NestingRule, budget::Budget,
+	mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
 };
 use pallet_evm::account::CrossAccountId;
 use pallet_common::{
@@ -94,6 +94,14 @@
 		QueryKind = OptionQuery,
 	>;
 
+	#[pallet::storage]
+	pub type TokenProperties<T: Config> = StorageNMap<
+		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
+		Value = up_data_structs::Properties,
+		QueryKind = ValueQuery,
+		OnEmpty = up_data_structs::TokenProperties,
+	>;
+
 	/// Used to enumerate tokens owned by account
 	#[pallet::storage]
 	pub type Owned<T: Config> = StorageNMap<
@@ -246,6 +254,56 @@
 		Ok(())
 	}
 
+	pub fn change_token_property(
+		collection: &NonfungibleHandle<T>,
+		sender: &T::CrossAccountId,
+		token_id: TokenId,
+		property: Property,
+	) -> DispatchResult {
+		let permission = <PalletCommon<T>>::property_permission(collection.id)
+			.get(&property.key)
+			.map(|p| p.clone())
+			.unwrap_or(PropertyPermission::None);
+
+		let check_token_owner = || -> DispatchResult {
+			let token_data = <TokenData<T>>::get((collection.id, token_id))
+				.ok_or(<CommonError<T>>::TokenNotFound)?;
+
+			ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);
+
+			Ok(())
+		};
+
+		let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))
+			.get_property(&property.key)
+			.is_some();
+
+		match (permission, is_property_exists) {
+			(PropertyPermission::AdminConst, false) => {
+				collection.check_is_owner_or_admin(sender)?
+			}
+			(PropertyPermission::Admin, _) => collection.check_is_owner_or_admin(sender)?,
+			(PropertyPermission::ItemOwnerConst, false) => check_token_owner()?,
+			(PropertyPermission::ItemOwner, _) => check_token_owner()?,
+			(PropertyPermission::ItemOwnerOrAdmin, _) => {
+				check_token_owner().or(collection.check_is_owner_or_admin(sender))?;
+			}
+			_ => return Err(<CommonError<T>>::NoPermission.into()),
+		}
+
+		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
+			properties.try_change_property(property.clone())
+		})?;
+
+		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
+			collection.id,
+			token_id,
+			property,
+		));
+
+		Ok(())
+	}
+
 	pub fn transfer(
 		collection: &NonfungibleHandle<T>,
 		from: &T::CrossAccountId,
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -36,6 +36,7 @@
 	fn create_multiple_items(b: u32, ) -> Weight;
 	fn create_multiple_items_ex(b: u32, ) -> Weight;
 	fn burn_item() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -90,6 +91,12 @@
 			.saturating_add(T::DbWeight::get().reads(4 as Weight))
 			.saturating_add(T::DbWeight::get().writes(4 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// TODO calculate appropriate weight
+		50_000_000 as Weight
+	}
+
 	// Storage: Nonfungible TokenData (r:1 w:1)
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Allowance (r:1 w:0)
@@ -179,6 +186,12 @@
 			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// TODO calculate appropriate weight
+		50_000_000 as Weight
+	}
+
 	// Storage: Nonfungible TokenData (r:1 w:1)
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Allowance (r:1 w:0)
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -20,7 +20,7 @@
 use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};
 use up_data_structs::{
 	CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,
-	budget::Budget,
+	budget::Budget, Property,
 };
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::DispatchError;
@@ -66,6 +66,10 @@
 		max_weight_of!(burn_item_partial(), burn_item_fully())
 	}
 
+	fn set_property() -> Weight {
+		<SelfWeightOf<T>>::set_property()
+	}
+
 	fn transfer() -> Weight {
 		max_weight_of!(
 			transfer_normal(),
@@ -244,6 +248,23 @@
 		)
 	}
 
+	fn change_collection_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
+	fn change_token_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_token_id: TokenId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
 	fn set_variable_metadata(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -62,6 +62,8 @@
 		WrongRefungiblePieces,
 		/// Refungible token can't nest other tokens
 		RefungibleDisallowsNesting,
+		/// Item properties are not allowed
+		PropertiesNotAllowed,
 	}
 
 	#[pallet::config]
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -38,6 +38,7 @@
 	fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
 	fn burn_item_partial() -> Weight;
 	fn burn_item_fully() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer_normal() -> Weight;
 	fn transfer_creating() -> Weight;
 	fn transfer_removing() -> Weight;
@@ -129,6 +130,12 @@
 			.saturating_add(T::DbWeight::get().reads(4 as Weight))
 			.saturating_add(T::DbWeight::get().writes(6 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Refungible Balance (r:2 w:2)
 	fn transfer_normal() -> Weight {
 		(19_766_000 as Weight)
@@ -297,6 +304,12 @@
 			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Refungible Balance (r:2 w:2)
 	fn transfer_normal() -> Weight {
 		(19_766_000 as Weight)
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -39,7 +39,7 @@
 	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
 	AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,
 	SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,
-	CreateItemExData, budget, CollectionField,
+	CreateItemExData, budget, CollectionField, Property,
 };
 use pallet_evm::account::CrossAccountId;
 use pallet_common::{
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
before · primitives/data-structs/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::{20	convert::{TryFrom, TryInto},21	fmt,22};23use frame_support::{24	storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},25};2627#[cfg(feature = "serde")]28use serde::{Serialize, Deserialize};2930use sp_core::U256;31use sp_runtime::{ArithmeticError, sp_std::prelude::Vec};32use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};33use frame_support::{BoundedVec, traits::ConstU32};34use derivative::Derivative;35use scale_info::TypeInfo;3637mod bounded;38pub mod budget;39pub mod mapping;40mod migration;4142pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;43pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;44pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;4546pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {47	100_00048} else {49	1050};51pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {52	100_00053} else {54	1055};56pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {57	204858} else {59	1060};61pub const COLLECTION_ADMINS_LIMIT: u32 = 5;62pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;63pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {64	1_000_00065} else {66	1067};6869// Timeouts for item types in passed blocks70pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;71pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;72pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;7374pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;7576// Schema limits77pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;78pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;79pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;8081pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;82// u32::max is not const: OFFCHAIN_SCHEMA_LIMIT.max(VARIABLE_ON_CHAIN_SCHEMA_LIMIT).max(CONST_ON_CHAIN_SCHEMA_LIMIT);8384pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;85pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;86pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;8788/// How much items can be created per single89/// create_many call90pub const MAX_ITEMS_PER_BATCH: u32 = 200;9192pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;9394#[derive(95	Encode,96	Decode,97	PartialEq,98	Eq,99	PartialOrd,100	Ord,101	Clone,102	Copy,103	Debug,104	Default,105	TypeInfo,106	MaxEncodedLen,107)]108#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]109pub struct CollectionId(pub u32);110impl EncodeLike<u32> for CollectionId {}111impl EncodeLike<CollectionId> for u32 {}112113#[derive(114	Encode,115	Decode,116	PartialEq,117	Eq,118	PartialOrd,119	Ord,120	Clone,121	Copy,122	Debug,123	Default,124	TypeInfo,125	MaxEncodedLen,126)]127#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]128pub struct TokenId(pub u32);129impl EncodeLike<u32> for TokenId {}130impl EncodeLike<TokenId> for u32 {}131132impl TokenId {133	pub fn try_next(self) -> Result<TokenId, ArithmeticError> {134		self.0135			.checked_add(1)136			.ok_or(ArithmeticError::Overflow)137			.map(Self)138	}139}140141impl From<TokenId> for U256 {142	fn from(t: TokenId) -> Self {143		t.0.into()144	}145}146147impl TryFrom<U256> for TokenId {148	type Error = &'static str;149150	fn try_from(value: U256) -> Result<Self, Self::Error> {151		Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))152	}153}154155pub struct OverflowError;156impl From<OverflowError> for &'static str {157	fn from(_: OverflowError) -> Self {158		"overflow occured"159	}160}161162pub type DecimalPoints = u8;163164#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]165#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]166pub enum CollectionMode {167	NFT,168	// decimal points169	Fungible(DecimalPoints),170	ReFungible,171}172173impl CollectionMode {174	pub fn id(&self) -> u8 {175		match self {176			CollectionMode::NFT => 1,177			CollectionMode::Fungible(_) => 2,178			CollectionMode::ReFungible => 3,179		}180	}181}182183pub trait SponsoringResolve<AccountId, Call> {184	fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;185}186187#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]188#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]189pub enum AccessMode {190	Normal,191	AllowList,192}193impl Default for AccessMode {194	fn default() -> Self {195		Self::Normal196	}197}198199#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]200#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]201pub enum SchemaVersion {202	ImageURL,203	Unique,204}205impl Default for SchemaVersion {206	fn default() -> Self {207		Self::ImageURL208	}209}210211#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]212#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]213pub struct Ownership<AccountId> {214	pub owner: AccountId,215	pub fraction: u128,216}217218#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]219#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]220pub enum SponsorshipState<AccountId> {221	/// The fees are applied to the transaction sender222	Disabled,223	Unconfirmed(AccountId),224	/// Transactions are sponsored by specified account225	Confirmed(AccountId),226}227228impl<AccountId> SponsorshipState<AccountId> {229	pub fn sponsor(&self) -> Option<&AccountId> {230		match self {231			Self::Confirmed(sponsor) => Some(sponsor),232			_ => None,233		}234	}235236	pub fn pending_sponsor(&self) -> Option<&AccountId> {237		match self {238			Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),239			_ => None,240		}241	}242243	pub fn confirmed(&self) -> bool {244		matches!(self, Self::Confirmed(_))245	}246}247248impl<T> Default for SponsorshipState<T> {249	fn default() -> Self {250		Self::Disabled251	}252}253254/// Used in storage255#[struct_versioning::versioned(version = 2, upper)]256#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]257pub struct Collection<AccountId> {258	pub owner: AccountId,259	pub mode: CollectionMode,260	pub access: AccessMode,261	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,262	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,263	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,264	pub mint_mode: bool,265266	#[version(..2)]267	pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,268269	pub schema_version: SchemaVersion,270	pub sponsorship: SponsorshipState<AccountId>,271272	#[version(..2)]273	pub limits: CollectionLimitsVersion1, // Collection private restrictions274	#[version(2.., upper(limits.into()))]275	pub limits: CollectionLimitsVersion2,276277	#[version(..2)]278	pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,279	#[version(..2)]280	pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,281282	pub meta_update_permission: MetaUpdatePermission,283}284285/// Used in RPC calls286#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]287#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]288pub struct RpcCollection<AccountId> {289	pub owner: AccountId,290	pub mode: CollectionMode,291	pub access: AccessMode,292	pub name: Vec<u16>,293	pub description: Vec<u16>,294	pub token_prefix: Vec<u8>,295	pub mint_mode: bool,296	pub offchain_schema: Vec<u8>,297	pub schema_version: SchemaVersion,298	pub sponsorship: SponsorshipState<AccountId>,299	pub limits: CollectionLimits,300	pub variable_on_chain_schema: Vec<u8>,301	pub const_on_chain_schema: Vec<u8>,302	pub meta_update_permission: MetaUpdatePermission,303}304305#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]306#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]307pub enum CollectionField {308	VariableOnChainSchema,309	ConstOnChainSchema,310	OffchainSchema,311}312313#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Debug, Derivative, MaxEncodedLen)]314#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]315#[derivative(Default(bound = ""))]316pub struct CreateCollectionData<AccountId> {317	#[derivative(Default(value = "CollectionMode::NFT"))]318	pub mode: CollectionMode,319	pub access: Option<AccessMode>,320	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]321	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,322	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]323	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,324	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]325	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,326	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]327	pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,328	pub schema_version: Option<SchemaVersion>,329	pub pending_sponsor: Option<AccountId>,330	pub limits: Option<CollectionLimits>,331	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]332	pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,333	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]334	pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,335	pub meta_update_permission: Option<MetaUpdatePermission>,336}337338#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]339#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]340pub struct NftItemType<AccountId> {341	pub owner: AccountId,342	pub const_data: Vec<u8>,343	pub variable_data: Vec<u8>,344}345346#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]347#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]348pub struct FungibleItemType {349	pub value: u128,350}351352#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]353#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]354pub struct ReFungibleItemType<AccountId> {355	pub owner: Vec<Ownership<AccountId>>,356	pub const_data: Vec<u8>,357	pub variable_data: Vec<u8>,358}359360/// All fields are wrapped in `Option`s, where None means chain default361#[struct_versioning::versioned(version = 2, upper)]362#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]363#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]364pub struct CollectionLimits {365	pub account_token_ownership_limit: Option<u32>,366	pub sponsored_data_size: Option<u32>,367	/// None - setVariableMetadata is not sponsored368	/// Some(v) - setVariableMetadata is sponsored369	///           if there is v block between txs370	pub sponsored_data_rate_limit: Option<SponsoringRateLimit>,371	pub token_limit: Option<u32>,372373	// Timeouts for item types in passed blocks374	pub sponsor_transfer_timeout: Option<u32>,375	pub sponsor_approve_timeout: Option<u32>,376	pub owner_can_transfer: Option<bool>,377	pub owner_can_destroy: Option<bool>,378	pub transfers_enabled: Option<bool>,379380	#[version(2.., upper(None))]381	pub nesting_rule: Option<NestingRule>,382}383384impl CollectionLimits {385	pub fn account_token_ownership_limit(&self) -> u32 {386		self.account_token_ownership_limit387			.unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)388			.min(MAX_TOKEN_OWNERSHIP)389	}390	pub fn sponsored_data_size(&self) -> u32 {391		self.sponsored_data_size392			.unwrap_or(CUSTOM_DATA_LIMIT)393			.min(CUSTOM_DATA_LIMIT)394	}395	pub fn token_limit(&self) -> u32 {396		self.token_limit397			.unwrap_or(COLLECTION_TOKEN_LIMIT)398			.min(COLLECTION_TOKEN_LIMIT)399	}400	pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {401		self.sponsor_transfer_timeout402			.unwrap_or(default)403			.min(MAX_SPONSOR_TIMEOUT)404	}405	pub fn sponsor_approve_timeout(&self) -> u32 {406		self.sponsor_approve_timeout407			.unwrap_or(SPONSOR_APPROVE_TIMEOUT)408			.min(MAX_SPONSOR_TIMEOUT)409	}410	pub fn owner_can_transfer(&self) -> bool {411		self.owner_can_transfer.unwrap_or(true)412	}413	pub fn owner_can_destroy(&self) -> bool {414		self.owner_can_destroy.unwrap_or(true)415	}416	pub fn transfers_enabled(&self) -> bool {417		self.transfers_enabled.unwrap_or(true)418	}419	pub fn sponsored_data_rate_limit(&self) -> Option<u32> {420		match self421			.sponsored_data_rate_limit422			.unwrap_or(SponsoringRateLimit::SponsoringDisabled)423		{424			SponsoringRateLimit::SponsoringDisabled => None,425			SponsoringRateLimit::Blocks(v) => Some(v.min(MAX_SPONSOR_TIMEOUT)),426		}427	}428	pub fn nesting_rule(&self) -> &NestingRule {429		static DEFAULT: NestingRule = NestingRule::Owner;430		self.nesting_rule.as_ref().unwrap_or(&DEFAULT)431	}432}433434#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen, Derivative)]435#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]436#[derivative(Debug)]437pub enum NestingRule {438	/// No one can nest tokens439	Disabled,440	/// Owner can nest any tokens441	Owner,442	/// Owner can nest tokens from specified collections443	OwnerRestricted(444		#[cfg_attr(feature = "serde1", serde(with = "bounded::set_serde"))]445		#[derivative(Debug(format_with = "bounded::set_debug"))]446		BoundedBTreeSet<CollectionId, ConstU32<16>>,447	),448}449450#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]451#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]452pub enum SponsoringRateLimit {453	SponsoringDisabled,454	Blocks(u32),455}456457#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]458#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]459#[derivative(Debug)]460pub struct CreateNftData {461	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]462	#[derivative(Debug(format_with = "bounded::vec_debug"))]463	pub const_data: BoundedVec<u8, CustomDataLimit>,464	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]465	#[derivative(Debug(format_with = "bounded::vec_debug"))]466	pub variable_data: BoundedVec<u8, CustomDataLimit>,467}468469#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]470#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]471pub struct CreateFungibleData {472	pub value: u128,473}474475#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]476#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]477#[derivative(Debug)]478pub struct CreateReFungibleData {479	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]480	#[derivative(Debug(format_with = "bounded::vec_debug"))]481	pub const_data: BoundedVec<u8, CustomDataLimit>,482	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]483	#[derivative(Debug(format_with = "bounded::vec_debug"))]484	pub variable_data: BoundedVec<u8, CustomDataLimit>,485	pub pieces: u128,486}487488#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]489#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]490pub enum MetaUpdatePermission {491	ItemOwner,492	Admin,493	None,494}495496impl Default for MetaUpdatePermission {497	fn default() -> Self {498		Self::ItemOwner499	}500}501502#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]503#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]504pub enum CreateItemData {505	NFT(CreateNftData),506	Fungible(CreateFungibleData),507	ReFungible(CreateReFungibleData),508}509510#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]511#[derivative(Debug)]512pub struct CreateNftExData<CrossAccountId> {513	#[derivative(Debug(format_with = "bounded::vec_debug"))]514	pub const_data: BoundedVec<u8, CustomDataLimit>,515	#[derivative(Debug(format_with = "bounded::vec_debug"))]516	pub variable_data: BoundedVec<u8, CustomDataLimit>,517	pub owner: CrossAccountId,518}519520#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]521#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]522pub struct CreateRefungibleExData<CrossAccountId> {523	#[derivative(Debug(format_with = "bounded::vec_debug"))]524	pub const_data: BoundedVec<u8, CustomDataLimit>,525	#[derivative(Debug(format_with = "bounded::vec_debug"))]526	pub variable_data: BoundedVec<u8, CustomDataLimit>,527	#[derivative(Debug(format_with = "bounded::map_debug"))]528	pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,529}530531#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]532#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]533pub enum CreateItemExData<CrossAccountId> {534	NFT(535		#[derivative(Debug(format_with = "bounded::vec_debug"))]536		BoundedVec<CreateNftExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,537	),538	Fungible(539		#[derivative(Debug(format_with = "bounded::map_debug"))]540		BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,541	),542	/// Many tokens, each may have only one owner543	RefungibleMultipleItems(544		#[derivative(Debug(format_with = "bounded::vec_debug"))]545		BoundedVec<CreateRefungibleExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,546	),547	/// Single token, which may have many owners548	RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),549}550551impl CreateItemData {552	pub fn data_size(&self) -> usize {553		match self {554			CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),555			CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),556			_ => 0,557		}558	}559}560561impl From<CreateNftData> for CreateItemData {562	fn from(item: CreateNftData) -> Self {563		CreateItemData::NFT(item)564	}565}566567impl From<CreateReFungibleData> for CreateItemData {568	fn from(item: CreateReFungibleData) -> Self {569		CreateItemData::ReFungible(item)570	}571}572573impl From<CreateFungibleData> for CreateItemData {574	fn from(item: CreateFungibleData) -> Self {575		CreateItemData::Fungible(item)576	}577}578579#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]580#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]581pub struct CollectionStats {582	pub created: u32,583	pub destroyed: u32,584	pub alive: u32,585}586587#[derive(Encode, Decode, PartialEq, Clone, Debug)]588pub struct PhantomType<T>(core::marker::PhantomData<T>);589590impl<T: TypeInfo + 'static> TypeInfo for PhantomType<T> {591	type Identity = PhantomType<T>;592593	fn type_info() -> scale_info::Type {594		use scale_info::{595			Type, Path,596			build::{FieldsBuilder, UnnamedFields},597			type_params,598		};599		Type::builder()600			.path(Path::new("up_data_structs", "PhantomType"))601			.type_params(type_params!(T))602			.composite(<FieldsBuilder<UnnamedFields>>::default().field(|b| b.ty::<[T; 0]>()))603	}604}605impl<T> MaxEncodedLen for PhantomType<T> {606	fn max_encoded_len() -> usize {607		0608	}609}
after · primitives/data-structs/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::{20	convert::{TryFrom, TryInto},21	fmt,22};23use frame_support::{24	storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},25	traits::Get,26};2728#[cfg(feature = "serde")]29use serde::{Serialize, Deserialize};3031use sp_core::U256;32use sp_runtime::{ArithmeticError, sp_std::prelude::Vec, DispatchError};33use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};34use frame_support::{BoundedVec, traits::ConstU32};35use derivative::Derivative;36use scale_info::TypeInfo;3738mod bounded;39pub mod budget;40pub mod mapping;41mod migration;4243pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;44pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;45pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;4647pub const MAX_TOKEN_OWNERSHIP: u32 = if cfg!(not(feature = "limit-testing")) {48	100_00049} else {50	1051};52pub const COLLECTION_NUMBER_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {53	100_00054} else {55	1056};57pub const CUSTOM_DATA_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {58	204859} else {60	1061};62pub const COLLECTION_ADMINS_LIMIT: u32 = 5;63pub const COLLECTION_TOKEN_LIMIT: u32 = u32::MAX;64pub const ACCOUNT_TOKEN_OWNERSHIP_LIMIT: u32 = if cfg!(not(feature = "limit-testing")) {65	1_000_00066} else {67	1068};6970// Timeouts for item types in passed blocks71pub const NFT_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;72pub const FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;73pub const REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT: u32 = 5;7475pub const SPONSOR_APPROVE_TIMEOUT: u32 = 5;7677// Schema limits78pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;79pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;80pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;8182pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;83// u32::max is not const: OFFCHAIN_SCHEMA_LIMIT.max(VARIABLE_ON_CHAIN_SCHEMA_LIMIT).max(CONST_ON_CHAIN_SCHEMA_LIMIT);8485pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;86pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;87pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;8889pub const MAX_PROPERTY_KEY_LENGTH: u32 = 256;90pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;91pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;9293// pub const MAX_PROPERTY_KEYS_OVERALL_LENGTH: u32 = MAX_PROPERTY_KEY_LENGTH * MAX_PROPERTIES_PER_ITEM;94pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;95pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;9697pub const MAX_COLLECTION_PROPERTIES_ENCODE_LEN: u32 =98	MAX_PROPERTIES_PER_ITEM * MAX_PROPERTY_KEY_LENGTH + MAX_COLLECTION_PROPERTIES_SIZE;99100pub struct MaxPropertiesPermissionsEncodeLen;101102impl Get<u32> for MaxPropertiesPermissionsEncodeLen {103	fn get() -> u32 {104		MAX_PROPERTIES_PER_ITEM * MAX_PROPERTY_KEY_LENGTH105			+ <PropertyPermission as MaxEncodedLen>::max_encoded_len() as u32106	}107}108109/// How much items can be created per single110/// create_many call111pub const MAX_ITEMS_PER_BATCH: u32 = 200;112113pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;114115#[derive(116	Encode,117	Decode,118	PartialEq,119	Eq,120	PartialOrd,121	Ord,122	Clone,123	Copy,124	Debug,125	Default,126	TypeInfo,127	MaxEncodedLen,128)]129#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]130pub struct CollectionId(pub u32);131impl EncodeLike<u32> for CollectionId {}132impl EncodeLike<CollectionId> for u32 {}133134#[derive(135	Encode,136	Decode,137	PartialEq,138	Eq,139	PartialOrd,140	Ord,141	Clone,142	Copy,143	Debug,144	Default,145	TypeInfo,146	MaxEncodedLen,147)]148#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]149pub struct TokenId(pub u32);150impl EncodeLike<u32> for TokenId {}151impl EncodeLike<TokenId> for u32 {}152153impl TokenId {154	pub fn try_next(self) -> Result<TokenId, ArithmeticError> {155		self.0156			.checked_add(1)157			.ok_or(ArithmeticError::Overflow)158			.map(Self)159	}160}161162impl From<TokenId> for U256 {163	fn from(t: TokenId) -> Self {164		t.0.into()165	}166}167168impl TryFrom<U256> for TokenId {169	type Error = &'static str;170171	fn try_from(value: U256) -> Result<Self, Self::Error> {172		Ok(TokenId(value.try_into().map_err(|_| "too large token id")?))173	}174}175176pub struct OverflowError;177impl From<OverflowError> for &'static str {178	fn from(_: OverflowError) -> Self {179		"overflow occured"180	}181}182183pub type DecimalPoints = u8;184185#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]186#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]187pub enum CollectionMode {188	NFT,189	// decimal points190	Fungible(DecimalPoints),191	ReFungible,192}193194impl CollectionMode {195	pub fn id(&self) -> u8 {196		match self {197			CollectionMode::NFT => 1,198			CollectionMode::Fungible(_) => 2,199			CollectionMode::ReFungible => 3,200		}201	}202}203204pub trait SponsoringResolve<AccountId, Call> {205	fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>;206}207208#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]209#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]210pub enum AccessMode {211	Normal,212	AllowList,213}214impl Default for AccessMode {215	fn default() -> Self {216		Self::Normal217	}218}219220#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]221#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]222pub enum SchemaVersion {223	ImageURL,224	Unique,225}226impl Default for SchemaVersion {227	fn default() -> Self {228		Self::ImageURL229	}230}231232#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]233#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]234pub struct Ownership<AccountId> {235	pub owner: AccountId,236	pub fraction: u128,237}238239#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]240#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]241pub enum SponsorshipState<AccountId> {242	/// The fees are applied to the transaction sender243	Disabled,244	Unconfirmed(AccountId),245	/// Transactions are sponsored by specified account246	Confirmed(AccountId),247}248249impl<AccountId> SponsorshipState<AccountId> {250	pub fn sponsor(&self) -> Option<&AccountId> {251		match self {252			Self::Confirmed(sponsor) => Some(sponsor),253			_ => None,254		}255	}256257	pub fn pending_sponsor(&self) -> Option<&AccountId> {258		match self {259			Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),260			_ => None,261		}262	}263264	pub fn confirmed(&self) -> bool {265		matches!(self, Self::Confirmed(_))266	}267}268269impl<T> Default for SponsorshipState<T> {270	fn default() -> Self {271		Self::Disabled272	}273}274275/// Used in storage276#[struct_versioning::versioned(version = 2, upper)]277#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]278pub struct Collection<AccountId> {279	pub owner: AccountId,280	pub mode: CollectionMode,281	pub access: AccessMode,282	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,283	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,284	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,285	pub mint_mode: bool,286287	#[version(..2)]288	pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,289290	pub schema_version: SchemaVersion,291	pub sponsorship: SponsorshipState<AccountId>,292293	#[version(..2)]294	pub limits: CollectionLimitsVersion1, // Collection private restrictions295	#[version(2.., upper(limits.into()))]296	pub limits: CollectionLimitsVersion2,297298	#[version(..2)]299	pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,300	#[version(..2)]301	pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,302303	pub meta_update_permission: MetaUpdatePermission,304}305306/// Used in RPC calls307#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]308#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]309pub struct RpcCollection<AccountId> {310	pub owner: AccountId,311	pub mode: CollectionMode,312	pub access: AccessMode,313	pub name: Vec<u16>,314	pub description: Vec<u16>,315	pub token_prefix: Vec<u8>,316	pub mint_mode: bool,317	pub offchain_schema: Vec<u8>,318	pub schema_version: SchemaVersion,319	pub sponsorship: SponsorshipState<AccountId>,320	pub limits: CollectionLimits,321	pub variable_on_chain_schema: Vec<u8>,322	pub const_on_chain_schema: Vec<u8>,323	pub meta_update_permission: MetaUpdatePermission,324}325326#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]327#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]328pub enum CollectionField {329	VariableOnChainSchema,330	ConstOnChainSchema,331	OffchainSchema,332}333334#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Derivative, MaxEncodedLen)]335#[derivative(Debug, Default(bound = ""))]336pub struct CreateCollectionData<AccountId> {337	#[derivative(Default(value = "CollectionMode::NFT"))]338	pub mode: CollectionMode,339	pub access: Option<AccessMode>,340	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,341	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,342	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,343	pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,344	pub schema_version: Option<SchemaVersion>,345	pub pending_sponsor: Option<AccountId>,346	pub limits: Option<CollectionLimits>,347	pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,348	pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,349	pub meta_update_permission: Option<MetaUpdatePermission>,350	pub token_property_permissions: CollectionPropertiesPermissionsVec,351	pub properties: CollectionPropertiesVec,352}353354pub type CollectionPropertiesPermissionsVec =355	BoundedVec<PropertyKeyPermission, MaxPropertiesPermissionsEncodeLen>;356357pub type CollectionPropertiesVec =358	BoundedVec<Property, ConstU32<MAX_COLLECTION_PROPERTIES_ENCODE_LEN>>;359360#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]361#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]362pub struct NftItemType<AccountId> {363	pub owner: AccountId,364	pub const_data: Vec<u8>,365	pub variable_data: Vec<u8>,366}367368#[derive(Encode, Decode, Default, Debug, Clone, PartialEq, TypeInfo)]369#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]370pub struct FungibleItemType {371	pub value: u128,372}373374#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]375#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]376pub struct ReFungibleItemType<AccountId> {377	pub owner: Vec<Ownership<AccountId>>,378	pub const_data: Vec<u8>,379	pub variable_data: Vec<u8>,380}381382/// All fields are wrapped in `Option`s, where None means chain default383#[struct_versioning::versioned(version = 2, upper)]384#[derive(Encode, Decode, Debug, Default, Clone, PartialEq, TypeInfo, MaxEncodedLen)]385#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]386pub struct CollectionLimits {387	pub account_token_ownership_limit: Option<u32>,388	pub sponsored_data_size: Option<u32>,389	/// None - setVariableMetadata is not sponsored390	/// Some(v) - setVariableMetadata is sponsored391	///           if there is v block between txs392	pub sponsored_data_rate_limit: Option<SponsoringRateLimit>,393	pub token_limit: Option<u32>,394395	// Timeouts for item types in passed blocks396	pub sponsor_transfer_timeout: Option<u32>,397	pub sponsor_approve_timeout: Option<u32>,398	pub owner_can_transfer: Option<bool>,399	pub owner_can_destroy: Option<bool>,400	pub transfers_enabled: Option<bool>,401402	#[version(2.., upper(None))]403	pub nesting_rule: Option<NestingRule>,404}405406impl CollectionLimits {407	pub fn account_token_ownership_limit(&self) -> u32 {408		self.account_token_ownership_limit409			.unwrap_or(ACCOUNT_TOKEN_OWNERSHIP_LIMIT)410			.min(MAX_TOKEN_OWNERSHIP)411	}412	pub fn sponsored_data_size(&self) -> u32 {413		self.sponsored_data_size414			.unwrap_or(CUSTOM_DATA_LIMIT)415			.min(CUSTOM_DATA_LIMIT)416	}417	pub fn token_limit(&self) -> u32 {418		self.token_limit419			.unwrap_or(COLLECTION_TOKEN_LIMIT)420			.min(COLLECTION_TOKEN_LIMIT)421	}422	pub fn sponsor_transfer_timeout(&self, default: u32) -> u32 {423		self.sponsor_transfer_timeout424			.unwrap_or(default)425			.min(MAX_SPONSOR_TIMEOUT)426	}427	pub fn sponsor_approve_timeout(&self) -> u32 {428		self.sponsor_approve_timeout429			.unwrap_or(SPONSOR_APPROVE_TIMEOUT)430			.min(MAX_SPONSOR_TIMEOUT)431	}432	pub fn owner_can_transfer(&self) -> bool {433		self.owner_can_transfer.unwrap_or(true)434	}435	pub fn owner_can_destroy(&self) -> bool {436		self.owner_can_destroy.unwrap_or(true)437	}438	pub fn transfers_enabled(&self) -> bool {439		self.transfers_enabled.unwrap_or(true)440	}441	pub fn sponsored_data_rate_limit(&self) -> Option<u32> {442		match self443			.sponsored_data_rate_limit444			.unwrap_or(SponsoringRateLimit::SponsoringDisabled)445		{446			SponsoringRateLimit::SponsoringDisabled => None,447			SponsoringRateLimit::Blocks(v) => Some(v.min(MAX_SPONSOR_TIMEOUT)),448		}449	}450	pub fn nesting_rule(&self) -> &NestingRule {451		static DEFAULT: NestingRule = NestingRule::Owner;452		self.nesting_rule.as_ref().unwrap_or(&DEFAULT)453	}454}455456#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen, Derivative)]457#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]458#[derivative(Debug)]459pub enum NestingRule {460	/// No one can nest tokens461	Disabled,462	/// Owner can nest any tokens463	Owner,464	/// Owner can nest tokens from specified collections465	OwnerRestricted(466		#[cfg_attr(feature = "serde1", serde(with = "bounded::set_serde"))]467		#[derivative(Debug(format_with = "bounded::set_debug"))]468		BoundedBTreeSet<CollectionId, ConstU32<16>>,469	),470}471472#[derive(Encode, Decode, Debug, Clone, Copy, PartialEq, TypeInfo, MaxEncodedLen)]473#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]474pub enum SponsoringRateLimit {475	SponsoringDisabled,476	Blocks(u32),477}478479#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]480#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]481#[derivative(Debug)]482pub struct CreateNftData {483	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]484	#[derivative(Debug(format_with = "bounded::vec_debug"))]485	pub const_data: BoundedVec<u8, CustomDataLimit>,486	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]487	#[derivative(Debug(format_with = "bounded::vec_debug"))]488	pub variable_data: BoundedVec<u8, CustomDataLimit>,489}490491#[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq, TypeInfo)]492#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]493pub struct CreateFungibleData {494	pub value: u128,495}496497#[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]498#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]499#[derivative(Debug)]500pub struct CreateReFungibleData {501	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]502	#[derivative(Debug(format_with = "bounded::vec_debug"))]503	pub const_data: BoundedVec<u8, CustomDataLimit>,504	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]505	#[derivative(Debug(format_with = "bounded::vec_debug"))]506	pub variable_data: BoundedVec<u8, CustomDataLimit>,507	pub pieces: u128,508}509510#[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo, MaxEncodedLen)]511#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]512pub enum MetaUpdatePermission {513	ItemOwner,514	Admin,515	None,516}517518impl Default for MetaUpdatePermission {519	fn default() -> Self {520		Self::ItemOwner521	}522}523524#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]525#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]526pub enum CreateItemData {527	NFT(CreateNftData),528	Fungible(CreateFungibleData),529	ReFungible(CreateReFungibleData),530}531532#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]533#[derivative(Debug)]534pub struct CreateNftExData<CrossAccountId> {535	#[derivative(Debug(format_with = "bounded::vec_debug"))]536	pub const_data: BoundedVec<u8, CustomDataLimit>,537	#[derivative(Debug(format_with = "bounded::vec_debug"))]538	pub variable_data: BoundedVec<u8, CustomDataLimit>,539	pub owner: CrossAccountId,540}541542#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]543#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]544pub struct CreateRefungibleExData<CrossAccountId> {545	#[derivative(Debug(format_with = "bounded::vec_debug"))]546	pub const_data: BoundedVec<u8, CustomDataLimit>,547	#[derivative(Debug(format_with = "bounded::vec_debug"))]548	pub variable_data: BoundedVec<u8, CustomDataLimit>,549	#[derivative(Debug(format_with = "bounded::map_debug"))]550	pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,551}552553#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]554#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]555pub enum CreateItemExData<CrossAccountId> {556	NFT(557		#[derivative(Debug(format_with = "bounded::vec_debug"))]558		BoundedVec<CreateNftExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,559	),560	Fungible(561		#[derivative(Debug(format_with = "bounded::map_debug"))]562		BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,563	),564	/// Many tokens, each may have only one owner565	RefungibleMultipleItems(566		#[derivative(Debug(format_with = "bounded::vec_debug"))]567		BoundedVec<CreateRefungibleExData<CrossAccountId>, ConstU32<MAX_ITEMS_PER_BATCH>>,568	),569	/// Single token, which may have many owners570	RefungibleMultipleOwners(CreateRefungibleExData<CrossAccountId>),571}572573impl CreateItemData {574	pub fn data_size(&self) -> usize {575		match self {576			CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),577			CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),578			_ => 0,579		}580	}581}582583impl From<CreateNftData> for CreateItemData {584	fn from(item: CreateNftData) -> Self {585		CreateItemData::NFT(item)586	}587}588589impl From<CreateReFungibleData> for CreateItemData {590	fn from(item: CreateReFungibleData) -> Self {591		CreateItemData::ReFungible(item)592	}593}594595impl From<CreateFungibleData> for CreateItemData {596	fn from(item: CreateFungibleData) -> Self {597		CreateItemData::Fungible(item)598	}599}600601#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]602#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]603pub struct CollectionStats {604	pub created: u32,605	pub destroyed: u32,606	pub alive: u32,607}608609#[derive(Encode, Decode, PartialEq, Clone, Debug)]610pub struct PhantomType<T>(core::marker::PhantomData<T>);611612impl<T: TypeInfo + 'static> TypeInfo for PhantomType<T> {613	type Identity = PhantomType<T>;614615	fn type_info() -> scale_info::Type {616		use scale_info::{617			Type, Path,618			build::{FieldsBuilder, UnnamedFields},619			type_params,620		};621		Type::builder()622			.path(Path::new("up_data_structs", "PhantomType"))623			.type_params(type_params!(T))624			.composite(<FieldsBuilder<UnnamedFields>>::default().field(|b| b.ty::<[T; 0]>()))625	}626}627impl<T> MaxEncodedLen for PhantomType<T> {628	fn max_encoded_len() -> usize {629		0630	}631}632633pub type PropertyKey = BoundedVec<u8, ConstU32<MAX_PROPERTY_KEY_LENGTH>>;634pub type PropertyValue = BoundedVec<u8, ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;635636#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]637pub enum PropertyPermission {638	None,639	AdminConst,640	Admin,641	ItemOwnerConst,642	ItemOwner,643	ItemOwnerOrAdmin,644}645646#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, MaxEncodedLen)]647pub struct Property {648	pub key: PropertyKey,649	pub value: PropertyValue,650}651652#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]653pub struct PropertyKeyPermission {654	pub key: PropertyKey,655	pub permission: PropertyPermission,656}657658pub enum PropertiesError {659	NoSpaceForProperty,660	PropertyLimitReached,661}662663impl From<PropertiesError> for DispatchError {664	fn from(error: PropertiesError) -> Self {665		match error {666			PropertiesError::NoSpaceForProperty => DispatchError::Other("no space for property"),667			PropertiesError::PropertyLimitReached => {668				DispatchError::Other("property key limit reached")669			}670		}671	}672}673674pub type PropertiesMap =675	BoundedBTreeMap<PropertyKey, PropertyValue, ConstU32<MAX_PROPERTIES_PER_ITEM>>;676pub type PropertiesPermissionMap =677	BoundedBTreeMap<PropertyKey, PropertyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;678679#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, MaxEncodedLen)]680pub struct Properties {681	map: PropertiesMap,682	consumed_space: u32,683	space_limit: u32,684}685686impl Properties {687	pub fn new(space_limit: u32) -> Self {688		Self {689			map: BoundedBTreeMap::new(),690			consumed_space: 0,691			space_limit,692		}693	}694695	pub fn from_collection_props_vec(696		data: CollectionPropertiesVec,697	) -> Result<Self, PropertiesError> {698		let mut props = Self::new(MAX_COLLECTION_PROPERTIES_SIZE);699700		for property in data.into_iter() {701			props.try_change_property(property)?;702		}703704		Ok(props)705	}706707	pub fn try_change_property(&mut self, property: Property) -> Result<(), PropertiesError> {708		let value_len = property.value.len();709710		if self.consumed_space as usize + value_len > self.space_limit as usize {711			return Err(PropertiesError::NoSpaceForProperty);712		}713714		self.map715			.try_insert(property.key, property.value)716			.map_err(|_| PropertiesError::PropertyLimitReached)?;717718		self.consumed_space += value_len as u32;719720		Ok(())721	}722723	pub fn get_property(&self, key: &PropertyKey) -> Option<&PropertyValue> {724		self.map.get(key)725	}726}727728pub struct CollectionProperties;729730impl Get<Properties> for CollectionProperties {731	fn get() -> Properties {732		Properties::new(MAX_COLLECTION_PROPERTIES_SIZE)733	}734}735736pub struct TokenProperties;737738impl Get<Properties> for TokenProperties {739	fn get() -> Properties {740		Properties::new(MAX_TOKEN_PROPERTIES_SIZE)741	}742}743744// #[cfg(not(feature = "std"))]745// fn properties_map_debug(_properties: &PropertiesMap, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {746// 	write!(f, "<properties>")747// }748749// #[cfg(not(feature = "std"))]750// fn opt_properties_permissions_map_debug(properties: &Option<PropertiesPermissionMap>, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {751// 	if properties.is_some() {752// 		write!(f, "Some(<properties permissions>)")753// 	 } else {754// 		write!(f, "None")755// 	}756// }
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -16,7 +16,9 @@
 
 #![cfg_attr(not(feature = "std"), no_std)]
 
-use up_data_structs::{CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits};
+use up_data_structs::{
+	CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,
+};
 use sp_std::vec::Vec;
 use codec::Decode;
 use sp_runtime::DispatchError;
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -54,6 +54,10 @@
 		dispatch_weight::<T>() + max_weight_of!(burn_item())
 	}
 
+	fn set_property() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(set_property())
+	}
+
 	fn transfer() -> Weight {
 		dispatch_weight::<T>() + max_weight_of!(transfer())
 	}