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/>.1617//! Miscellaneous helpers and utilities used by the proxy pallet.1819use super::*;20use codec::{Encode, Decode, Error};2122/// Match errors from one type to another and return an error 23/// if a match is successful.24#[macro_export]25macro_rules! map_unique_err_to_proxy {26 (match $err:ident { $($unique_err_ty:ident :: $unique_err:ident => $proxy_err:ident),+ $(,)? }) => {27 $(28 if $err == <$unique_err_ty<T>>::$unique_err.into() {29 return <Error<T>>::$proxy_err.into()30 } else31 )+ {32 $err33 }34 };35}3637/// Interface to decode bytes from a bounded vector into an arbitrary type.38pub trait RmrkDecode<T: Decode, S> {39 /// Try to decode bytes from a bounded vector into an arbitrary type.40 fn decode(&self) -> Result<T, Error>;41}4243impl<T: Decode, S> RmrkDecode<T, S> for BoundedVec<u8, S> {44 fn decode(&self) -> Result<T, Error> {45 let mut value = self.as_slice();4647 T::decode(&mut value)48 }49}5051/// Interface to "rebind", change the limit of a bounded byte vector.52pub trait RmrkRebind<T, S> {53 /// Try to change the limit of a bounded byte vector.54 fn rebind(&self) -> Result<BoundedVec<u8, S>, Error>;55}5657impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>58where59 BoundedVec<u8, S>: TryFrom<Vec<u8>>,60{61 fn rebind(&self) -> Result<BoundedVec<u8, S>, Error> {62 BoundedVec::<u8, S>::try_from(self.clone().into_inner())63 .map_err(|_| "BoundedVec exceeds its limit".into())64 }65}6667/// RMRK Base shares functionality with a regular collection, and is thus68/// stored as one, but they are used for different purposes and need to be differentiated.69#[derive(Encode, Decode, PartialEq, Eq)]70pub enum CollectionType {71 Regular,72 Base,73}7475/// RMRK Base, being stored as a collection, can have different kinds of tokens,76/// all except the `Regular` type, which is attributed to `Regular` collection.77#[derive(Encode, Decode, PartialEq, Eq)]78pub enum NftType {79 Regular,80 FixedPart,81 SlotPart,82 Theme,83}difftreelog
source
pallets/proxy-rmrk-core/src/misc.rs2.6 KiBsourcehistory