difftreelog
feat add resource-type rmrk property
in: master
1 file changed
pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth1use super::*;2use core::convert::AsRef;34pub enum RmrkProperty {5 Metadata,6 CollectionType,7 Recipient,8 Royalty,9 Equipped,10 ResourceCollection,11 ResourcePriorities,12 PendingResourceAccept,13 PendingResourceRemoval,14 Parts,15 Base,16 Src,17 Slot,18 License,19 Thumb,20 EquippedNft,21 BaseType,22 // // RmrkPartId(/* Id type? */)23 EquippableList,24 ZIndex,25 ThemeName,26 ThemeProperty(RmrkString),27 ThemeInherit,28}2930impl RmrkProperty {31 pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {32 fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {33 container.as_ref()34 }3536 macro_rules! key {37 ($($component:expr),+) => {38 PropertyKey::try_from([$(key!(@ &$component)),+].concat())39 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)40 };4142 (@ $key:expr) => {43 get_bytes($key)44 };45 }4647 match self {48 Self::Metadata => key!("metadata"),49 Self::CollectionType => key!("collection-type"),50 Self::Recipient => key!("recipient"),51 Self::Royalty => key!("royalty"),52 Self::Equipped => key!("equipped"),53 Self::ResourceCollection => key!("resource-collection"),54 Self::ResourcePriorities => key!("resource-priorities"),55 Self::PendingResourceAccept => key!("pending-accept"),56 Self::PendingResourceRemoval => key!("pending-removal"),57 Self::Parts => key!("parts"),58 Self::Base => key!("base"),59 Self::Src => key!("src"),60 Self::Slot => key!("slot"),61 Self::License => key!("license"),62 Self::Thumb => key!("thumb"),63 Self::EquippedNft => key!("equipped-nft"),64 Self::BaseType => key!("base-type"),65 // RmrkResourceId(/* Id type? */)66 // RmrkPartId(/* Id type? */)67 Self::EquippableList => key!("equippable-list"),68 Self::ZIndex => key!("z-index"),69 Self::ThemeName => key!("theme-name"),70 Self::ThemeProperty(name) => key!("theme-property-", name),71 Self::ThemeInherit => key!("theme-inherit"),72 }73 }74}7576#[macro_export]77macro_rules! rmrk_property {78 (Config=$cfg:ty, key: $key:ident $(($key_ext:expr))?) => {79 rmrk_property!(Config=$cfg, $crate::RmrkProperty::$key $(($key_ext))?)80 };8182 (Config=$cfg:ty, $key:ident $(($key_ext:expr))?: $value:expr) => {{83 let key = rmrk_property!(@$cfg, $crate::RmrkProperty::$key $(($key_ext))?)?;8485 let value = $value.into_property_value()86 .map_err(<$crate::Error<$cfg>>::from)?;8788 Ok::<_, $crate::Error<$cfg>>(Property {89 key,90 value,91 })92 }};9394 (@$cfg:ty, $key_enum:expr) => {95 $key_enum.to_key::<$cfg>()96 };9798 (Config=$cfg:ty, $key_enum:expr) => {99 PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key_enum)?)100 .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)101 };102}1use super::*;2use core::convert::AsRef;34pub enum RmrkProperty {5 Metadata,6 CollectionType,7 Recipient,8 Royalty,9 Equipped,10 ResourceCollection,11 ResourcePriorities,12 ResourceType,13 PendingResourceAccept,14 PendingResourceRemoval,15 Parts,16 Base,17 Src,18 Slot,19 License,20 Thumb,21 EquippedNft,22 BaseType,23 // // RmrkPartId(/* Id type? */)24 EquippableList,25 ZIndex,26 ThemeName,27 ThemeProperty(RmrkString),28 ThemeInherit,29}3031impl RmrkProperty {32 pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {33 fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {34 container.as_ref()35 }3637 macro_rules! key {38 ($($component:expr),+) => {39 PropertyKey::try_from([$(key!(@ &$component)),+].concat())40 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)41 };4243 (@ $key:expr) => {44 get_bytes($key)45 };46 }4748 match self {49 Self::Metadata => key!("metadata"),50 Self::CollectionType => key!("collection-type"),51 Self::Recipient => key!("recipient"),52 Self::Royalty => key!("royalty"),53 Self::Equipped => key!("equipped"),54 Self::ResourceCollection => key!("resource-collection"),55 Self::ResourcePriorities => key!("resource-priorities"),56 Self::ResourceType => key!("resource-type"),57 Self::PendingResourceAccept => key!("pending-accept"),58 Self::PendingResourceRemoval => key!("pending-removal"),59 Self::Parts => key!("parts"),60 Self::Base => key!("base"),61 Self::Src => key!("src"),62 Self::Slot => key!("slot"),63 Self::License => key!("license"),64 Self::Thumb => key!("thumb"),65 Self::EquippedNft => key!("equipped-nft"),66 Self::BaseType => key!("base-type"),67 // RmrkResourceId(/* Id type? */)68 // RmrkPartId(/* Id type? */)69 Self::EquippableList => key!("equippable-list"),70 Self::ZIndex => key!("z-index"),71 Self::ThemeName => key!("theme-name"),72 Self::ThemeProperty(name) => key!("theme-property-", name),73 Self::ThemeInherit => key!("theme-inherit"),74 }75 }76}7778#[macro_export]79macro_rules! rmrk_property {80 (Config=$cfg:ty, key: $key:ident $(($key_ext:expr))?) => {81 rmrk_property!(Config=$cfg, $crate::RmrkProperty::$key $(($key_ext))?)82 };8384 (Config=$cfg:ty, $key:ident $(($key_ext:expr))?: $value:expr) => {{85 let key = rmrk_property!(@$cfg, $crate::RmrkProperty::$key $(($key_ext))?)?;8687 let value = $value.into_property_value()88 .map_err(<$crate::Error<$cfg>>::from)?;8990 Ok::<_, $crate::Error<$cfg>>(Property {91 key,92 value,93 })94 }};9596 (@$cfg:ty, $key_enum:expr) => {97 $key_enum.to_key::<$cfg>()98 };99100 (Config=$cfg:ty, $key_enum:expr) => {101 PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key_enum)?)102 .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)103 };104}