git.delta.rocks / unique-network / refs/commits / 3c77c1e2ea04

difftreelog

source

pallets/proxy-rmrk-core/src/misc.rs2.7 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/>.1617//! Miscellaneous helpers and utilities used by the proxy pallet.1819use super::*;20use codec::{Encode, Decode, Error};2122/// Match an error to a provided pattern matcher and get23/// the corresponding error of another type 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 some serialized bytes into an arbitrary type `T`,38/// preferably if these bytes were originally encoded from `T`.39pub trait RmrkDecode<T: Decode, S> {40	/// Try to decode self into an arbitrary type `T`.41	fn decode(&self) -> Result<T, Error>;42}4344impl<T: Decode, S> RmrkDecode<T, S> for BoundedVec<u8, S> {45	fn decode(&self) -> Result<T, Error> {46		let mut value = self.as_slice();4748		T::decode(&mut value)49	}50}5152/// Interface to "rebind" - change the limit of a bounded byte vector.53pub trait RmrkRebind<T, S> {54	/// Try to change the limit of a bounded byte vector.55	fn rebind(&self) -> Result<BoundedVec<u8, S>, Error>;56}5758impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>59where60	BoundedVec<u8, S>: TryFrom<Vec<u8>>,61{62	fn rebind(&self) -> Result<BoundedVec<u8, S>, Error> {63		BoundedVec::<u8, S>::try_from(self.clone().into_inner())64			.map_err(|_| "BoundedVec exceeds its limit".into())65	}66}6768/// RMRK Base shares functionality with a regular collection, and is thus69/// stored as one, but they are used for different purposes and need to be differentiated.70#[derive(Encode, Decode, PartialEq, Eq)]71pub enum CollectionType {72	Regular,73	Base,74}7576/// RMRK Base, being stored as a collection, can have different kinds of tokens,77/// all except the `Regular` type, which is attributed to `Regular` collection.78#[derive(Encode, Decode, PartialEq, Eq)]79pub enum NftType {80	Regular,81	FixedPart,82	SlotPart,83	Theme,84}