git.delta.rocks / unique-network / refs/commits / 4154c5103c94

difftreelog

Add token_data RPC

Daniel Shiposha2022-05-06parent: #06ce619.patch.diff
in: master

10 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -21,7 +21,7 @@
 use jsonrpc_derive::rpc;
 use up_data_structs::{
 	RpcCollection, CollectionId, CollectionStats, CollectionLimits, TokenId, Property,
-	PropertyKeyPermission,
+	PropertyKeyPermission, TokenData,
 };
 use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};
 use sp_blockchain::HeaderBackend;
@@ -104,6 +104,15 @@
 		at: Option<BlockHash>,
 	) -> Result<Vec<PropertyKeyPermission>>;
 
+	#[rpc(name = "unique_tokenData")]
+	fn token_data(
+		&self,
+		collection: CollectionId,
+		token_id: TokenId,
+		keys: Vec<String>,
+		at: Option<BlockHash>,
+	) -> Result<TokenData<CrossAccountId>>;
+
 	#[rpc(name = "unique_totalSupply")]
 	fn total_supply(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;
 	#[rpc(name = "unique_accountBalance")]
@@ -294,6 +303,14 @@
 		keys: Vec<String>
 	) -> Vec<PropertyKeyPermission>);
 
+	pass_method!(token_data(
+		collection: CollectionId,
+		token_id: TokenId,
+
+		#[map(|keys| string_keys_to_bytes_keys(keys))]
+		keys: Vec<String>,
+	) -> TokenData<CrossAccountId>);
+
 	pass_method!(total_supply(collection: CollectionId) -> u32);
 	pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);
 	pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -36,7 +36,7 @@
 	CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,
 	CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,
 	PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
-	PropertiesError, PropertyKeyPermission,
+	PropertiesError, PropertyKeyPermission, TokenData,
 };
 pub use pallet::*;
 use sp_core::H160;
@@ -454,6 +454,7 @@
 			CollectionStats,
 			CollectionId,
 			TokenId,
+			PhantomType<TokenData<T::CrossAccountId>>,
 			PhantomType<RpcCollection<T::AccountId>>,
 		),
 		QueryKind = OptionQuery,
@@ -843,6 +844,57 @@
 		Ok(())
 	}
 
