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

difftreelog

source

pallets/proxy-rmrk-core/src/misc.rs1.5 KiBsourcehistory
1use super::*;2use codec::{Encode, Decode};3use derivative::Derivative;45#[macro_export]6macro_rules! map_common_err_to_proxy {7    (match $err:ident { $($common_err:ident => $proxy_err:ident),+ }) => {8        $(9            if $err == <CommonError<T>>::$common_err.into() {10                return <Error<T>>::$proxy_err.into()11            } else12        )+ {13            $err14        }15    };16}1718pub trait RmrkDecode<T: Decode + Default, S> {19	fn decode_or_default(&self) -> T;20}2122// todo fail if unwrap doesn't work23impl<T: Decode + Default, S> RmrkDecode<T, S> for BoundedVec<u8, S> {24	fn decode_or_default(&self) -> T {25		let mut value = self.as_slice();2627		T::decode(&mut value).unwrap_or_default()28	}29}3031pub trait RmrkRebind<T, S> {32	fn rebind(&self) -> BoundedVec<u8, S>;33}3435// todo fail if unwrap doesn't work36impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>37where38	BoundedVec<u8, S>: TryFrom<Vec<u8>>,39{40	fn rebind(&self) -> BoundedVec<u8, S> {41		BoundedVec::<u8, S>::try_from(self.clone().into_inner()).unwrap_or_default()42	}43}4445#[derive(Encode, Decode, PartialEq, Eq)]46pub enum CollectionType {47	Regular,48	Resource,49	Base,50}5152// todo remove default?53#[derive(Encode, Decode, PartialEq, Eq, Derivative)]54#[derivative(Default(bound=""))]55pub enum NftType {56	#[derivative(Default)]57	Regular,58	Resource,59	FixedPart,60	SlotPart,61	Theme,62}6364// todo remove default?65#[derive(Encode, Decode, PartialEq, Eq, Derivative)]66#[derivative(Default(bound=""))]67pub enum ResourceType {68	#[derivative(Default)]69	Basic,70	Composable,71	Slot,72}