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

difftreelog

source

pallets/proxy-rmrk-core/src/property.rs2.8 KiBsourcehistory
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 super::*;18use core::convert::AsRef;1920pub enum RmrkProperty<'r> {21	Metadata,22	CollectionType,23	TokenType,24	Transferable,25	RoyaltyInfo,26	Equipped,27	ResourceCollection,28	ResourcePriorities,29	ResourceType,30	PendingNftAccept,31	PendingResourceAccept,32	PendingResourceRemoval,33	Parts,34	Base,35	Src,36	Slot,37	License,38	Thumb,39	EquippedNft,40	BaseType,41	ExternalPartId,42	EquippableList,43	ZIndex,44	ThemeName,45	ThemeInherit,46	UserProperty(&'r [u8]),47}4849impl<'r> RmrkProperty<'r> {50	pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {51		fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {52			container.as_ref()53		}5455		macro_rules! key {56            ($($component:expr),+) => {57                PropertyKey::try_from([$(key!(@ &$component)),+].concat())58                    .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)59            };6061            (@ $key:expr) => {62                get_bytes($key)63            };64        }6566		match self {67			Self::Metadata => key!("metadata"),68			Self::CollectionType => key!("collection-type"),69			Self::TokenType => key!("token-type"),70			Self::Transferable => key!("transferable"),71			Self::RoyaltyInfo => key!("royalty-info"),72			Self::Equipped => key!("equipped"),73			Self::ResourceCollection => key!("resource-collection"),74			Self::ResourcePriorities => key!("resource-priorities"),75			Self::ResourceType => key!("resource-type"),76			Self::PendingNftAccept => key!("pending-nft-accept"),77			Self::PendingResourceAccept => key!("pending-resource-accept"),78			Self::PendingResourceRemoval => key!("pending-resource-removal"),79			Self::Parts => key!("parts"),80			Self::Base => key!("base"),81			Self::Src => key!("src"),82			Self::Slot => key!("slot"),83			Self::License => key!("license"),84			Self::Thumb => key!("thumb"),85			Self::EquippedNft => key!("equipped-nft"),86			Self::BaseType => key!("base-type"),87			Self::ExternalPartId => key!("ext-part-id"),88			Self::EquippableList => key!("equippable-list"),89			Self::ZIndex => key!("z-index"),90			Self::ThemeName => key!("theme-name"),91			Self::ThemeInherit => key!("theme-inherit"),92			Self::UserProperty(name) => key!("userprop-", name),93		}94	}95}