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
--- a/pallets/rmrk-proxy/src/lib.rs
+++ b/pallets/rmrk-proxy/src/lib.rs
@@ -27,8 +27,10 @@
 pub use pallet::*;
 
 pub mod misc;
+pub mod property;
 
 use misc::*;
+pub use property::*;
 
 #[frame_support::pallet]
 pub mod pallet {
@@ -69,6 +71,7 @@
         /* Unique-specific events */
         CorruptedCollectionType,
         NotRmrkCollection,
+        RmrkPropertyIsTooLong,
 
         /* RMRK compatible events */
         CollectionNotEmpty,
@@ -113,8 +116,8 @@
                 &collection,
                 PropertyScope::Rmrk,
                 [
-                    rmrk_property!(Metadata, metadata),
-                    rmrk_property!(CollectionType, CollectionType::Regular),
+                    rmrk_property!(Config=T, Metadata: metadata)?,
+                    rmrk_property!(Config=T, CollectionType: CollectionType::Regular)?,
                 ].into_iter()
             )?;
 
@@ -215,7 +218,7 @@
 
     fn get_collection_type(collection_id: CollectionId) -> Result<CollectionType, DispatchError> {
         let collection_type: CollectionType = <PalletCommon<T>>::collection_properties(collection_id)
-            .get(&rmrk_property!(CollectionType))
+            .get(&rmrk_property!(Config=T, CollectionType)?)
             .ok_or(<Error<T>>::NotRmrkCollection)?
             .try_into()
             .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
after · pallets/rmrk-proxy/src/property.rs
1use super::*;2use core::convert::AsRef;34pub enum RmrkProperty {5    Metadata,6    CollectionType,7    Recipient,8    Royalty,9    Equipped,10    Pending,11    ResourceCollection,12    ResourcePriorities,13    PendingRemoval,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>>::RmrkPropertyIsTooLong)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::Pending => key!("pending"),54            Self::ResourceCollection => key!("resource-collection"),55            Self::ResourcePriorities => key!("resource-priorities"),56            Self::PendingRemoval => 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            // RmrkPartId(/* Id type? */)66            Self::EquippableList => key!("equippable-list"),67            Self::ZIndex => key!("z-index"),68            Self::ThemeName => key!("theme-name"),69            Self::ThemeProperty(name) => key!("theme-property-", name),70            Self::ThemeInherit => key!("theme-inherit"),71        }72    }73}7475#[macro_export]76macro_rules! rmrk_property {77    (Config=$cfg:ty, $key:ident: $value:expr) => {78        rmrk_property!(@$cfg, $key).map(|key| Property {79            key,80            value: $value.into()81        })82    };8384    (@$cfg:ty, $key:ident) => {85        $crate::RmrkProperty::$key.to_key::<$cfg>()86    };8788    (Config=$cfg:ty, $key:ident) => {89        PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key)?)90            .map_err(|_| <Error<T>>::RmrkPropertyIsTooLong)91    };92}
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>;