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

difftreelog

source

pallets/proxy-rmrk-core/src/property.rs2.7 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;1920const RESOURCE_ID_PREFIX: &str = "rsid-";2122pub enum RmrkProperty<'r> {23	Metadata,24	CollectionType,25	RmrkInternalCollectionId,26	TokenType,27	Transferable,28	RoyaltyInfo,29	Equipped,30	ResourcePriorities,31	NextResourceId,32	ResourceId(RmrkResourceId),33	PendingNftAccept,34	Parts,35	Base,36	Src,37	EquippedNft,38	BaseType,39	ExternalPartId,40	EquippableList,41	ZIndex,42	ThemeName,43	ThemeInherit,44	UserProperty(&'r [u8]),45}4647impl<'r> RmrkProperty<'r> {48	pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {49		fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {50			container.as_ref()51		}5253		macro_rules! key {54            ($($component:expr),+) => {55                PropertyKey::try_from([$(key!(@ &$component)),+].concat())56                    .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)57            };5859            (@ $key:expr) => {60                get_bytes($key)61            };62        }6364		match self {65			Self::Metadata => key!("metadata"),66			Self::CollectionType => key!("collection-type"),67			Self::RmrkInternalCollectionId => key!("internal-id"),68			Self::TokenType => key!("token-type"),69			Self::Transferable => key!("transferable"),70			Self::RoyaltyInfo => key!("royalty-info"),71			Self::Equipped => key!("equipped"),72			Self::ResourcePriorities => key!("resource-priorities"),73			Self::NextResourceId => key!("next-resource-id"),74			Self::ResourceId(id) => key!(RESOURCE_ID_PREFIX, id.to_le_bytes()),75			Self::PendingNftAccept => key!("pending-nft-accept"),76			Self::Parts => key!("parts"),77			Self::Base => key!("base"),78			Self::Src => key!("src"),79			Self::EquippedNft => key!("equipped-nft"),80			Self::BaseType => key!("base-type"),81			Self::ExternalPartId => key!("ext-part-id"),82			Self::EquippableList => key!("equippable-list"),83			Self::ZIndex => key!("z-index"),84			Self::ThemeName => key!("theme-name"),85			Self::ThemeInherit => key!("theme-inherit"),86			Self::UserProperty(name) => key!("userprop-", name),87		}88	}89}