git.delta.rocks / unique-network / refs/commits / 1861bd960303

difftreelog

source

pallets/proxy-rmrk-core/src/misc.rs2.1 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use super::*;18use codec::{Encode, Decode, Error};1920#[macro_export]21macro_rules! map_unique_err_to_proxy {22    (match $err:ident { $($unique_err_ty:ident :: $unique_err:ident => $proxy_err:ident),+ $(,)? }) => {23        $(24            if $err == <$unique_err_ty<T>>::$unique_err.into() {25                return <Error<T>>::$proxy_err.into()26            } else27        )+ {28            $err29        }30    };31}3233// Utilize the RmrkCore pallet for access to Runtime errors.34pub trait RmrkDecode<T: Decode, S> {35	fn decode(&self) -> Result<T, Error>;36}3738impl<T: Decode, S> RmrkDecode<T, S> for BoundedVec<u8, S> {39	fn decode(&self) -> Result<T, Error> {40		let mut value = self.as_slice();4142		T::decode(&mut value)43	}44}4546// Utilize the RmrkCore pallet for access to Runtime errors.47pub trait RmrkRebind<T, S> {48	fn rebind(&self) -> Result<BoundedVec<u8, S>, Error>;49}5051impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>52where53	BoundedVec<u8, S>: TryFrom<Vec<u8>>,54{55	fn rebind(&self) -> Result<BoundedVec<u8, S>, Error> {56		BoundedVec::<u8, S>::try_from(self.clone().into_inner())57			.map_err(|_| "BoundedVec exceeds its limit".into())58	}59}6061#[derive(Encode, Decode, PartialEq, Eq)]62pub enum CollectionType {63	Regular,64	Resource,65	Base,66}6768#[derive(Encode, Decode, PartialEq, Eq)]69pub enum NftType {70	Regular,71	Resource,72	FixedPart,73	SlotPart,74	Theme,75}7677#[derive(Encode, Decode, PartialEq, Eq)]78pub enum ResourceType {79	Basic,80	Composable,81	Slot,82}