+	pub fn bytes_keys_to_property_keys(keys: Vec<Vec<u8>>) -> Result<Vec<PropertyKey>, DispatchError> {
+		keys.into_iter()
+			.map(|key| -> Result<PropertyKey, DispatchError> {
+				// TODO Fix error
+				key.try_into().map_err(|_| DispatchError::Other("Can't read property key"))
+			})
+			.collect::<Result<Vec<PropertyKey>, DispatchError>>()
+	}
+
+	pub fn filter_collection_properties(
+		collection_id: CollectionId,
+		keys: Vec<PropertyKey>
+	) -> Result<Vec<Property>, DispatchError> {
+		let properties = Self::collection_properties(collection_id);
+
+		let properties = keys.into_iter()
+			.filter_map(|key| {
+				properties.get_property(&key)
+					.map(|value| {
+						Property {
+							key,
+							value: value.clone()
+						}
+					})
+			})
+			.collect();
+
+		Ok(properties)
+	}
+
+	pub fn filter_property_permissions(
+		collection_id: CollectionId,
+		keys: Vec<PropertyKey>
+	) -> Result<Vec<PropertyKeyPermission>, DispatchError> {
+		let permissions = Self::property_permissions(collection_id);
+
+		let key_permissions = keys.into_iter()
+			.filter_map(|key| {
+				permissions.get(&key)
+					.map(|permission| {
+						PropertyKeyPermission {
+							key,
+							permission: permission.clone()
+						}
+					})
+			})
+			.collect();
+
+		Ok(key_permissions)
+	}
+
 	fn set_field_raw(
 		collection_id: CollectionId,
 		field: CollectionField,
@@ -1117,7 +1169,11 @@
 	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;
 	fn const_metadata(&self, token: TokenId) -> Vec<u8>;
 	fn variable_metadata(&self, token: TokenId) -> Vec<u8>;
-
+	fn token_properties(
+		&self,
+		token_id: TokenId,
+		keys: Vec<PropertyKey>
+	) -> Vec<Property>;
 	/// Amount of unique collection tokens
 	fn total_supply(&self) -> u32;
 	/// Amount of different tokens account has (Applicable to nonfungible/refungible)
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -250,7 +250,7 @@
 		_sender: T::CrossAccountId,
 		_property: Vec<Property>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn delete_collection_properties(
@@ -258,7 +258,7 @@
 		_sender: &T::CrossAccountId,
 		_property_keys: Vec<PropertyKey>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn set_token_properties(
@@ -267,7 +267,7 @@
 		_token_id: TokenId,
 		_property: Vec<Property>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn set_property_permissions(
@@ -275,7 +275,7 @@
 		_sender: &T::CrossAccountId,
 		_property_permissions: Vec<PropertyKeyPermission>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn delete_token_properties(
@@ -284,7 +284,7 @@
 		_token_id: TokenId,
 		_property_keys: Vec<PropertyKey>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn set_variable_metadata(
@@ -336,6 +336,14 @@
 		Vec::new()
 	}
 
+	fn token_properties(
+		&self,
+		_token_id: TokenId,
+		_keys: Vec<PropertyKey>
+	) -> Vec<Property> {
+		Vec::new()
+	}
+
 	fn total_supply(&self) -> u32 {
 		1
 	}
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -61,8 +61,8 @@
 		FungibleItemsDontHaveData,
 		/// Fungible token does not support nested
 		FungibleDisallowsNesting,
-		/// Item properties are not allowed
-		PropertiesNotAllowed,
+		/// Setting item properties is not allowed
+		SettingPropertiesNotAllowed,
 	}
 
 	#[pallet::config]
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
before · pallets/nonfungible/src/common.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/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};20use up_data_structs::{21	TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,22	PropertyKey, PropertyKeyPermission,23};24use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use sp_runtime::DispatchError;26use sp_std::vec::Vec;2728use crate::{29	AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,30	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,31};3233pub struct CommonWeights<T: Config>(PhantomData<T>);34impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {35	fn create_item() -> Weight {36		<SelfWeightOf<T>>::create_item()37	}3839	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {40		match data {41			CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),42			_ => 0,43		}44	}4546	fn create_multiple_items(amount: u32) -> Weight {47		<SelfWeightOf<T>>::create_multiple_items(amount)48	}4950	fn burn_item() -> Weight {51		<SelfWeightOf<T>>::burn_item()52	}5354	fn set_collection_properties(amount: u32) -> Weight {55		<SelfWeightOf<T>>::set_collection_properties(amount)56	}5758	fn delete_collection_properties(amount: u32) -> Weight {59		<SelfWeightOf<T>>::delete_collection_properties(amount)60	}6162	fn set_token_properties(amount: u32) -> Weight {63		<SelfWeightOf<T>>::set_token_properties(amount)64	}6566	fn delete_token_properties(amount: u32) -> Weight {67		<SelfWeightOf<T>>::delete_token_properties(amount)68	}6970	fn set_property_permissions(amount: u32) -> Weight {71		<SelfWeightOf<T>>::set_property_permissions(amount)72	}7374	fn transfer() -> Weight {75		<SelfWeightOf<T>>::transfer()76	}7778	fn approve() -> Weight {79		<SelfWeightOf<T>>::approve()80	}8182	fn transfer_from() -> Weight {83		<SelfWeightOf<T>>::transfer_from()84	}8586	fn burn_from() -> Weight {87		<SelfWeightOf<T>>::burn_from()88	}8990	fn set_variable_metadata(bytes: u32) -> Weight {91		<SelfWeightOf<T>>::set_variable_metadata(bytes)92	}93}9495fn map_create_data<T: Config>(96	data: up_data_structs::CreateItemData,97	to: &T::CrossAccountId,98) -> Result<CreateItemData<T>, DispatchError> {99	match data {100		up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {101			const_data: data.const_data,102			variable_data: data.variable_data,103			properties: data.properties,104			owner: to.clone(),105		}),106		_ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),107	}108}109110impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {111	fn create_item(112		&self,113		sender: T::CrossAccountId,114		to: T::CrossAccountId,115		data: up_data_structs::CreateItemData,116		nesting_budget: &dyn Budget,117	) -> DispatchResultWithPostInfo {118		with_weight(119			<Pallet<T>>::create_item(120				self,121				&sender,122				map_create_data::<T>(data, &to)?,123				nesting_budget,124			),125			<CommonWeights<T>>::create_item(),126		)127	}128129	fn create_multiple_items(130		&self,131		sender: T::CrossAccountId,132		to: T::CrossAccountId,133		data: Vec<up_data_structs::CreateItemData>,134		nesting_budget: &dyn Budget,135	) -> DispatchResultWithPostInfo {136		let data = data137			.into_iter()138			.map(|d| map_create_data::<T>(d, &to))139			.collect::<Result<Vec<_>, DispatchError>>()?;140141		let amount = data.len();142		with_weight(143			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),144			<CommonWeights<T>>::create_multiple_items(amount as u32),145		)146	}147148	fn create_multiple_items_ex(149		&self,150		sender: <T>::CrossAccountId,151		data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,152		nesting_budget: &dyn Budget,153	) -> DispatchResultWithPostInfo {154		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);155		let data = match data {156			up_data_structs::CreateItemExData::NFT(nft) => nft,157			_ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),158		};159160		with_weight(161			<Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),162			weight,163		)164	}165166	fn set_collection_properties(167		&self,168		sender: T::CrossAccountId,169		properties: Vec<Property>,170	) -> DispatchResultWithPostInfo {171		let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);172173		with_weight(174			<Pallet<T>>::set_collection_properties(self, &sender, properties),175			weight,176		)177	}178179	fn delete_collection_properties(180		&self,181		sender: &T::CrossAccountId,182		property_keys: Vec<PropertyKey>,183	) -> DispatchResultWithPostInfo {184		let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);185186		with_weight(187			<Pallet<T>>::delete_collection_properties(self, &sender, property_keys),188			weight,189		)190	}191192	fn set_token_properties(193		&self,194		sender: T::CrossAccountId,195		token_id: TokenId,196		properties: Vec<Property>,197	) -> DispatchResultWithPostInfo {198		let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);199200		with_weight(201			<Pallet<T>>::set_token_properties(self, &sender, token_id, properties),202			weight,203		)204	}205206	fn delete_token_properties(207		&self,208		sender: T::CrossAccountId,209		token_id: TokenId,210		property_keys: Vec<PropertyKey>,211	) -> DispatchResultWithPostInfo {212		let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);213214		with_weight(215			<Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),216			weight,217		)218	}219220	fn set_property_permissions(221		&self,222		sender: &T::CrossAccountId,223		property_permissions: Vec<PropertyKeyPermission>,224	) -> DispatchResultWithPostInfo {225		let weight =226			<CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);227228		with_weight(229			<Pallet<T>>::set_property_permissions(self, sender, property_permissions),230			weight,231		)232	}233234	fn burn_item(235		&self,236		sender: T::CrossAccountId,237		token: TokenId,238		amount: u128,239	) -> DispatchResultWithPostInfo {240		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);241		if amount == 1 {242			with_weight(243				<Pallet<T>>::burn(self, &sender, token),244				<CommonWeights<T>>::burn_item(),245			)246		} else {247			Ok(().into())248		}249	}250251	fn transfer(252		&self,253		from: T::CrossAccountId,254		to: T::CrossAccountId,255		token: TokenId,256		amount: u128,257		nesting_budget: &dyn Budget,258	) -> DispatchResultWithPostInfo {259		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);260		if amount == 1 {261			with_weight(262				<Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),263				<CommonWeights<T>>::transfer(),264			)265		} else {266			Ok(().into())267		}268	}269270	fn approve(271		&self,272		sender: T::CrossAccountId,273		spender: T::CrossAccountId,274		token: TokenId,275		amount: u128,276	) -> DispatchResultWithPostInfo {277		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);278279		with_weight(280			if amount == 1 {281				<Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))282			} else {283				<Pallet<T>>::set_allowance(self, &sender, token, None)284			},285			<CommonWeights<T>>::approve(),286		)287	}288289	fn transfer_from(290		&self,291		sender: T::CrossAccountId,292		from: T::CrossAccountId,293		to: T::CrossAccountId,294		token: TokenId,295		amount: u128,296		nesting_budget: &dyn Budget,297	) -> DispatchResultWithPostInfo {298		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);299300		if amount == 1 {301			with_weight(302				<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),303				<CommonWeights<T>>::transfer_from(),304			)305		} else {306			Ok(().into())307		}308	}309310	fn burn_from(311		&self,312		sender: T::CrossAccountId,313		from: T::CrossAccountId,314		token: TokenId,315		amount: u128,316		nesting_budget: &dyn Budget,317	) -> DispatchResultWithPostInfo {318		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);319320		if amount == 1 {321			with_weight(322				<Pallet<T>>::burn_from(self, &sender, &from, token, nesting_budget),323				<CommonWeights<T>>::burn_from(),324			)325		} else {326			Ok(().into())327		}328	}329330	fn set_variable_metadata(331		&self,332		sender: T::CrossAccountId,333		token: TokenId,334		data: BoundedVec<u8, CustomDataLimit>,335	) -> DispatchResultWithPostInfo {336		let len = data.len();337		with_weight(338			<Pallet<T>>::set_variable_metadata(self, &sender, token, data),339			<CommonWeights<T>>::set_variable_metadata(len as u32),340		)341	}342343	fn check_nesting(344		&self,345		sender: T::CrossAccountId,346		from: (CollectionId, TokenId),347		under: TokenId,348		budget: &dyn Budget,349	) -> sp_runtime::DispatchResult {350		<Pallet<T>>::check_nesting(self, sender, from, under, budget)351	}352353	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {354		<Owned<T>>::iter_prefix((self.id, account))355			.map(|(id, _)| id)356			.collect()357	}358359	fn collection_tokens(&self) -> Vec<TokenId> {360		<TokenData<T>>::iter_prefix((self.id,))361			.map(|(id, _)| id)362			.collect()363	}364365	fn token_exists(&self, token: TokenId) -> bool {366		<Pallet<T>>::token_exists(self, token)367	}368369	fn last_token_id(&self) -> TokenId {370		TokenId(<TokensMinted<T>>::get(self.id))371	}372373	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {374		<TokenData<T>>::get((self.id, token)).map(|t| t.owner)375	}376	fn const_metadata(&self, token: TokenId) -> Vec<u8> {377		<TokenData<T>>::get((self.id, token))378			.map(|t| t.const_data)379			.unwrap_or_default()380			.into_inner()381	}382	fn variable_metadata(&self, token: TokenId) -> Vec<u8> {383		<TokenData<T>>::get((self.id, token))384			.map(|t| t.variable_data)385			.unwrap_or_default()386			.into_inner()387	}388389	fn total_supply(&self) -> u32 {390		<Pallet<T>>::total_supply(self)391	}392393	fn account_balance(&self, account: T::CrossAccountId) -> u32 {394		<AccountBalance<T>>::get((self.id, account))395	}396397	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {398		if <TokenData<T>>::get((self.id, token))399			.map(|a| a.owner == account)400			.unwrap_or(false)401		{402			1403		} else {404			0405		}406	}407408	fn allowance(409		&self,410		sender: T::CrossAccountId,411		spender: T::CrossAccountId,412		token: TokenId,413	) -> u128 {414		if <TokenData<T>>::get((self.id, token))415			.map(|a| a.owner != sender)416			.unwrap_or(true)417		{418			0419		} else if <Allowance<T>>::get((self.id, token)) == Some(spender) {420			1421		} else {422			0423		}424	}425}
after · pallets/nonfungible/src/common.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/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};20use up_data_structs::{21	TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,22	PropertyKey, PropertyKeyPermission,23};24use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};25use sp_runtime::DispatchError;26use sp_std::vec::Vec;2728use crate::{29	AccountBalance, Allowance, Config, CreateItemData, Error, NonfungibleHandle, Owned, Pallet,30	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,31};3233pub struct CommonWeights<T: Config>(PhantomData<T>);34impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {35	fn create_item() -> Weight {36		<SelfWeightOf<T>>::create_item()37	}3839	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {40		match data {41			CreateItemExData::NFT(t) => <SelfWeightOf<T>>::create_multiple_items_ex(t.len() as u32),42			_ => 0,43		}44	}4546	fn create_multiple_items(amount: u32) -> Weight {47		<SelfWeightOf<T>>::create_multiple_items(amount)48	}4950	fn burn_item() -> Weight {51		<SelfWeightOf<T>>::burn_item()52	}5354	fn set_collection_properties(amount: u32) -> Weight {55		<SelfWeightOf<T>>::set_collection_properties(amount)56	}5758	fn delete_collection_properties(amount: u32) -> Weight {59		<SelfWeightOf<T>>::delete_collection_properties(amount)60	}6162	fn set_token_properties(amount: u32) -> Weight {63		<SelfWeightOf<T>>::set_token_properties(amount)64	}6566	fn delete_token_properties(amount: u32) -> Weight {67		<SelfWeightOf<T>>::delete_token_properties(amount)68	}6970	fn set_property_permissions(amount: u32) -> Weight {71		<SelfWeightOf<T>>::set_property_permissions(amount)72	}7374	fn transfer() -> Weight {75		<SelfWeightOf<T>>::transfer()76	}7778	fn approve() -> Weight {79		<SelfWeightOf<T>>::approve()80	}8182	fn transfer_from() -> Weight {83		<SelfWeightOf<T>>::transfer_from()84	}8586	fn burn_from() -> Weight {87		<SelfWeightOf<T>>::burn_from()88	}8990	fn set_variable_metadata(bytes: u32) -> Weight {91		<SelfWeightOf<T>>::set_variable_metadata(bytes)92	}93}9495fn map_create_data<T: Config>(96	data: up_data_structs::CreateItemData,97	to: &T::CrossAccountId,98) -> Result<CreateItemData<T>, DispatchError> {99	match data {100		up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {101			const_data: data.const_data,102			variable_data: data.variable_data,103			properties: data.properties,104			owner: to.clone(),105		}),106		_ => fail!(<Error<T>>::NotNonfungibleDataUsedToMintFungibleCollectionToken),107	}108}109110impl<T: Config> CommonCollectionOperations<T> for NonfungibleHandle<T> {111	fn create_item(112		&self,113		sender: T::CrossAccountId,114		to: T::CrossAccountId,115		data: up_data_structs::CreateItemData,116		nesting_budget: &dyn Budget,117	) -> DispatchResultWithPostInfo {118		with_weight(119			<Pallet<T>>::create_item(120				self,121				&sender,122				map_create_data::<T>(data, &to)?,123				nesting_budget,124			),125			<CommonWeights<T>>::create_item(),126		)127	}128129	fn create_multiple_items(130		&self,131		sender: T::CrossAccountId,132		to: T::CrossAccountId,133		data: Vec<up_data_structs::CreateItemData>,134		nesting_budget: &dyn Budget,135	) -> DispatchResultWithPostInfo {136		let data = data137			.into_iter()138			.map(|d| map_create_data::<T>(d, &to))139			.collect::<Result<Vec<_>, DispatchError>>()?;140141		let amount = data.len();142		with_weight(143			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),144			<CommonWeights<T>>::create_multiple_items(amount as u32),145		)146	}147148	fn create_multiple_items_ex(149		&self,150		sender: <T>::CrossAccountId,151		data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,152		nesting_budget: &dyn Budget,153	) -> DispatchResultWithPostInfo {154		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);155		let data = match data {156			up_data_structs::CreateItemExData::NFT(nft) => nft,157			_ => fail!(Error::<T>::NotNonfungibleDataUsedToMintFungibleCollectionToken),158		};159160		with_weight(161			<Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),162			weight,163		)164	}165166	fn set_collection_properties(167		&self,168		sender: T::CrossAccountId,169		properties: Vec<Property>,170	) -> DispatchResultWithPostInfo {171		let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);172173		with_weight(174			<Pallet<T>>::set_collection_properties(self, &sender, properties),175			weight,176		)177	}178179	fn delete_collection_properties(180		&self,181		sender: &T::CrossAccountId,182		property_keys: Vec<PropertyKey>,183	) -> DispatchResultWithPostInfo {184		let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);185186		with_weight(187			<Pallet<T>>::delete_collection_properties(self, &sender, property_keys),188			weight,189		)190	}191192	fn set_token_properties(193		&self,194		sender: T::CrossAccountId,195		token_id: TokenId,196		properties: Vec<Property>,197	) -> DispatchResultWithPostInfo {198		let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);199200		with_weight(201			<Pallet<T>>::set_token_properties(self, &sender, token_id, properties),202			weight,203		)204	}205206	fn delete_token_properties(207		&self,208		sender: T::CrossAccountId,209		token_id: TokenId,210		property_keys: Vec<PropertyKey>,211	) -> DispatchResultWithPostInfo {212		let weight = <CommonWeights<T>>::delete_token_properties(property_keys.len() as u32);213214		with_weight(215			<Pallet<T>>::delete_token_properties(self, &sender, token_id, property_keys),216			weight,217		)218	}219220	fn set_property_permissions(221		&self,222		sender: &T::CrossAccountId,223		property_permissions: Vec<PropertyKeyPermission>,224	) -> DispatchResultWithPostInfo {225		let weight =226			<CommonWeights<T>>::set_property_permissions(property_permissions.len() as u32);227228		with_weight(229			<Pallet<T>>::set_property_permissions(self, sender, property_permissions),230			weight,231		)232	}233234	fn burn_item(235		&self,236		sender: T::CrossAccountId,237		token: TokenId,238		amount: u128,239	) -> DispatchResultWithPostInfo {240		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);241		if amount == 1 {242			with_weight(243				<Pallet<T>>::burn(self, &sender, token),244				<CommonWeights<T>>::burn_item(),245			)246		} else {247			Ok(().into())248		}249	}250251	fn transfer(252		&self,253		from: T::CrossAccountId,254		to: T::CrossAccountId,255		token: TokenId,256		amount: u128,257		nesting_budget: &dyn Budget,258	) -> DispatchResultWithPostInfo {259		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);260		if amount == 1 {261			with_weight(262				<Pallet<T>>::transfer(self, &from, &to, token, nesting_budget),263				<CommonWeights<T>>::transfer(),264			)265		} else {266			Ok(().into())267		}268	}269270	fn approve(271		&self,272		sender: T::CrossAccountId,273		spender: T::CrossAccountId,274		token: TokenId,275		amount: u128,276	) -> DispatchResultWithPostInfo {277		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);278279		with_weight(280			if amount == 1 {281				<Pallet<T>>::set_allowance(self, &sender, token, Some(&spender))282			} else {283				<Pallet<T>>::set_allowance(self, &sender, token, None)284			},285			<CommonWeights<T>>::approve(),286		)287	}288289	fn transfer_from(290		&self,291		sender: T::CrossAccountId,292		from: T::CrossAccountId,293		to: T::CrossAccountId,294		token: TokenId,295		amount: u128,296		nesting_budget: &dyn Budget,297	) -> DispatchResultWithPostInfo {298		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);299300		if amount == 1 {301			with_weight(302				<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, nesting_budget),303				<CommonWeights<T>>::transfer_from(),304			)305		} else {306			Ok(().into())307		}308	}309310	fn burn_from(311		&self,312		sender: T::CrossAccountId,313		from: T::CrossAccountId,314		token: TokenId,315		amount: u128,316		nesting_budget: &dyn Budget,317	) -> DispatchResultWithPostInfo {318		ensure!(amount <= 1, <Error<T>>::NonfungibleItemsHaveNoAmount);319320		if amount == 1 {321			with_weight(322				<Pallet<T>>::burn_from(self, &sender, &from, token, nesting_budget),323				<CommonWeights<T>>::burn_from(),324			)325		} else {326			Ok(().into())327		}328	}329330	fn set_variable_metadata(331		&self,332		sender: T::CrossAccountId,333		token: TokenId,334		data: BoundedVec<u8, CustomDataLimit>,335	) -> DispatchResultWithPostInfo {336		let len = data.len();337		with_weight(338			<Pallet<T>>::set_variable_metadata(self, &sender, token, data),339			<CommonWeights<T>>::set_variable_metadata(len as u32),340		)341	}342343	fn check_nesting(344		&self,345		sender: T::CrossAccountId,346		from: (CollectionId, TokenId),347		under: TokenId,348		budget: &dyn Budget,349	) -> sp_runtime::DispatchResult {350		<Pallet<T>>::check_nesting(self, sender, from, under, budget)351	}352353	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {354		<Owned<T>>::iter_prefix((self.id, account))355			.map(|(id, _)| id)356			.collect()357	}358359	fn collection_tokens(&self) -> Vec<TokenId> {360		<TokenData<T>>::iter_prefix((self.id,))361			.map(|(id, _)| id)362			.collect()363	}364365	fn token_exists(&self, token: TokenId) -> bool {366		<Pallet<T>>::token_exists(self, token)367	}368369	fn last_token_id(&self) -> TokenId {370		TokenId(<TokensMinted<T>>::get(self.id))371	}372373	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {374		<TokenData<T>>::get((self.id, token)).map(|t| t.owner)375	}376	fn const_metadata(&self, token: TokenId) -> Vec<u8> {377		<TokenData<T>>::get((self.id, token))378			.map(|t| t.const_data)379			.unwrap_or_default()380			.into_inner()381	}382	fn variable_metadata(&self, token: TokenId) -> Vec<u8> {383		<TokenData<T>>::get((self.id, token))384			.map(|t| t.variable_data)385			.unwrap_or_default()386			.into_inner()387	}388389	fn token_properties(390		&self,391		token_id: TokenId,392		keys: Vec<PropertyKey>393	) -> Vec<Property> {394		let properties = <Pallet<T>>::token_properties((self.id, token_id));395396		keys.into_iter()397			.filter_map(|key| {398				properties.get_property(&key)399					.map(|value| {400						Property {401							key,402							value: value.clone()403						}404					})405			})406			.collect()407	}408409	fn total_supply(&self) -> u32 {410		<Pallet<T>>::total_supply(self)411	}412413	fn account_balance(&self, account: T::CrossAccountId) -> u32 {414		<AccountBalance<T>>::get((self.id, account))415	}416417	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {418		if <TokenData<T>>::get((self.id, token))419			.map(|a| a.owner == account)420			.unwrap_or(false)421		{422			1423		} else {424			0425		}426	}427428	fn allowance(429		&self,430		sender: T::CrossAccountId,431		spender: T::CrossAccountId,432		token: TokenId,433	) -> u128 {434		if <TokenData<T>>::get((self.id, token))435			.map(|a| a.owner != sender)436			.unwrap_or(true)437		{438			0439		} else if <Allowance<T>>::get((self.id, token)) == Some(spender) {440			1441		} else {442			0443		}444	}445}
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -269,7 +269,7 @@
 		_sender: T::CrossAccountId,
 		_property: Vec<Property>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn delete_collection_properties(
@@ -277,7 +277,7 @@
 		_sender: &T::CrossAccountId,
 		_property_keys: Vec<PropertyKey>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn set_token_properties(
@@ -286,7 +286,7 @@
 		_token_id: TokenId,
 		_property: Vec<Property>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn set_property_permissions(
@@ -294,7 +294,7 @@
 		_sender: &T::CrossAccountId,
 		_property_permissions: Vec<PropertyKeyPermission>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn delete_token_properties(
@@ -303,7 +303,7 @@
 		_token_id: TokenId,
 		_property_keys: Vec<PropertyKey>,
 	) -> DispatchResultWithPostInfo {
-		fail!(<Error<T>>::PropertiesNotAllowed)
+		fail!(<Error<T>>::SettingPropertiesNotAllowed)
 	}
 
 	fn set_variable_metadata(
@@ -363,6 +363,14 @@
 			.into_inner()
 	}
 
+	fn token_properties(
+		&self,
+		_token_id: TokenId,
+		_keys: Vec<PropertyKey>
+	) -> Vec<Property> {
+		Vec::new()
+	}
+
 	fn total_supply(&self) -> u32 {
 		<Pallet<T>>::total_supply(self)
 	}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -62,8 +62,8 @@
 		WrongRefungiblePieces,
 		/// Refungible token can't nest other tokens
 		RefungibleDisallowsNesting,
-		/// Item properties are not allowed
-		PropertiesNotAllowed,
+		/// Setting item properties is not allowed
+		SettingPropertiesNotAllowed,
 	}
 
 	#[pallet::config]
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -173,6 +173,14 @@
 	}
 }
 
