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

difftreelog

fix(rmrk) use derivative for enum defaults

Daniel Shiposha2022-06-02parent: #4b3d058.patch.diff
in: master

3 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6329,6 +6329,7 @@
 name = "pallet-rmrk-core"
 version = "0.1.0"
 dependencies = [
+ "derivative",
  "frame-benchmarking",
  "frame-support",
  "frame-system",
modifiedpallets/proxy-rmrk-core/Cargo.tomldiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/Cargo.toml
+++ b/pallets/proxy-rmrk-core/Cargo.toml
@@ -23,6 +23,7 @@
 pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.22" }
 frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.22" }
 scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
+derivative = { version = "2.2.0", features = ["use_core"] }
 
 [features]
 default = ["std"]
modifiedpallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth
before · pallets/proxy-rmrk-core/src/misc.rs
1use super::*;2use codec::{Encode, Decode};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}1617pub trait RmrkDecode<T: Decode + Default, S> {18	fn decode_or_default(&self) -> T;19}2021// todo fail if unwrap doesn't work22impl<T: Decode + Default, S> RmrkDecode<T, S> for BoundedVec<u8, S> {23	fn decode_or_default(&self) -> T {24		let mut value = self.as_slice();2526		T::decode(&mut value).unwrap_or_default()27	}28}2930pub trait RmrkRebind<T, S> {31	fn rebind(&self) -> BoundedVec<u8, S>;32}3334// todo fail if unwrap doesn't work35impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T>36where37	BoundedVec<u8, S>: TryFrom<Vec<u8>>,38{39	fn rebind(&self) -> BoundedVec<u8, S> {40		BoundedVec::<u8, S>::try_from(self.clone().into_inner()).unwrap_or_default()41	}42}4344#[derive(Encode, Decode, PartialEq, Eq)]45pub enum CollectionType {46	Regular,47	Resource,48	Base,49}5051// todo remove default?52#[derive(Encode, Decode, PartialEq, Eq, Default)]53pub enum NftType {54	#[default]55	Regular,56	Resource,57	FixedPart,58	SlotPart,59	Theme,60}6162// todo remove default?63#[derive(Encode, Decode, PartialEq, Eq, Default)]64pub enum ResourceType {65	#[default]66	Basic,67	Composable,68	Slot,69}