git.delta.rocks / unique-network / refs/commits / 334927b2e0c4

difftreelog

source

pallets/proxy-rmrk-core/src/misc.rs1.4 KiBsourcehistory
1use super::*;2use codec::{Encode, Decode, Error};34#[macro_export]5macro_rules! map_common_err_to_proxy {6    (match $err:ident { $($common_err:ident => $proxy_err:ident),+ }) => {7        $(8            if $err == <CommonError<T>>::$common_err.into() {9                return <Error<T>>::$proxy_err.into()10            } else11        )+ {12            $err13        }14    };15}1617// Utilize the RmrkCore pallet for access to Runtime errors.18pub trait RmrkDecode<T: Decode, S> {19	fn decode(&self) -> Result<T, Error>;20}2122impl<T: Decode, S> RmrkDecode<T, S> for BoundedVec<u8, S> {23	fn decode(&self) -> Result<T, Error> {24		let mut value = self.as_slice();2526		T::decode(&mut value)27	}28}2930// Utilize the RmrkCore pallet for access to Runtime errors.31pub trait RmrkRebind<T, S> {32	fn rebind(&self) -> Result<BoundedVec<u8, S>, Error>;33}3435impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>36where37	BoundedVec<u8, S>: TryFrom<Vec<u8>>,38{39	fn rebind(&self) -> Result<BoundedVec<u8, S>, Error> {40		BoundedVec::<u8, S>::try_from(self.clone().into_inner()).map_err(|_| "BoundedVec exceeds its limit".into())41	}42}4344#[derive(Encode, Decode, PartialEq, Eq)]45pub enum CollectionType {46	Regular,47	Resource,48	Base,49}5051#[derive(Encode, Decode, PartialEq, Eq)]52pub enum NftType {53	Regular,54	Resource,55	FixedPart,56	SlotPart,57	Theme,58}5960#[derive(Encode, Decode, PartialEq, Eq)]61pub enum ResourceType {62	Basic,63	Composable,64	Slot,65}