git.delta.rocks / unique-network / refs/commits / 9802d7a2367e

difftreelog

source

pallets/proxy-rmrk-core/src/misc.rs1.5 KiBsourcehistory
1use super::*;2use codec::{Encode, Decode};3use pallet_nonfungible::NonfungibleHandle;45macro_rules! impl_rmrk_value {6    ($enum_name:path, decode_error: $error:ident) => {7        impl From<$enum_name> for PropertyValue {8            fn from(e: $enum_name) -> Self {9                e.encode().try_into().unwrap()10            }11        }1213        impl TryFrom<&PropertyValue> for $enum_name {14            type Error = MiscError;1516            fn try_from(value: &PropertyValue) -> Result<Self, Self::Error> {17                let mut value = value.as_slice();1819                <$enum_name>::decode(&mut value)20                    .map_err(|_| MiscError::$error)21            }22        }2324    };25}2627pub enum MiscError {28    CorruptedCollectionType,29}3031impl<T: Config> From<MiscError> for Error<T> {32    fn from(error: MiscError) -> Self {33        match error {34            MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,35        }36    }37}3839pub trait IntoNftCollection<T: Config> {40    fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>>;41}4243impl<T: Config> IntoNftCollection<T> for CollectionHandle<T> {44    fn into_nft_collection(self) -> Result<NonfungibleHandle<T>, Error<T>> {45        match self.mode {46            CollectionMode::NFT => Ok(NonfungibleHandle::cast(self)),47            _ => Err(<Error<T>>::NotRmrkCollection)48        }49    }50}5152#[derive(Encode, Decode, PartialEq, Eq)]53pub enum CollectionType {54    Regular,55    Resource,56    Base,57}5859impl_rmrk_value!(CollectionType, decode_error: CorruptedCollectionType);