difftreelog
fix use rmrk type in proxy
in: master
4 files changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth161617#![cfg_attr(not(feature = "std"), no_std)]17#![cfg_attr(not(feature = "std"), no_std)]181819use frame_support::{pallet_prelude::*, transactional, BoundedVec, traits::ConstU32, dispatch::DispatchResult};19use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};20use frame_system::{pallet_prelude::*, ensure_signed};20use frame_system::{pallet_prelude::*, ensure_signed};21use sp_runtime::DispatchError;21use sp_runtime::{DispatchError, traits::StaticLookup};22use up_data_structs::*;22use up_data_structs::*;23use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};23use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle, CommonCollectionOperations};24use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};24use pallet_nonfungible::{Pallet as PalletNft, NonfungibleHandle};54 pub enum Event<T: Config> {54 pub enum Event<T: Config> {55 CollectionCreated {55 CollectionCreated {56 issuer: T::AccountId,56 issuer: T::AccountId,57 collection_id: CollectionId,57 collection_id: RmrkCollectionId,58 },58 },59 CollectionDestroyed {59 CollectionDestroyed {60 issuer: T::AccountId,60 issuer: T::AccountId,61 collection_id: CollectionId,61 collection_id: RmrkCollectionId,62 },62 },63 IssuerChanged {64 old_issuer: T::AccountId,65 new_issuer: T::AccountId,66 collection_id: RmrkCollectionId,67 },63 CollectionLocked {68 CollectionLocked {64 issuer: T::AccountId,69 issuer: T::AccountId,65 collection_id: CollectionId,70 collection_id: RmrkCollectionId,66 },71 },67 }72 }687371 /* Unique-specific events */76 /* Unique-specific events */72 CorruptedCollectionType,77 CorruptedCollectionType,73 NotRmrkCollection,78 NotRmrkCollection,74 RmrkPropertyIsTooLong,79 RmrkPropertyKeyIsTooLong,80 RmrkPropertyValueIsTooLong,758176 /* RMRK compatible events */82 /* RMRK compatible events */77 CollectionNotEmpty,83 CollectionNotEmpty,85 #[transactional]91 #[transactional]86 pub fn create_collection(92 pub fn create_collection(87 origin: OriginFor<T>,93 origin: OriginFor<T>,88 metadata: PropertyValue,94 metadata: RmrkString,89 max: Option<u32>,95 max: Option<u32>,90 symbol: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,96 symbol: RmrkCollectionSymbol,91 ) -> DispatchResult {97 ) -> DispatchResult {92 let sender = ensure_signed(origin)?;98 let sender = ensure_signed(origin)?;93999810499 let data = CreateCollectionData {105 let data = CreateCollectionData {100 limits,106 limits,101 token_prefix: symbol,107 token_prefix: symbol.into_inner()108 .try_into()109 .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,102 ..Default::default()110 ..Default::default()103 };111 };104112123131124 Self::deposit_event(Event::CollectionCreated { issuer: sender, collection_id });132 Self::deposit_event(Event::CollectionCreated {133 issuer: sender,134 collection_id: collection_id.0135 });125136126 Ok(())137 Ok(())130 #[transactional]141 #[transactional]131 pub fn destroy_collection(142 pub fn destroy_collection(132 origin: OriginFor<T>,143 origin: OriginFor<T>,133 collection_id: CollectionId,144 collection_id: RmrkCollectionId,134 ) -> DispatchResult {145 ) -> DispatchResult {135 let sender = ensure_signed(origin)?;146 let sender = ensure_signed(origin)?;136 let cross_sender = T::CrossAccountId::from_sub(sender.clone());147 let cross_sender = T::CrossAccountId::from_sub(sender.clone());148149 let unique_collection_id = collection_id.into();137150138 let collection = Self::get_nft_collection(collection_id)?;151 let collection = Self::get_nft_collection(unique_collection_id)?;139152140 Self::check_collection_type(collection_id, CollectionType::Regular)?;153 Self::check_collection_type(unique_collection_id, CollectionType::Regular)?;141154142 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);155 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);143156152 #[transactional]165 #[transactional]153 pub fn change_collection_issuer(166 pub fn change_collection_issuer(154 origin: OriginFor<T>,167 origin: OriginFor<T>,155 collection_id: CollectionId,168 collection_id: RmrkCollectionId,156 new_issuer: T::AccountId,169 new_issuer: <T::Lookup as StaticLookup>::Source,157 ) -> DispatchResult {170 ) -> DispatchResult {158 let sender = ensure_signed(origin)?;171 let sender = ensure_signed(origin)?;172173 let new_issuer = T::Lookup::lookup(new_issuer)?;159174160 Self::change_collection_owner(175 Self::change_collection_owner(161 collection_id,176 collection_id.into(),162 CollectionType::Regular,177 CollectionType::Regular,163 sender,178 sender.clone(),164 new_issuer179 new_issuer.clone()165 )?;180 )?;181182 Self::deposit_event(Event::IssuerChanged {183 old_issuer: sender,184 new_issuer,185 collection_id,186 });166187167 Ok(())188 Ok(())168 }189 }171 #[transactional]192 #[transactional]172 pub fn lock_collection(193 pub fn lock_collection(173 origin: OriginFor<T>,194 origin: OriginFor<T>,174 collection_id: CollectionId,195 collection_id: RmrkCollectionId,175 ) -> DispatchResult {196 ) -> DispatchResult {176 let sender = ensure_signed(origin)?;197 let sender = ensure_signed(origin)?;177 let cross_sender = T::CrossAccountId::from_sub(sender.clone());198 let cross_sender = T::CrossAccountId::from_sub(sender.clone());178199179 let collection = Self::get_nft_collection(collection_id)?;200 let collection = Self::get_nft_collection(collection_id.into())?;180 collection.check_is_owner(&cross_sender)?;201 collection.check_is_owner(&cross_sender)?;181202182 let token_count = collection.total_supply();203 let token_count = collection.total_supply();pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth445macro_rules! impl_rmrk_value {5macro_rules! impl_rmrk_value {6 ($enum_name:path, decode_error: $error:ident) => {6 ($enum_name:path, decode_error: $error:ident) => {7 impl From<$enum_name> for PropertyValue {7 impl IntoPropertyValue for $enum_name {8 fn from(e: $enum_name) -> Self {8 fn into_property_value(self) -> Result<PropertyValue, MiscError> {9 e.encode().try_into().unwrap()9 self.encode()10 .try_into()11 .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)10 }12 }11 }13 }121425}27}262827pub enum MiscError {29pub enum MiscError {30 RmrkPropertyValueIsTooLong,28 CorruptedCollectionType,31 CorruptedCollectionType,29}32}303331impl<T: Config> From<MiscError> for Error<T> {34impl<T: Config> From<MiscError> for Error<T> {32 fn from(error: MiscError) -> Self {35 fn from(error: MiscError) -> Self {33 match error {36 match error {37 MiscError::RmrkPropertyValueIsTooLong => Self::RmrkPropertyValueIsTooLong,34 MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,38 MiscError::CorruptedCollectionType => Self::CorruptedCollectionType,35 }39 }36 }40 }49 }53 }50}54}5556pub trait IntoPropertyValue {57 fn into_property_value(self) -> Result<PropertyValue, MiscError>;58}5960impl<L: Get<u32>> IntoPropertyValue for BoundedVec<u8, L> {61 fn into_property_value(self) -> Result<PropertyValue, MiscError> {62 self.into_inner()63 .try_into()64 .map_err(|_| MiscError::RmrkPropertyValueIsTooLong)65 }66}516752#[derive(Encode, Decode, PartialEq, Eq)]68#[derive(Encode, Decode, PartialEq, Eq)]53pub enum CollectionType {69pub enum CollectionType {pallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth36 macro_rules! key {36 macro_rules! key {37 ($($component:expr),+) => {37 ($($component:expr),+) => {38 PropertyKey::try_from([$(key!(@ &$component)),+].concat())38 PropertyKey::try_from([$(key!(@ &$component)),+].concat())39 .map_err(|_| <Error<T>>::RmrkPropertyIsTooLong)39 .map_err(|_| <Error<T>>::RmrkPropertyKeyIsTooLong)40 };40 };414142 (@ $key:expr) => {42 (@ $key:expr) => {757576#[macro_export]76#[macro_export]77macro_rules! rmrk_property {77macro_rules! rmrk_property {78 (Config=$cfg:ty, $key:ident: $value:expr) => {78 (Config=$cfg:ty, $key:ident: $value:expr) => {{79 rmrk_property!(@$cfg, $key).map(|key| Property {79 let key = rmrk_property!(@$cfg, $key)?;8081 let value = $value.into_property_value()82 .map_err(<$crate::Error<$cfg>>::from)?;8384 Ok::<_, $crate::Error<$cfg>>(Property {80 key,85 key,81 value: $value.into()86 value,82 })87 })83 };88 }};848985 (@$cfg:ty, $key:ident) => {90 (@$cfg:ty, $key:ident) => {86 $crate::RmrkProperty::$key.to_key::<$cfg>()91 $crate::RmrkProperty::$key.to_key::<$cfg>()87 };92 };889389 (Config=$cfg:ty, $key:ident) => {94 (Config=$cfg:ty, $key:ident) => {90 PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key)?)95 PropertyScope::Rmrk.apply(rmrk_property!(@$cfg, $key)?)91 .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyIsTooLong)96 .map_err(|_| <$crate::Error<$cfg>>::RmrkPropertyKeyIsTooLong)92 };97 };93}98}9499primitives/data-structs/src/lib.rsdiffbeforeafterboth905 pub const RmrkPartsLimit: u32 = 3;905 pub const RmrkPartsLimit: u32 = 3;906}906}907907908impl From<RmrkCollectionId> for CollectionId {909 fn from(id: RmrkCollectionId) -> Self {910 Self(id)911 }912}913914impl From<RmrkNftId> for TokenId {915 fn from(id: RmrkNftId) -> Self {916 Self(id)917 }918}919920pub type RmrkCollectionSymbol = BoundedVec<u8, RmrkCollectionSymbolLimit>;908pub type RmrkCollectionInfo<AccountId> =921pub type RmrkCollectionInfo<AccountId> = CollectionInfo<RmrkString, RmrkCollectionSymbol, AccountId>;909 CollectionInfo<RmrkString, BoundedVec<u8, RmrkCollectionSymbolLimit>, AccountId>;910pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;922pub type RmrkInstanceInfo<AccountId> = NftInfo<AccountId, Permill, RmrkString>;911pub type RmrkResourceInfo = ResourceInfo<923pub type RmrkResourceInfo = ResourceInfo<912 BoundedVec<u8, RmrkResourceSymbolLimit>,924 BoundedVec<u8, RmrkResourceSymbolLimit>,