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
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -386,6 +386,26 @@
 			.into_inner()
 	}
 
+	fn token_properties(
+		&self,
+		token_id: TokenId,
+		keys: Vec<PropertyKey>
+	) -> Vec<Property> {
+		let properties = <Pallet<T>>::token_properties((self.id, token_id));
+
+		keys.into_iter()
+			.filter_map(|key| {
+				properties.get_property(&key)
+					.map(|value| {
+						Property {
+							key,
+							value: value.clone()
+						}
+					})
+			})
+			.collect()
+	}
+
 	fn total_supply(&self) -> u32 {
 		<Pallet<T>>::total_supply(self)
 	}
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
before · pallets/refungible/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 sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};21use up_data_structs::{22	CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,23	budget::Budget, Property, PropertyKey, PropertyKeyPermission,24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;27use sp_std::{vec::Vec, vec};2829use crate::{30	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,31	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,32};3334macro_rules! max_weight_of {35	($($method:ident ($($args:tt)*)),*) => {36		037		$(38			.max(<SelfWeightOf<T>>::$method($($args)*))39		)*40	};41}4243pub struct CommonWeights<T: Config>(PhantomData<T>);44impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {45	fn create_item() -> Weight {46		<SelfWeightOf<T>>::create_item()47	}4849	fn create_multiple_items(amount: u32) -> Weight {50		<SelfWeightOf<T>>::create_multiple_items(amount)51	}5253	fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {54		match call {55			CreateItemExData::RefungibleMultipleOwners(i) => {56				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)57			}58			CreateItemExData::RefungibleMultipleItems(i) => {59				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)60			}61			_ => 0,62		}63	}6465	fn burn_item() -> Weight {66		max_weight_of!(burn_item_partial(), burn_item_fully())67	}6869	fn set_collection_properties(amount: u32) -> Weight {70		<SelfWeightOf<T>>::set_collection_properties(amount)71	}7273	fn delete_collection_properties(amount: u32) -> Weight {74		<SelfWeightOf<T>>::delete_collection_properties(amount)75	}7677	fn set_token_properties(amount: u32) -> Weight {78		<SelfWeightOf<T>>::set_token_properties(amount)79	}8081	fn delete_token_properties(amount: u32) -> Weight {82		<SelfWeightOf<T>>::delete_token_properties(amount)83	}8485	fn set_property_permissions(amount: u32) -> Weight {86		<SelfWeightOf<T>>::set_property_permissions(amount)87	}8889	fn transfer() -> Weight {90		max_weight_of!(91			transfer_normal(),92			transfer_creating(),93			transfer_removing(),94			transfer_creating_removing()95		)96	}9798	fn approve() -> Weight {99		<SelfWeightOf<T>>::approve()100	}101102	fn transfer_from() -> Weight {103		max_weight_of!(104			transfer_from_normal(),105			transfer_from_creating(),106			transfer_from_removing(),107			transfer_from_creating_removing()108		)109	}110111	fn burn_from() -> Weight {112		<SelfWeightOf<T>>::burn_from()113	}114115	fn set_variable_metadata(bytes: u32) -> Weight {116		<SelfWeightOf<T>>::set_variable_metadata(bytes)117	}118}119120fn map_create_data<T: Config>(121	data: up_data_structs::CreateItemData,122	to: &T::CrossAccountId,123) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {124	match data {125		up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {126			const_data: data.const_data,127			variable_data: data.variable_data,128			users: {129				let mut out = BTreeMap::new();130				out.insert(to.clone(), data.pieces);131				out.try_into().expect("limit > 0")132			},133		}),134		_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),135	}136}137138impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {139	fn create_item(140		&self,141		sender: T::CrossAccountId,142		to: T::CrossAccountId,143		data: up_data_structs::CreateItemData,144		nesting_budget: &dyn Budget,145	) -> DispatchResultWithPostInfo {146		with_weight(147			<Pallet<T>>::create_item(148				self,149				&sender,150				map_create_data::<T>(data, &to)?,151				nesting_budget,152			),153			<CommonWeights<T>>::create_item(),154		)155	}156157	fn create_multiple_items(158		&self,159		sender: T::CrossAccountId,160		to: T::CrossAccountId,161		data: Vec<up_data_structs::CreateItemData>,162		nesting_budget: &dyn Budget,163	) -> DispatchResultWithPostInfo {164		let data = data165			.into_iter()166			.map(|d| map_create_data::<T>(d, &to))167			.collect::<Result<Vec<_>, DispatchError>>()?;168169		let amount = data.len();170		with_weight(171			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),172			<CommonWeights<T>>::create_multiple_items(amount as u32),173		)174	}175176	fn create_multiple_items_ex(177		&self,178		sender: <T>::CrossAccountId,179		data: CreateItemExData<T::CrossAccountId>,180		nesting_budget: &dyn Budget,181	) -> DispatchResultWithPostInfo {182		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);183		let data = match data {184			CreateItemExData::RefungibleMultipleOwners(r) => vec![r],185			CreateItemExData::RefungibleMultipleItems(r)186				if r.iter().all(|i| i.users.len() == 1) =>187			{188				r.into_inner()189			}190			_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),191		};192193		with_weight(194			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),195			weight,196		)197	}198199	fn burn_item(200		&self,201		sender: T::CrossAccountId,202		token: TokenId,203		amount: u128,204	) -> DispatchResultWithPostInfo {205		with_weight(206			<Pallet<T>>::burn(self, &sender, token, amount),207			<CommonWeights<T>>::burn_item(),208		)209	}210211	fn transfer(212		&self,213		from: T::CrossAccountId,214		to: T::CrossAccountId,215		token: TokenId,216		amount: u128,217		nesting_budget: &dyn Budget,218	) -> DispatchResultWithPostInfo {219		with_weight(220			<Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),221			<CommonWeights<T>>::transfer(),222		)223	}224225	fn approve(226		&self,227		sender: T::CrossAccountId,228		spender: T::CrossAccountId,229		token: TokenId,230		amount: u128,231	) -> DispatchResultWithPostInfo {232		with_weight(233			<Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),234			<CommonWeights<T>>::approve(),235		)236	}237238	fn transfer_from(239		&self,240		sender: T::CrossAccountId,241		from: T::CrossAccountId,242		to: T::CrossAccountId,243		token: TokenId,244		amount: u128,245		nesting_budget: &dyn Budget,246	) -> DispatchResultWithPostInfo {247		with_weight(248			<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),249			<CommonWeights<T>>::transfer_from(),250		)251	}252253	fn burn_from(254		&self,255		sender: T::CrossAccountId,256		from: T::CrossAccountId,257		token: TokenId,258		amount: u128,259		nesting_budget: &dyn Budget,260	) -> DispatchResultWithPostInfo {261		with_weight(262			<Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),263			<CommonWeights<T>>::burn_from(),264		)265	}266267	fn set_collection_properties(268		&self,269		_sender: T::CrossAccountId,270		_property: Vec<Property>,271	) -> DispatchResultWithPostInfo {272		fail!(<Error<T>>::PropertiesNotAllowed)273	}274275	fn delete_collection_properties(276		&self,277		_sender: &T::CrossAccountId,278		_property_keys: Vec<PropertyKey>,279	) -> DispatchResultWithPostInfo {280		fail!(<Error<T>>::PropertiesNotAllowed)281	}282283	fn set_token_properties(284		&self,285		_sender: T::CrossAccountId,286		_token_id: TokenId,287		_property: Vec<Property>,288	) -> DispatchResultWithPostInfo {289		fail!(<Error<T>>::PropertiesNotAllowed)290	}291292	fn set_property_permissions(293		&self,294		_sender: &T::CrossAccountId,295		_property_permissions: Vec<PropertyKeyPermission>,296	) -> DispatchResultWithPostInfo {297		fail!(<Error<T>>::PropertiesNotAllowed)298	}299300	fn delete_token_properties(301		&self,302		_sender: T::CrossAccountId,303		_token_id: TokenId,304		_property_keys: Vec<PropertyKey>,305	) -> DispatchResultWithPostInfo {306		fail!(<Error<T>>::PropertiesNotAllowed)307	}308309	fn set_variable_metadata(310		&self,311		sender: T::CrossAccountId,312		token: TokenId,313		data: BoundedVec<u8, CustomDataLimit>,314	) -> DispatchResultWithPostInfo {315		let len = data.len();316		with_weight(317			<Pallet<T>>::set_variable_metadata(self, &sender, token, data),318			<CommonWeights<T>>::set_variable_metadata(len as u32),319		)320	}321322	fn check_nesting(323		&self,324		_sender: <T>::CrossAccountId,325		_from: (CollectionId, TokenId),326		_under: TokenId,327		_budget: &dyn Budget,328	) -> sp_runtime::DispatchResult {329		fail!(<Error<T>>::RefungibleDisallowsNesting)330	}331332	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {333		<Owned<T>>::iter_prefix((self.id, account))334			.map(|(id, _)| id)335			.collect()336	}337338	fn collection_tokens(&self) -> Vec<TokenId> {339		<TokenData<T>>::iter_prefix((self.id,))340			.map(|(id, _)| id)341			.collect()342	}343344	fn token_exists(&self, token: TokenId) -> bool {345		<Pallet<T>>::token_exists(self, token)346	}347348	fn last_token_id(&self) -> TokenId {349		TokenId(<TokensMinted<T>>::get(self.id))350	}351352	fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {353		None354	}355	fn const_metadata(&self, token: TokenId) -> Vec<u8> {356		<TokenData<T>>::get((self.id, token))357			.const_data358			.into_inner()359	}360	fn variable_metadata(&self, token: TokenId) -> Vec<u8> {361		<TokenData<T>>::get((self.id, token))362			.variable_data363			.into_inner()364	}365366	fn total_supply(&self) -> u32 {367		<Pallet<T>>::total_supply(self)368	}369370	fn account_balance(&self, account: T::CrossAccountId) -> u32 {371		<AccountBalance<T>>::get((self.id, account))372	}373374	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {375		<Balance<T>>::get((self.id, token, account))376	}377378	fn allowance(379		&self,380		sender: T::CrossAccountId,381		spender: T::CrossAccountId,382		token: TokenId,383	) -> u128 {384		<Allowance<T>>::get((self.id, token, sender, spender))385	}386}
after · pallets/refungible/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 sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};21use up_data_structs::{22	CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,23	budget::Budget, Property, PropertyKey, PropertyKeyPermission,24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;27use sp_std::{vec::Vec, vec};2829use crate::{30	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,31	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,32};3334macro_rules! max_weight_of {35	($($method:ident ($($args:tt)*)),*) => {36		037		$(38			.max(<SelfWeightOf<T>>::$method($($args)*))39		)*40	};41}4243pub struct CommonWeights<T: Config>(PhantomData<T>);44impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {45	fn create_item() -> Weight {46		<SelfWeightOf<T>>::create_item()47	}4849	fn create_multiple_items(amount: u32) -> Weight {50		<SelfWeightOf<T>>::create_multiple_items(amount)51	}5253	fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {54		match call {55			CreateItemExData::RefungibleMultipleOwners(i) => {56				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)57			}58			CreateItemExData::RefungibleMultipleItems(i) => {59				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)60			}61			_ => 0,62		}63	}6465	fn burn_item() -> Weight {66		max_weight_of!(burn_item_partial(), burn_item_fully())67	}6869	fn set_collection_properties(amount: u32) -> Weight {70		<SelfWeightOf<T>>::set_collection_properties(amount)71	}7273	fn delete_collection_properties(amount: u32) -> Weight {74		<SelfWeightOf<T>>::delete_collection_properties(amount)75	}7677	fn set_token_properties(amount: u32) -> Weight {78		<SelfWeightOf<T>>::set_token_properties(amount)79	}8081	fn delete_token_properties(amount: u32) -> Weight {82		<SelfWeightOf<T>>::delete_token_properties(amount)83	}8485	fn set_property_permissions(amount: u32) -> Weight {86		<SelfWeightOf<T>>::set_property_permissions(amount)87	}8889	fn transfer() -> Weight {90		max_weight_of!(91			transfer_normal(),92			transfer_creating(),93			transfer_removing(),94			transfer_creating_removing()95		)96	}9798	fn approve() -> Weight {99		<SelfWeightOf<T>>::approve()100	}101102	fn transfer_from() -> Weight {103		max_weight_of!(104			transfer_from_normal(),105			transfer_from_creating(),106			transfer_from_removing(),107			transfer_from_creating_removing()108		)109	}110111	fn burn_from() -> Weight {112		<SelfWeightOf<T>>::burn_from()113	}114115	fn set_variable_metadata(bytes: u32) -> Weight {116		<SelfWeightOf<T>>::set_variable_metadata(bytes)117	}118}119120fn map_create_data<T: Config>(121	data: up_data_structs::CreateItemData,122	to: &T::CrossAccountId,123) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {124	match data {125		up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {126			const_data: data.const_data,127			variable_data: data.variable_data,128			users: {129				let mut out = BTreeMap::new();130				out.insert(to.clone(), data.pieces);131				out.try_into().expect("limit > 0")132			},133		}),134		_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),135	}136}137138impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {139	fn create_item(140		&self,141		sender: T::CrossAccountId,142		to: T::CrossAccountId,143		data: up_data_structs::CreateItemData,144		nesting_budget: &dyn Budget,145	) -> DispatchResultWithPostInfo {146		with_weight(147			<Pallet<T>>::create_item(148				self,149				&sender,150				map_create_data::<T>(data, &to)?,151				nesting_budget,152			),153			<CommonWeights<T>>::create_item(),154		)155	}156157	fn create_multiple_items(158		&self,159		sender: T::CrossAccountId,160		to: T::CrossAccountId,161		data: Vec<up_data_structs::CreateItemData>,162		nesting_budget: &dyn Budget,163	) -> DispatchResultWithPostInfo {164		let data = data165			.into_iter()166			.map(|d| map_create_data::<T>(d, &to))167			.collect::<Result<Vec<_>, DispatchError>>()?;168169		let amount = data.len();170		with_weight(171			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),172			<CommonWeights<T>>::create_multiple_items(amount as u32),173		)174	}175176	fn create_multiple_items_ex(177		&self,178		sender: <T>::CrossAccountId,179		data: CreateItemExData<T::CrossAccountId>,180		nesting_budget: &dyn Budget,181	) -> DispatchResultWithPostInfo {182		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);183		let data = match data {184			CreateItemExData::RefungibleMultipleOwners(r) => vec![r],185			CreateItemExData::RefungibleMultipleItems(r)186				if r.iter().all(|i| i.users.len() == 1) =>187			{188				r.into_inner()189			}190			_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),191		};192193		with_weight(194			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),195			weight,196		)197	}198199	fn burn_item(200		&self,201		sender: T::CrossAccountId,202		token: TokenId,203		amount: u128,204	) -> DispatchResultWithPostInfo {205		with_weight(206			<Pallet<T>>::burn(self, &sender, token, amount),207			<CommonWeights<T>>::burn_item(),208		)209	}210211	fn transfer(212		&self,213		from: T::CrossAccountId,214		to: T::CrossAccountId,215		token: TokenId,216		amount: u128,217		nesting_budget: &dyn Budget,218	) -> DispatchResultWithPostInfo {219		with_weight(220			<Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),221			<CommonWeights<T>>::transfer(),222		)223	}224225	fn approve(226		&self,227		sender: T::CrossAccountId,228		spender: T::CrossAccountId,229		token: TokenId,230		amount: u128,231	) -> DispatchResultWithPostInfo {232		with_weight(233			<Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),234			<CommonWeights<T>>::approve(),235		)236	}237238	fn transfer_from(239		&self,240		sender: T::CrossAccountId,241		from: T::CrossAccountId,242		to: T::CrossAccountId,243		token: TokenId,244		amount: u128,245		nesting_budget: &dyn Budget,246	) -> DispatchResultWithPostInfo {247		with_weight(248			<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),249			<CommonWeights<T>>::transfer_from(),250		)251	}252253	fn burn_from(254		&self,255		sender: T::CrossAccountId,256		from: T::CrossAccountId,257		token: TokenId,258		amount: u128,259		nesting_budget: &dyn Budget,260	) -> DispatchResultWithPostInfo {261		with_weight(262			<Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),263			<CommonWeights<T>>::burn_from(),264		)265	}266267	fn set_collection_properties(268		&self,269		_sender: T::CrossAccountId,270		_property: Vec<Property>,271	) -> DispatchResultWithPostInfo {272		fail!(<Error<T>>::SettingPropertiesNotAllowed)273	}274275	fn delete_collection_properties(276		&self,277		_sender: &T::CrossAccountId,278		_property_keys: Vec<PropertyKey>,279	) -> DispatchResultWithPostInfo {280		fail!(<Error<T>>::SettingPropertiesNotAllowed)281	}282283	fn set_token_properties(284		&self,285		_sender: T::CrossAccountId,286		_token_id: TokenId,287		_property: Vec<Property>,288	) -> DispatchResultWithPostInfo {289		fail!(<Error<T>>::SettingPropertiesNotAllowed)290	}291292	fn set_property_permissions(293		&self,294		_sender: &T::CrossAccountId,295		_property_permissions: Vec<PropertyKeyPermission>,296	) -> DispatchResultWithPostInfo {297		fail!(<Error<T>>::SettingPropertiesNotAllowed)298	}299300	fn delete_token_properties(301		&self,302		_sender: T::CrossAccountId,303		_token_id: TokenId,304		_property_keys: Vec<PropertyKey>,305	) -> DispatchResultWithPostInfo {306		fail!(<Error<T>>::SettingPropertiesNotAllowed)307	}308309	fn set_variable_metadata(310		&self,311		sender: T::CrossAccountId,312		token: TokenId,313		data: BoundedVec<u8, CustomDataLimit>,314	) -> DispatchResultWithPostInfo {315		let len = data.len();316		with_weight(317			<Pallet<T>>::set_variable_metadata(self, &sender, token, data),318			<CommonWeights<T>>::set_variable_metadata(len as u32),319		)320	}321322	fn check_nesting(323		&self,324		_sender: <T>::CrossAccountId,325		_from: (CollectionId, TokenId),326		_under: TokenId,327		_budget: &dyn Budget,328	) -> sp_runtime::DispatchResult {329		fail!(<Error<T>>::RefungibleDisallowsNesting)330	}331332	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {333		<Owned<T>>::iter_prefix((self.id, account))334			.map(|(id, _)| id)335			.collect()336	}337338	fn collection_tokens(&self) -> Vec<TokenId> {339		<TokenData<T>>::iter_prefix((self.id,))340			.map(|(id, _)| id)341			.collect()342	}343344	fn token_exists(&self, token: TokenId) -> bool {345		<Pallet<T>>::token_exists(self, token)346	}347348	fn last_token_id(&self) -> TokenId {349		TokenId(<TokensMinted<T>>::get(self.id))350	}351352	fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {353		None354	}355	fn const_metadata(&self, token: TokenId) -> Vec<u8> {356		<TokenData<T>>::get((self.id, token))357			.const_data358			.into_inner()359	}360	fn variable_metadata(&self, token: TokenId) -> Vec<u8> {361		<TokenData<T>>::get((self.id, token))362			.variable_data363			.into_inner()364	}365366	fn token_properties(367		&self,368		_token_id: TokenId,369		_keys: Vec<PropertyKey>370	) -> Vec<Property> {371		Vec::new()372	}373374	fn total_supply(&self) -> u32 {375		<Pallet<T>>::total_supply(self)376	}377378	fn account_balance(&self, account: T::CrossAccountId) -> u32 {379		<AccountBalance<T>>::get((self.id, account))380	}381382	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {383		<Balance<T>>::get((self.id, token, account))384	}385386	fn allowance(387		&self,388		sender: T::CrossAccountId,389		spender: T::CrossAccountId,390		token: TokenId,391	) -> u128 {392		<Allowance<T>>::get((self.id, token, sender, spender))393	}394}
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> {