1234567891011121314151617use 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}