+#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
+#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
+pub struct TokenData<CrossAccountId> {
+	pub const_data: Vec<u8>,
+	pub properties: Vec<Property>,
+	pub owner: Option<CrossAccountId>,
+}
+
 pub struct OverflowError;
 impl From<OverflowError> for &'static str {
 	fn from(_: OverflowError) -> Self {
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -18,7 +18,7 @@
 
 use up_data_structs::{
 	CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,
-	PropertyKeyPermission,
+	PropertyKeyPermission, TokenData,
 };
 use sp_std::vec::Vec;
 use codec::Decode;
@@ -57,6 +57,8 @@
 			properties: Vec<Vec<u8>>
 		) -> Result<Vec<PropertyKeyPermission>>;
 
+		fn token_data(collection: CollectionId, token_id: TokenId, keys: Vec<Vec<u8>>) -> Result<TokenData<CrossAccountId>>;
+
 		fn total_supply(collection: CollectionId) -> Result<u32>;
 		fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;
 		fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -7,14 +7,6 @@
             $($custom_apis:tt)+
         )?
     ) => {
-        fn bytes_keys_to_property_keys(keys: Vec<Vec<u8>>) -> Result<Vec<PropertyKey>, DispatchError> {
-            keys.into_iter()
-                .map(|key| -> Result<PropertyKey, DispatchError> {
-                    key.try_into().map_err(|_| DispatchError::Other("Can't read property key"))
-                })
-                .collect::<Result<Vec<PropertyKey>, DispatchError>>()
-        }
-
         impl_runtime_apis! {
             $($($custom_apis)+)?
 
@@ -48,23 +40,9 @@
                     collection: CollectionId,
                     keys: Vec<Vec<u8>>
                 ) -> Result<Vec<Property>, DispatchError> {
-                    let keys = bytes_keys_to_property_keys(keys)?;
-
-                    let properties = pallet_common::Pallet::<Runtime>::collection_properties(collection);
-
-                    let properties = keys.into_iter()
-                        .filter_map(|key| {
-                            properties.get_property(&key)
-                                .map(|value| {
-                                    Property {
-                                        key,
-                                        value: value.clone()
-                                    }
-                                })
-                        })
-                        .collect();
+                    let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;
 
-                    Ok(properties)
+                    pallet_common::Pallet::<Runtime>::filter_collection_properties(collection, keys)
                 }
 
                 fn token_properties(
@@ -72,46 +50,31 @@
                     token_id: TokenId,
                     keys: Vec<Vec<u8>>
                 ) -> Result<Vec<Property>, DispatchError> {
-                    let keys = bytes_keys_to_property_keys(keys)?;
-
-                    let properties = pallet_nonfungible::Pallet::<Runtime>::token_properties((collection, token_id));
-
-                    let properties = keys.into_iter()
-                        .filter_map(|key| {
-                            properties.get_property(&key)
-                                .map(|value| {
-                                    Property {
-                                        key,
-                                        value: value.clone()
-                                    }
-                                })
-                        })
-                        .collect();
-
-                    Ok(properties)
+                    let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;
+                    dispatch_unique_runtime!(collection.token_properties(token_id, keys))
                 }
 
                 fn property_permissions(
                     collection: CollectionId,
                     keys: Vec<Vec<u8>>
                 ) -> Result<Vec<PropertyKeyPermission>, DispatchError> {
-                    let keys = bytes_keys_to_property_keys(keys)?;
+                    let keys = pallet_common::Pallet::<Runtime>::bytes_keys_to_property_keys(keys)?;
 
-                    let permissions = pallet_common::Pallet::<Runtime>::property_permissions(collection);
+                    pallet_common::Pallet::<Runtime>::filter_property_permissions(collection, keys)
+                }
 
-                    let key_permissions = keys.into_iter()
-                        .filter_map(|key| {
-                            permissions.get(&key)
-                                .map(|permission| {
-                                    PropertyKeyPermission {
-                                        key,
-                                        permission: permission.clone()
-                                    }
-                                })
-                        })
-                        .collect();
+                fn token_data(
+                    collection: CollectionId,
+                    token_id: TokenId,
+                    keys: Vec<Vec<u8>>
+                ) -> Result<TokenData<CrossAccountId>, DispatchError> {
+                    let token_data = TokenData {
+                        const_data: Self::const_metadata(collection, token_id)?,
+                        properties: Self::token_properties(collection, token_id, keys)?,
+                        owner: Self::token_owner(collection, token_id)?
+                    };
 
-                    Ok(key_permissions)
+                    Ok(token_data)
                 }
 
                 fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {