git.delta.rocks / unique-network / refs/commits / 960c1089697d

difftreelog

refactor move RMRK rpc impl to proxy pallets

Daniel Shiposha2022-06-17parent: #a8df50d.patch.diff
in: master

6 files changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -35,6 +35,7 @@
 pub mod benchmarking;
 pub mod misc;
 pub mod property;
+pub mod rpc;
 pub mod weights;
 
 pub type SelfWeightOf<T> = <T as Config>::WeightInfo;
addedpallets/proxy-rmrk-core/src/rpc.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/proxy-rmrk-core/src/rpc.rs
@@ -0,0 +1,265 @@
+use super::*;
+
+pub fn last_collection_idx<T: Config>() -> Result<RmrkCollectionId, DispatchError> {
+	Ok(<Pallet<T>>::last_collection_idx())
+}
+
+pub fn collection_by_id<T: Config>(
+	collection_id: RmrkCollectionId,
+) -> Result<Option<RmrkCollectionInfo<T::AccountId>>, DispatchError> {
+	let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(
+		collection_id,
+		misc::CollectionType::Regular,
+	) {
+		Ok(c) => c,
+		Err(_) => return Ok(None),
+	};
+
+	let nfts_count = collection.total_supply();
+
+	Ok(Some(RmrkCollectionInfo {
+		issuer: collection.owner.clone(),
+		metadata: <Pallet<T>>::get_collection_property_decoded(
+			collection_id,
+			RmrkProperty::Metadata,
+		)?,
+		max: collection.limits.token_limit,
+		symbol: <Pallet<T>>::rebind(&collection.token_prefix)?,
+		nfts_count,
+	}))
+}
+
+pub fn nft_by_id<T: Config>(
+	collection_id: RmrkCollectionId,
+	nft_by_id: RmrkNftId,
+) -> Result<Option<RmrkInstanceInfo<T::AccountId>>, DispatchError> {
+	let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(
+		collection_id,
+		misc::CollectionType::Regular,
+	) {
+		Ok(c) => c,
+		Err(_) => return Ok(None),
+	};
+
+	let nft_id = TokenId(nft_by_id);
+	if !<Pallet<T>>::nft_exists(collection_id, nft_id) {
+		return Ok(None);
+	}
+
+	let owner = match collection.token_owner(nft_id) {
+		Some(owner) => match T::CrossTokenAddressMapping::address_to_token(&owner) {
+			Some((col, tok)) => {
+				let rmrk_collection = <Pallet<T>>::rmrk_collection_id(col)?;
+
+				RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)
+			}
+			None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone()),
+		},
+		None => return Ok(None),
+	};
+
+	Ok(Some(RmrkInstanceInfo {
+		owner: owner,
+		royalty: <Pallet<T>>::get_nft_property_decoded(
+			collection_id,
+			nft_id,
+			RmrkProperty::RoyaltyInfo,
+		)?,
+		metadata: <Pallet<T>>::get_nft_property_decoded(
+			collection_id,
+			nft_id,
+			RmrkProperty::Metadata,
+		)?,
+		equipped: <Pallet<T>>::get_nft_property_decoded(
+			collection_id,
+			nft_id,
+			RmrkProperty::Equipped,
+		)?,
+		pending: <Pallet<T>>::get_nft_property_decoded(
+			collection_id,
+			nft_id,
+			RmrkProperty::PendingNftAccept,
+		)?,
+	}))
+}
+
+pub fn account_tokens<T: Config>(
+	account_id: T::AccountId,
+	collection_id: RmrkCollectionId,
+) -> Result<Vec<RmrkNftId>, DispatchError> {
+	let cross_account_id = CrossAccountId::from_sub(account_id);
+
+	let (collection, collection_id) = match <Pallet<T>>::get_typed_nft_collection_mapped(
+		collection_id,
+		misc::CollectionType::Regular,
+	) {
+		Ok(c) => c,
+		Err(_) => return Ok(Vec::new()),
+	};
+
+	let tokens = collection
+		.account_tokens(cross_account_id)
+		.into_iter()
+		.filter(|token| {
+			let is_pending = <Pallet<T>>::get_nft_property_decoded(
+				collection_id,
+				*token,
+				RmrkProperty::PendingNftAccept,
+			)
+			.unwrap_or(true);
+
+			!is_pending
+		})
+		.map(|token| token.0)
+		.collect();
+
+	Ok(tokens)
+}
+
+pub fn nft_children<T: Config>(
+	collection_id: RmrkCollectionId,
+	nft_id: RmrkNftId,
+) -> Result<Vec<RmrkNftChild>, DispatchError> {
+	let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {
+		Ok(id) => id,
+		Err(_) => return Ok(Vec::new()),
+	};
+	let nft_id = TokenId(nft_id);
+	if !<Pallet<T>>::nft_exists(collection_id, nft_id) {
+		return Ok(Vec::new());
+	}
+
+	Ok(
+		pallet_nonfungible::TokenChildren::<T>::iter_prefix((collection_id, nft_id))
+			.filter_map(|((child_collection, child_token), _)| {
+				let is_pending = <Pallet<T>>::get_nft_property_decoded(
+					child_collection,
+					child_token,
+					RmrkProperty::PendingNftAccept,
+				)
+				.ok()?;
+
+				if is_pending {
+					return None;
+				}
+
+				let rmrk_child_collection =
+					<Pallet<T>>::rmrk_collection_id(child_collection).ok()?;
+
+				Some(RmrkNftChild {
+					collection_id: rmrk_child_collection,
+					nft_id: child_token.0,
+				})
+			})
+			.collect(),
+	)
+}
+
+pub fn collection_properties<T: Config>(
+	collection_id: RmrkCollectionId,
+	filter_keys: Option<Vec<RmrkPropertyKey>>,
+) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {
+	let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {
+		Ok(id) => id,
+		Err(_) => return Ok(Vec::new()),
+	};
+	if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {
+		return Ok(Vec::new());
+	}
+
+	let properties = <Pallet<T>>::filter_user_properties(
+		collection_id,
+		/* token_id = */ None,
+		filter_keys,
+		|key, value| RmrkPropertyInfo { key, value },
+	)?;
+
+	Ok(properties)
+}
+
+pub fn nft_properties<T: Config>(
+	collection_id: RmrkCollectionId,
+	nft_id: RmrkNftId,
+	filter_keys: Option<Vec<RmrkPropertyKey>>,
+) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {
+	let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {
+		Ok(id) => id,
+		Err(_) => return Ok(Vec::new()),
+	};
+	let token_id = TokenId(nft_id);
+
+	if <Pallet<T>>::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {
+		return Ok(Vec::new());
+	}
+
+	let properties = <Pallet<T>>::filter_user_properties(
+		collection_id,
+		Some(token_id),
+		filter_keys,
+		|key, value| RmrkPropertyInfo { key, value },
+	)?;
+
+	Ok(properties)
+}
+
+pub fn nft_resources<T: Config>(
+	collection_id: RmrkCollectionId,
+	nft_id: RmrkNftId,
+) -> Result<Vec<RmrkResourceInfo>, DispatchError> {
+	let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {
+		Ok(id) => id,
+		Err(_) => return Ok(Vec::new()),
+	};
+	if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {
+		return Ok(Vec::new());
+	}
+
+	let nft_id = TokenId(nft_id);
+	if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {
+		return Ok(Vec::new());
+	}
+
+	let resources = <pallet_nonfungible::Pallet<T>>::iterate_token_aux_properties(
+		collection_id,
+		nft_id,
+		PropertyScope::Rmrk,
+	)
+	.filter_map(|(_, value)| {
+		let resource_info: RmrkResourceInfo = <Pallet<T>>::decode_property(&value).ok()?;
+
+		Some(resource_info)
+	})
+	.collect();
+
+	Ok(resources)
+}
+
+pub fn nft_resource_priority<T: Config>(
+	collection_id: RmrkCollectionId,
+	nft_id: RmrkNftId,
+	resource_id: RmrkResourceId,
+) -> Result<Option<u32>, DispatchError> {
+	let collection_id = match <Pallet<T>>::unique_collection_id(collection_id) {
+		Ok(id) => id,
+		Err(_) => return Ok(None),
+	};
+	if <Pallet<T>>::ensure_collection_type(collection_id, misc::CollectionType::Regular).is_err() {
+		return Ok(None);
+	}
+
+	let nft_id = TokenId(nft_id);
+	if <Pallet<T>>::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() {
+		return Ok(None);
+	}
+
+	let priorities: Vec<_> = <Pallet<T>>::get_nft_property_decoded(
+		collection_id,
+		nft_id,
+		RmrkProperty::ResourcePriorities,
+	)?;
+	Ok(priorities
+		.into_iter()
+		.enumerate()
+		.find(|(_, id)| *id == resource_id)
+		.map(|(priority, _): (usize, RmrkResourceId)| priority as u32))
+}
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -34,6 +34,7 @@
 
 #[cfg(feature = "runtime-benchmarks")]
 pub mod benchmarking;
+pub mod rpc;
 pub mod weights;
 
 pub type SelfWeightOf<T> = <T as Config>::WeightInfo;
addedpallets/proxy-rmrk-equip/src/rpc.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/proxy-rmrk-equip/src/rpc.rs
@@ -0,0 +1,186 @@
+use super::*;
+use pallet_rmrk_core::{misc, property::*};
+use sp_std::vec::Vec;
+
+pub fn base<T: Config>(
+	base_id: RmrkBaseId,
+) -> Result<Option<RmrkBaseInfo<T::AccountId>>, DispatchError> {
+	let (collection, collection_id) =
+		match <PalletCore<T>>::get_typed_nft_collection_mapped(base_id, misc::CollectionType::Base)
+		{
+			Ok(c) => c,
+			Err(_) => return Ok(None),
+		};
+
+	Ok(Some(RmrkBaseInfo {
+		issuer: collection.owner.clone(),
+		base_type: <PalletCore<T>>::get_collection_property_decoded(
+			collection_id,
+			RmrkProperty::BaseType,
+		)?,
+		symbol: <PalletCore<T>>::rebind(&collection.token_prefix)?,
+	}))
+}
+
+pub fn base_parts<T: Config>(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {
+	use pallet_common::CommonCollectionOperations;
+
+	let (collection, collection_id) =
+		match <PalletCore<T>>::get_typed_nft_collection_mapped(base_id, misc::CollectionType::Base)
+		{
+			Ok(c) => c,
+			Err(_) => return Ok(Vec::new()),
+		};
+
+	let parts = collection
+		.collection_tokens()
+		.into_iter()
+		.filter_map(|token_id| {
+			let nft_type = <PalletCore<T>>::get_nft_type(collection_id, token_id).ok()?;
+
+			match nft_type {
+				NftType::FixedPart => Some(RmrkPartType::FixedPart(RmrkFixedPart {
+					id: <PalletCore<T>>::get_nft_property_decoded(
+						collection_id,
+						token_id,
+						RmrkProperty::ExternalPartId,
+					)
+					.ok()?,
+					src: <PalletCore<T>>::get_nft_property_decoded(
+						collection_id,
+						token_id,
+						RmrkProperty::Src,
+					)
+					.ok()?,
+					z: <PalletCore<T>>::get_nft_property_decoded(
+						collection_id,
+						token_id,
+						RmrkProperty::ZIndex,
+					)
+					.ok()?,
+				})),
+				NftType::SlotPart => Some(RmrkPartType::SlotPart(RmrkSlotPart {
+					id: <PalletCore<T>>::get_nft_property_decoded(
+						collection_id,
+						token_id,
+						RmrkProperty::ExternalPartId,
+					)
+					.ok()?,
+					src: <PalletCore<T>>::get_nft_property_decoded(
+						collection_id,
+						token_id,
+						RmrkProperty::Src,
+					)
+					.ok()?,
+					z: <PalletCore<T>>::get_nft_property_decoded(
+						collection_id,
+						token_id,
+						RmrkProperty::ZIndex,
+					)
+					.ok()?,
+					equippable: <PalletCore<T>>::get_nft_property_decoded(
+						collection_id,
+						token_id,
+						RmrkProperty::EquippableList,
+					)
+					.ok()?,
+				})),
+				_ => None,
+			}
+		})
+		.collect();
+
+	Ok(parts)
+}
+
+pub fn theme_names<T: Config>(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {
+	use pallet_common::CommonCollectionOperations;
+
+	let (collection, collection_id) =
+		match <PalletCore<T>>::get_typed_nft_collection_mapped(base_id, misc::CollectionType::Base)
+		{
+			Ok(c) => c,
+			Err(_) => return Ok(Vec::new()),
+		};
+
+	let theme_names = collection
+		.collection_tokens()
+		.iter()
+		.filter_map(|token_id| {
+			let nft_type = <PalletCore<T>>::get_nft_type(collection_id, *token_id).ok()?;
+
+			match nft_type {
+				NftType::Theme => <PalletCore<T>>::get_nft_property_decoded(
+					collection_id,
+					*token_id,
+					RmrkProperty::ThemeName,
+				)
+				.ok(),
+				_ => None,
+			}
+		})
+		.collect();
+
+	Ok(theme_names)
+}
+
+pub fn theme<T: Config>(
+	base_id: RmrkBaseId,
+	theme_name: RmrkThemeName,
+	filter_keys: Option<Vec<RmrkPropertyKey>>,
+) -> Result<Option<RmrkTheme>, DispatchError> {
+	use pallet_common::CommonCollectionOperations;
+
+	let (collection, collection_id) =
+		match <PalletCore<T>>::get_typed_nft_collection_mapped(base_id, misc::CollectionType::Base)
+		{
+			Ok(c) => c,
+			Err(_) => return Ok(None),
+		};
+
+	let theme_info = collection
+		.collection_tokens()
+		.into_iter()
+		.find_map(|token_id| {
+			<PalletCore<T>>::ensure_nft_type(collection_id, token_id, NftType::Theme).ok()?;
+
+			let name: RmrkString = <PalletCore<T>>::get_nft_property_decoded(
+				collection_id,
+				token_id,
+				RmrkProperty::ThemeName,
+			)
+			.ok()?;
+
+			if name == theme_name {
+				Some((name, token_id))
+			} else {
+				None
+			}
+		});
+
+	let (name, theme_id) = match theme_info {
+		Some((name, theme_id)) => (name, theme_id),
+		None => return Ok(None),
+	};
+
+	let properties = <PalletCore<T>>::filter_user_properties(
+		collection_id,
+		Some(theme_id),
+		filter_keys,
+		|key, value| RmrkThemeProperty { key, value },
+	)?;
+
+	let inherit = <PalletCore<T>>::get_nft_property_decoded(
+		collection_id,
+		theme_id,
+		RmrkProperty::ThemeInherit,
+	)?;
+
+	let theme = RmrkTheme {
+		name,
+		properties,
+		inherit,
+	};
+
+	Ok(Some(theme))
+}
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -74,9 +74,8 @@
 	CollectionStats, RpcCollection,
 	mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
 	TokenChild, RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo,
-	RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkThemeProperty, RmrkCollectionId,
-	RmrkNftId, RmrkAccountIdOrCollectionNftTuple, RmrkNftChild, RmrkPropertyKey, RmrkResourceId,
-	RmrkBaseId, RmrkFixedPart, RmrkSlotPart, RmrkString,
+	RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkCollectionId, RmrkNftId,
+	RmrkNftChild, RmrkPropertyKey, RmrkResourceId, RmrkBaseId,
 };
 
 // use pallet_contracts::weights::WeightInfo;
@@ -1330,352 +1329,55 @@
 		RmrkTheme
 	> for Runtime {
 		fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {
-			Ok(RmrkCore::last_collection_idx())
+			pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>()
 		}
 
 		fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {
-			use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};
-			use pallet_common::CommonCollectionOperations;
-
-			let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {
-				Ok(c) => c,
-				Err(_) => return Ok(None),
-			};
-
-			let nfts_count = collection.total_supply();
-
-			Ok(Some(RmrkCollectionInfo {
-				issuer: collection.owner.clone(),
-				metadata: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::Metadata)?,
-				max: collection.limits.token_limit,
-				symbol: RmrkCore::rebind(&collection.token_prefix)?,
-				nfts_count
-			}))
+			pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id)
 		}
 
 		fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {
-			use up_data_structs::mapping::TokenAddressMapping;
-			use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};
-			use pallet_common::CommonCollectionOperations;
-
-			let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {
-				Ok(c) => c,
-				Err(_) => return Ok(None),
-			};
-
-			let nft_id = TokenId(nft_by_id);
-			if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }
-
-			let owner = match collection.token_owner(nft_id) {
-				Some(owner) => match <Runtime as pallet_common::Config>::CrossTokenAddressMapping::address_to_token(&owner) {
-					Some((col, tok)) => {
-						let rmrk_collection = RmrkCore::rmrk_collection_id(col)?;
-
-						RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)
-					}
-					None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone())
-				},
-				None => return Ok(None)
-			};
-
-			Ok(Some(RmrkInstanceInfo {
-				owner: owner,
-				royalty: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::RoyaltyInfo)?,
-				metadata: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Metadata)?,
-				equipped: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Equipped)?,
-				pending: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::PendingNftAccept)?,
-			}))
+			pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id)
 		}
 
 		fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {
-			use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};
-			use pallet_common::CommonCollectionOperations;
-
-			let cross_account_id = CrossAccountId::from_sub(account_id);
-
-			let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {
-				Ok(c) => c,
-				Err(_) => return Ok(Vec::new()),
-			};
-
-			let tokens = collection.account_tokens(cross_account_id)
-				.into_iter()
-				.filter(|token| {
-					let is_pending = RmrkCore::get_nft_property_decoded(
-						collection_id,
-						*token,
-						RmrkProperty::PendingNftAccept
-					).unwrap_or(true);
-
-					!is_pending
-				})
-				.map(|token| token.0)
-				.collect();
-
-			Ok(tokens)
+			pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id)
 		}
 
 		fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {
-			use pallet_proxy_rmrk_core::RmrkProperty;
-
-			let collection_id = match RmrkCore::unique_collection_id(collection_id) {
-				Ok(id) => id,
-				Err(_) => return Ok(Vec::new())
-			};
-			let nft_id = TokenId(nft_id);
-			if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }
-
-			Ok(
-				pallet_nonfungible::TokenChildren::<Runtime>::iter_prefix((collection_id, nft_id))
-					.filter_map(|((child_collection, child_token), _)| {
-						let is_pending = RmrkCore::get_nft_property_decoded(
-							child_collection,
-							child_token,
-							RmrkProperty::PendingNftAccept
-						).ok()?;
-
-						if is_pending {
-							return None;
-						}
-
-						let rmrk_child_collection = RmrkCore::rmrk_collection_id(
-							child_collection
-						).ok()?;
-
-						Some(RmrkNftChild {
-							collection_id: rmrk_child_collection,
-							nft_id: child_token.0,
-						})
-					}).collect()
-			)
+			pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id)
 		}
 
 		fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {
-			use pallet_proxy_rmrk_core::misc::CollectionType;
-
-			let collection_id = match RmrkCore::unique_collection_id(collection_id) {
-				Ok(id) => id,
-				Err(_) => return Ok(Vec::new())
-			};
-			if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() {
-				return Ok(Vec::new());
-			}
-
-			let properties = RmrkCore::filter_user_properties(
-				collection_id,
-				/* token_id = */ None,
-				filter_keys,
-				|key, value| RmrkPropertyInfo {
-					key,
-					value
-				}
-			)?;
-
-			Ok(properties)
+			pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys)
 		}
 
 		fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {
-			use pallet_proxy_rmrk_core::misc::NftType;
-
-			let collection_id = match RmrkCore::unique_collection_id(collection_id) {
-				Ok(id) => id,
-				Err(_) => return Ok(Vec::new())
-			};
-			let token_id = TokenId(nft_id);
-
-			if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {
-				return Ok(Vec::new());
-			}
-
-			let properties = RmrkCore::filter_user_properties(
-				collection_id,
-				Some(token_id),
-				filter_keys,
-				|key, value| RmrkPropertyInfo {
-					key,
-					value
-				}
-			)?;
-
-			Ok(properties)
+			pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys)
 		}
 
 		fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {
-			use pallet_proxy_rmrk_core::misc::{CollectionType, NftType};
-			use up_data_structs::PropertyScope;
-
-			let collection_id = match RmrkCore::unique_collection_id(collection_id) {
-				Ok(id) => id,
-				Err(_) => return Ok(Vec::new())
-			};
-			if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(Vec::new()); }
-
-			let nft_id = TokenId(nft_id);
-			if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }
-
-			let resources = <pallet_nonfungible::Pallet<Runtime>>::iterate_token_aux_properties(
-				collection_id, nft_id, PropertyScope::Rmrk
-			).filter_map(|(_, value)| {
-				let resource_info: RmrkResourceInfo = RmrkCore::decode_property(&value).ok()?;
-
-				Some(resource_info)
-			}).collect();
-
-			Ok(resources)
+			pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id)
 		}
 
 		fn nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Result<Option<u32>, DispatchError> {
-			use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};
-
-			let collection_id = match RmrkCore::unique_collection_id(collection_id) {
-				Ok(id) => id,
-				Err(_) => return Ok(None)
-			};
-			if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(None); }
-
-			let nft_id = TokenId(nft_id);
-			if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(None); }
-
-			let priorities: Vec<_> = RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::ResourcePriorities)?;
-			Ok(
-				priorities.into_iter()
-					.enumerate()
-					.find(|(_, id)| *id == resource_id)
-					.map(|(priority, _): (usize, RmrkResourceId)| priority as u32)
-			)
+			pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id)
 		}
 
 		fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {
-			use pallet_proxy_rmrk_core::{
-				RmrkProperty, misc::{CollectionType},
-			};
-
-			let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
-				Ok(c) => c,
-				Err(_) => return Ok(None),
-			};
-
-			Ok(Some(RmrkBaseInfo {
-				issuer: collection.owner.clone(),
-				base_type: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::BaseType)?,
-				symbol: RmrkCore::rebind(&collection.token_prefix)?,
-			}))
+			pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id)
 		}
 
 		fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {
-			use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};
-			use pallet_common::CommonCollectionOperations;
-
-			let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
-				Ok(c) => c,
-				Err(_) => return Ok(Vec::new()),
-			};
-
-			let parts = collection.collection_tokens()
-				.into_iter()
-				.filter_map(|token_id| {
-					let nft_type = RmrkCore::get_nft_type(collection_id, token_id).ok()?;
-
-					match nft_type {
-						NftType::FixedPart => Some(RmrkPartType::FixedPart(RmrkFixedPart {
-							id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,
-							src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,
-							z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,
-						})),
-						NftType::SlotPart => Some(RmrkPartType::SlotPart(RmrkSlotPart {
-							id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,
-							src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,
-							z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,
-							equippable: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::EquippableList).ok()?,
-						})),
-						_ => None
-					}
-				})
-				.collect();
-
-			Ok(parts)
+			pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id)
 		}
 
 		fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {
-			use pallet_proxy_rmrk_core::{RmrkProperty, misc::{NftType, CollectionType}};
-			use pallet_common::CommonCollectionOperations;
-
-			let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
-				Ok(c) => c,
-				Err(_) => return Ok(Vec::new()),
-			};
-
-			let theme_names = collection.collection_tokens()
-				.iter()
-				.filter_map(|token_id| {
-					let nft_type = RmrkCore::get_nft_type(collection_id, *token_id).ok()?;
-
-					match nft_type {
-						NftType::Theme => RmrkCore::get_nft_property_decoded(collection_id, *token_id, RmrkProperty::ThemeName).ok(),
-						_ => None
-					}
-				})
-				.collect();
-
-			Ok(theme_names)
+			pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id)
 		}
 
 		fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {
-			use pallet_proxy_rmrk_core::{
-				RmrkProperty,
-				misc::{CollectionType, NftType}
-			};
-			use pallet_common::CommonCollectionOperations;
-
-			let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
-				Ok(c) => c,
-				Err(_) => return Ok(None),
-			};
-
-			let theme_info = collection.collection_tokens()
-				.into_iter()
-				.find_map(|token_id| {
-					RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Theme).ok()?;
-
-					let name: RmrkString = RmrkCore::get_nft_property_decoded(
-						collection_id, token_id, RmrkProperty::ThemeName
-					).ok()?;
-
-					if name == theme_name {
-						Some((name, token_id))
-					} else {
-						None
-					}
-				});
-
-			let (name, theme_id) = match theme_info {
-				Some((name, theme_id)) => (name, theme_id),
-				None => return Ok(None)
-			};
-
-			let properties = RmrkCore::filter_user_properties(
-				collection_id,
-				Some(theme_id),
-				filter_keys,
-				|key, value| RmrkThemeProperty {
-					key,
-					value
-				}
-			)?;
-
-			let inherit = RmrkCore::get_nft_property_decoded(
-				collection_id,
-				theme_id,
-				RmrkProperty::ThemeInherit
-			)?;
-
-			let theme = RmrkTheme {
-				name,
-				properties,
-				inherit,
-			};
-
-			Ok(Some(theme))
+			pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys)
 		}
 	}
 }
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
74 CollectionStats, RpcCollection,74 CollectionStats, RpcCollection,
75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
76 TokenChild, RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo,76 TokenChild, RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo,
77 RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkThemeProperty, RmrkCollectionId,77 RmrkBaseInfo, RmrkPartType, RmrkTheme, RmrkThemeName, RmrkCollectionId, RmrkNftId,
78 RmrkNftId, RmrkAccountIdOrCollectionNftTuple, RmrkNftChild, RmrkPropertyKey, RmrkResourceId,78 RmrkNftChild, RmrkPropertyKey, RmrkResourceId, RmrkBaseId,
79 RmrkBaseId, RmrkFixedPart, RmrkSlotPart, RmrkString,
80};79};
8180
82// use pallet_contracts::weights::WeightInfo;81// use pallet_contracts::weights::WeightInfo;
1330 RmrkTheme1329 RmrkTheme
1331 > for Runtime {1330 > for Runtime {
1332 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {1331 fn last_collection_idx() -> Result<RmrkCollectionId, DispatchError> {
1333 Ok(RmrkCore::last_collection_idx())1332 pallet_proxy_rmrk_core::rpc::last_collection_idx::<Runtime>()
1334 }1333 }
13351334
1336 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {1335 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {
1337 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1336 pallet_proxy_rmrk_core::rpc::collection_by_id::<Runtime>(collection_id)
1338 use pallet_common::CommonCollectionOperations;
1339
1340 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {
1341 Ok(c) => c,
1342 Err(_) => return Ok(None),
1343 };
1344
1345 let nfts_count = collection.total_supply();
1346
1347 Ok(Some(RmrkCollectionInfo {
1348 issuer: collection.owner.clone(),
1349 metadata: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::Metadata)?,
1350 max: collection.limits.token_limit,
1351 symbol: RmrkCore::rebind(&collection.token_prefix)?,
1352 nfts_count
1353 }))
1354 }1337 }
13551338
1356 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {1339 fn nft_by_id(collection_id: RmrkCollectionId, nft_by_id: RmrkNftId) -> Result<Option<RmrkInstanceInfo<AccountId>>, DispatchError> {
1357 use up_data_structs::mapping::TokenAddressMapping;
1358 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1340 pallet_proxy_rmrk_core::rpc::nft_by_id::<Runtime>(collection_id, nft_by_id)
1359 use pallet_common::CommonCollectionOperations;
1360
1361 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {
1362 Ok(c) => c,
1363 Err(_) => return Ok(None),
1364 };
1365
1366 let nft_id = TokenId(nft_by_id);
1367 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }
1368
1369 let owner = match collection.token_owner(nft_id) {
1370 Some(owner) => match <Runtime as pallet_common::Config>::CrossTokenAddressMapping::address_to_token(&owner) {
1371 Some((col, tok)) => {
1372 let rmrk_collection = RmrkCore::rmrk_collection_id(col)?;
1373
1374 RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(rmrk_collection, tok.0)
1375 }
1376 None => RmrkAccountIdOrCollectionNftTuple::AccountId(owner.as_sub().clone())
1377 },
1378 None => return Ok(None)
1379 };
1380
1381 Ok(Some(RmrkInstanceInfo {
1382 owner: owner,
1383 royalty: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::RoyaltyInfo)?,
1384 metadata: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Metadata)?,
1385 equipped: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::Equipped)?,
1386 pending: RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::PendingNftAccept)?,
1387 }))
1388 }1341 }
13891342
1390 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {1343 fn account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Result<Vec<RmrkNftId>, DispatchError> {
1391 use pallet_proxy_rmrk_core::{RmrkProperty, misc::CollectionType};1344 pallet_proxy_rmrk_core::rpc::account_tokens::<Runtime>(account_id, collection_id)
1392 use pallet_common::CommonCollectionOperations;
1393
1394 let cross_account_id = CrossAccountId::from_sub(account_id);
1395
1396 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(collection_id, CollectionType::Regular) {
1397 Ok(c) => c,
1398 Err(_) => return Ok(Vec::new()),
1399 };
1400
1401 let tokens = collection.account_tokens(cross_account_id)
1402 .into_iter()
1403 .filter(|token| {
1404 let is_pending = RmrkCore::get_nft_property_decoded(
1405 collection_id,
1406 *token,
1407 RmrkProperty::PendingNftAccept
1408 ).unwrap_or(true);
1409
1410 !is_pending
1411 })
1412 .map(|token| token.0)
1413 .collect();
1414
1415 Ok(tokens)
1416 }1345 }
14171346
1418 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {1347 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {
1419 use pallet_proxy_rmrk_core::RmrkProperty;1348 pallet_proxy_rmrk_core::rpc::nft_children::<Runtime>(collection_id, nft_id)
1420
1421 let collection_id = match RmrkCore::unique_collection_id(collection_id) {
1422 Ok(id) => id,
1423 Err(_) => return Ok(Vec::new())
1424 };
1425 let nft_id = TokenId(nft_id);
1426 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }
1427
1428 Ok(
1429 pallet_nonfungible::TokenChildren::<Runtime>::iter_prefix((collection_id, nft_id))
1430 .filter_map(|((child_collection, child_token), _)| {
1431 let is_pending = RmrkCore::get_nft_property_decoded(
1432 child_collection,
1433 child_token,
1434 RmrkProperty::PendingNftAccept
1435 ).ok()?;
1436
1437 if is_pending {
1438 return None;
1439 }
1440
1441 let rmrk_child_collection = RmrkCore::rmrk_collection_id(
1442 child_collection
1443 ).ok()?;
1444
1445 Some(RmrkNftChild {
1446 collection_id: rmrk_child_collection,
1447 nft_id: child_token.0,
1448 })
1449 }).collect()
1450 )
1451 }1349 }
14521350
1453 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1351 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {
1454 use pallet_proxy_rmrk_core::misc::CollectionType;1352 pallet_proxy_rmrk_core::rpc::collection_properties::<Runtime>(collection_id, filter_keys)
1455
1456 let collection_id = match RmrkCore::unique_collection_id(collection_id) {
1457 Ok(id) => id,
1458 Err(_) => return Ok(Vec::new())
1459 };
1460 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() {
1461 return Ok(Vec::new());
1462 }
1463
1464 let properties = RmrkCore::filter_user_properties(
1465 collection_id,
1466 /* token_id = */ None,
1467 filter_keys,
1468 |key, value| RmrkPropertyInfo {
1469 key,
1470 value
1471 }
1472 )?;
1473
1474 Ok(properties)
1475 }1353 }
14761354
1477 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {1355 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {
1478 use pallet_proxy_rmrk_core::misc::NftType;1356 pallet_proxy_rmrk_core::rpc::nft_properties::<Runtime>(collection_id, nft_id, filter_keys)
1479
1480 let collection_id = match RmrkCore::unique_collection_id(collection_id) {
1481 Ok(id) => id,
1482 Err(_) => return Ok(Vec::new())
1483 };
1484 let token_id = TokenId(nft_id);
1485
1486 if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {
1487 return Ok(Vec::new());
1488 }
1489
1490 let properties = RmrkCore::filter_user_properties(
1491 collection_id,
1492 Some(token_id),
1493 filter_keys,
1494 |key, value| RmrkPropertyInfo {
1495 key,
1496 value
1497 }
1498 )?;
1499
1500 Ok(properties)
1501 }1357 }
15021358
1503 fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {1359 fn nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceInfo>, DispatchError> {
1504 use pallet_proxy_rmrk_core::misc::{CollectionType, NftType};1360 pallet_proxy_rmrk_core::rpc::nft_resources::<Runtime>(collection_id, nft_id)
1505 use up_data_structs::PropertyScope;
1506
1507 let collection_id = match RmrkCore::unique_collection_id(collection_id) {
1508 Ok(id) => id,
1509 Err(_) => return Ok(Vec::new())
1510 };
1511 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(Vec::new()); }
1512
1513 let nft_id = TokenId(nft_id);
1514 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(Vec::new()); }
1515
1516 let resources = <pallet_nonfungible::Pallet<Runtime>>::iterate_token_aux_properties(
1517 collection_id, nft_id, PropertyScope::Rmrk
1518 ).filter_map(|(_, value)| {
1519 let resource_info: RmrkResourceInfo = RmrkCore::decode_property(&value).ok()?;
1520
1521 Some(resource_info)
1522 }).collect();
1523
1524 Ok(resources)
1525 }1361 }
15261362
1527 fn nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Result<Option<u32>, DispatchError> {1363 fn nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Result<Option<u32>, DispatchError> {
1528 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};1364 pallet_proxy_rmrk_core::rpc::nft_resource_priority::<Runtime>(collection_id, nft_id, resource_id)
1529
1530 let collection_id = match RmrkCore::unique_collection_id(collection_id) {
1531 Ok(id) => id,
1532 Err(_) => return Ok(None)
1533 };
1534 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(None); }
1535
1536 let nft_id = TokenId(nft_id);
1537 if RmrkCore::ensure_nft_type(collection_id, nft_id, NftType::Regular).is_err() { return Ok(None); }
1538
1539 let priorities: Vec<_> = RmrkCore::get_nft_property_decoded(collection_id, nft_id, RmrkProperty::ResourcePriorities)?;
1540 Ok(
1541 priorities.into_iter()
1542 .enumerate()
1543 .find(|(_, id)| *id == resource_id)
1544 .map(|(priority, _): (usize, RmrkResourceId)| priority as u32)
1545 )
1546 }1365 }
15471366
1548 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {1367 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {
1549 use pallet_proxy_rmrk_core::{1368 pallet_proxy_rmrk_equip::rpc::base::<Runtime>(base_id)
1550 RmrkProperty, misc::{CollectionType},
1551 };
1552
1553 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
1554 Ok(c) => c,
1555 Err(_) => return Ok(None),
1556 };
1557
1558 Ok(Some(RmrkBaseInfo {
1559 issuer: collection.owner.clone(),
1560 base_type: RmrkCore::get_collection_property_decoded(collection_id, RmrkProperty::BaseType)?,
1561 symbol: RmrkCore::rebind(&collection.token_prefix)?,
1562 }))
1563 }1369 }
15641370
1565 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {1371 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {
1566 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType}};1372 pallet_proxy_rmrk_equip::rpc::base_parts::<Runtime>(base_id)
1567 use pallet_common::CommonCollectionOperations;
1568
1569 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
1570 Ok(c) => c,
1571 Err(_) => return Ok(Vec::new()),
1572 };
1573
1574 let parts = collection.collection_tokens()
1575 .into_iter()
1576 .filter_map(|token_id| {
1577 let nft_type = RmrkCore::get_nft_type(collection_id, token_id).ok()?;
1578
1579 match nft_type {
1580 NftType::FixedPart => Some(RmrkPartType::FixedPart(RmrkFixedPart {
1581 id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,
1582 src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,
1583 z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,
1584 })),
1585 NftType::SlotPart => Some(RmrkPartType::SlotPart(RmrkSlotPart {
1586 id: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?,
1587 src: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::Src).ok()?,
1588 z: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::ZIndex).ok()?,
1589 equippable: RmrkCore::get_nft_property_decoded(collection_id, token_id, RmrkProperty::EquippableList).ok()?,
1590 })),
1591 _ => None
1592 }
1593 })
1594 .collect();
1595
1596 Ok(parts)
1597 }1373 }
15981374
1599 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {1375 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {
1600 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{NftType, CollectionType}};1376 pallet_proxy_rmrk_equip::rpc::theme_names::<Runtime>(base_id)
1601 use pallet_common::CommonCollectionOperations;
1602
1603 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
1604 Ok(c) => c,
1605 Err(_) => return Ok(Vec::new()),
1606 };
1607
1608 let theme_names = collection.collection_tokens()
1609 .iter()
1610 .filter_map(|token_id| {
1611 let nft_type = RmrkCore::get_nft_type(collection_id, *token_id).ok()?;
1612
1613 match nft_type {
1614 NftType::Theme => RmrkCore::get_nft_property_decoded(collection_id, *token_id, RmrkProperty::ThemeName).ok(),
1615 _ => None
1616 }
1617 })
1618 .collect();
1619
1620 Ok(theme_names)
1621 }1377 }
16221378
1623 fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {1379 fn theme(base_id: RmrkBaseId, theme_name: RmrkThemeName, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Option<RmrkTheme>, DispatchError> {
1624 use pallet_proxy_rmrk_core::{1380 pallet_proxy_rmrk_equip::rpc::theme::<Runtime>(base_id, theme_name, filter_keys)
1625 RmrkProperty,
1626 misc::{CollectionType, NftType}
1627 };
1628 use pallet_common::CommonCollectionOperations;
1629
1630 let (collection, collection_id) = match RmrkCore::get_typed_nft_collection_mapped(base_id, CollectionType::Base) {
1631 Ok(c) => c,
1632 Err(_) => return Ok(None),
1633 };
1634
1635 let theme_info = collection.collection_tokens()
1636 .into_iter()
1637 .find_map(|token_id| {
1638 RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Theme).ok()?;
1639
1640 let name: RmrkString = RmrkCore::get_nft_property_decoded(
1641 collection_id, token_id, RmrkProperty::ThemeName
1642 ).ok()?;
1643
1644 if name == theme_name {
1645 Some((name, token_id))
1646 } else {
1647 None
1648 }
1649 });
1650
1651 let (name, theme_id) = match theme_info {
1652 Some((name, theme_id)) => (name, theme_id),
1653 None => return Ok(None)
1654 };
1655
1656 let properties = RmrkCore::filter_user_properties(
1657 collection_id,
1658 Some(theme_id),
1659 filter_keys,
1660 |key, value| RmrkThemeProperty {
1661 key,
1662 value
1663 }
1664 )?;
1665
1666 let inherit = RmrkCore::get_nft_property_decoded(
1667 collection_id,
1668 theme_id,
1669 RmrkProperty::ThemeInherit
1670 )?;
1671
1672 let theme = RmrkTheme {
1673 name,
1674 properties,
1675 inherit,
1676 };
1677
1678 Ok(Some(theme))
1679 }1381 }
1680 }1382 }
1681}1383}