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

difftreelog

feat add all rmrk properties

Daniel Shiposha2022-05-19parent: #fc4f875.patch.diff
in: master

4 files changed

modifiedpallets/rmrk-proxy/src/lib.rsdiffbeforeafterboth
27pub use pallet::*;27pub use pallet::*;
2828
29pub mod misc;29pub mod misc;
30pub mod property;
3031
31use misc::*;32use misc::*;
33pub use property::*;
3234
33#[frame_support::pallet]35#[frame_support::pallet]
34pub mod pallet {36pub mod pallet {
69 /* Unique-specific events */71 /* Unique-specific events */
70 CorruptedCollectionType,72 CorruptedCollectionType,
71 NotRmrkCollection,73 NotRmrkCollection,
74 RmrkPropertyIsTooLong,
7275
73 /* RMRK compatible events */76 /* RMRK compatible events */
74 CollectionNotEmpty,77 CollectionNotEmpty,
113 &collection,116 &collection,
114 PropertyScope::Rmrk,117 PropertyScope::Rmrk,
115 [118 [
116 rmrk_property!(Metadata, metadata),119 rmrk_property!(Config=T, Metadata: metadata)?,
117 rmrk_property!(CollectionType, CollectionType::Regular),120 rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,
118 ].into_iter()121 ].into_iter()
119 )?;122 )?;
120123
215218
216 fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {219 fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {
217 let collection_type: CollectionType = <PalletCommon<T>>::collection_properties(collection_id)220 let collection_type: CollectionType = <PalletCommon<T>>::collection_properties(collection_id)
218 .get(&rmrk_property!(CollectionType))221 .get(&rmrk_property!(Config=T, CollectionType)?)
219 .ok_or(<Error<T>>::NotRmrkCollection)?222 .ok_or(<Error<T>>::NotRmrkCollection)?
220 .try_into()223 .try_into()
221 .map_err(<Error<T>>::from)?;224 .map_err(<Error<T>>::from)?;
modifiedpallets/rmrk-proxy/src/misc.rsdiffbeforeafterboth
--- a/pallets/rmrk-proxy/src/misc.rs
+++ b/pallets/rmrk-proxy/src/misc.rs
@@ -1,31 +1,12 @@
 use super::*;
 use codec::{Encode, Decode};
-use frame_support::dispatch::Vec;
 use pallet_nonfungible::NonfungibleHandle;
-
-#[macro_export]
-macro_rules! rmrk_property {
-    ($key:ident, $value:expr) => {
-        Property {
-            key: rmrk_property!(@raw $key),
-            value: $value.into()
-        }
-    };
 
-    (@raw $key:ident) => {
-        RmrkProperty::$key.to_key()
-    };
-
-    ($key:ident) => {
-        PropertyScope::Rmrk.apply(rmrk_property!(@raw $key)).unwrap()
-    };
-}
-
 macro_rules! impl_rmrk_value {
     ($enum_name:path, decode_error: $error:ident) => {
-        impl Into<PropertyValue> for $enum_name {
-            fn into(self) -> PropertyValue {
-                self.encode().try_into().unwrap()
+        impl From<$enum_name> for PropertyValue {
+            fn from(e: $enum_name) -> Self {
+                e.encode().try_into().unwrap()
             }
         }
 
@@ -64,26 +45,6 @@
         match self.mode {
             CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),
             _ => Err(<Error<T>>::NotRmrkCollection)
-        }
-    }
-}
-
-pub enum RmrkProperty {
-    Metadata,
-    CollectionType,
-}
-
-impl RmrkProperty {
-    pub fn to_key(self) -> PropertyKey {
-        let key = |str_key: &str| {
-            PropertyKey::try_from(
-                str_key.bytes().collect::<Vec<_>>()
-            ).unwrap()
-        };
-
-        match self {
-            Self::Metadata => key("metadata"),
-            Self::CollectionType => key("collection-type"),
         }
     }
 }
addedpallets/rmrk-proxy/src/property.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/rmrk-proxy/src/property.rs
@@ -0,0 +1,92 @@
+use super::*;
+use core::convert::AsRef;
+
+pub enum RmrkProperty {
+    Metadata,
+    CollectionType,
+    Recipient,
+    Royalty,
+    Equipped,
+    Pending,
+    ResourceCollection,
+    ResourcePriorities,
+    PendingRemoval,
+    Parts,
+    Base,
+    Src,
+    Slot,
+    License,
+    Thumb,
+    EquippedNft,
+    BaseType,
+    // // RmrkPartId(/* Id type? */)
+    EquippableList,
+    ZIndex,
+    ThemeName,
+    ThemeProperty(RmrkString),
+    ThemeInherit,
+}
+
+impl RmrkProperty {
+    pub fn to_key<T: Config>(self) -> Result<PropertyKey, Error<T>> {
+        fn get_bytes<T: AsRef<[u8]>>(container: &T) -> &[u8] {
+            container.as_ref()
+        }
+
+        macro_rules! key {
+            ($($component:expr),+) => {
+                PropertyKey::try_from([$(key!(@ &$component)),+].concat())
+                    .map_err(|_| <Error<T>>::RmrkPropertyIsTooLong)
+            };
+
+            (@ $key:expr) => {
+                get_bytes($key)
+            };
+        }
+
+        match self {
+            Self::Metadata => key!("metadata"),
+            Self::CollectionType => key!("collection-type"),
+            Self::Recipient => key!("recipient"),
+            Self::Royalty => key!("royalty"),
+            Self::Equipped => key!("equipped"),
+            Self::Pending => key!("pending"),
+            Self::ResourceCollection => key!("resource-collection"),
+            Self::ResourcePriorities => key!("resource-priorities"),
+            Self::PendingRemoval => key!("pending-removal"),
+            Self::Parts => key!("parts"),
+            Self::Base => key!("base"),
+            Self::Src => key!("src"),
+            Self::Slot => key!("slot"),
+            Self::License => key!("license"),
+            Self::Thumb => key!("thumb"),
+            Self::EquippedNft => key!("equipped-nft"),
+            Self::BaseType => key!("base-type"),
+            // RmrkPartId(/* Id type? */)
+            Self::EquippableList => key!("equippable-list"),
+            Self::ZIndex => key!("z-index"),
+            Self::ThemeName => key!("theme-name"),
+            Self::ThemeProperty(name) => key!("theme-property-", name),
+            Self::ThemeInherit => key!("theme-inherit"),
+        }
+    }
+}
+
+#[macro_export]
+macro_rules! rmrk_property {
+    (Config=$cfg:ty, $key:ident: $value:expr) => {
+        rmrk_property!(@$cfg, $key).map(|key| Property {
+            key,
+            value: $value.into()
+        })
+    };
+
+    (@$cfg:ty, $key:ident) => {
+        $crate::RmrkProperty::$key.to_key::<$cfg>()
+    };
+
+    (Config=$cfg:ty, $key:ident) => {
+        PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key)?)
+            .map_err(|_| <Error<T>>::RmrkPropertyIsTooLong)
+    };
+}
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -924,4 +924,4 @@
 pub type RmrkThemeName = RmrkRpcString;
 pub type RmrkPropertyKey = RmrkRpcString;
 
-type RmrkString = BoundedVec<u8, RmrkStringLimit>;
+pub type RmrkString = BoundedVec<u8, RmrkStringLimit>;