difftreelog
feat(rmrk-proxy) separate collection ids for unique and rmrk and their mapping
in: master
2 files changed
pallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth54 #[pallet::getter(fn collection_index)]54 #[pallet::getter(fn collection_index)]55 pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;55 pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;5657 #[pallet::storage]58 #[pallet::getter(fn collection_index_map)]59 pub type CollectionIndexMap<T: Config> = 60 StorageMap<_, Twox64Concat, RmrkCollectionId, CollectionId, ValueQuery>;566157 #[pallet::pallet]62 #[pallet::pallet]58 #[pallet::generate_store(pub(super) trait Store)]63 #[pallet::generate_store(pub(super) trait Store)]146 return Err(<Error<T>>::NoAvailableCollectionId.into());151 return Err(<Error<T>>::NoAvailableCollectionId.into());147 }152 }148153149 let collection_id = collection_id_res?;154 let unique_collection_id = collection_id_res?;155 let rmrk_collection_id = <CollectionIndex<T>>::get();156157 <CollectionIndex<T>>::mutate(|n| *n += 1);158 <CollectionIndexMap<T>>::insert(rmrk_collection_id, unique_collection_id);150159151 <PalletCommon<T>>::set_scoped_collection_properties(160 <PalletCommon<T>>::set_scoped_collection_properties(152 collection_id,161 unique_collection_id,153 PropertyScope::Rmrk,162 PropertyScope::Rmrk,154 [163 [155 Self::rmrk_property(Metadata, &metadata)?,164 Self::rmrk_property(Metadata, &metadata)?,158 .into_iter(),167 .into_iter(),159 )?;168 )?;160161 <CollectionIndex<T>>::mutate(|n| *n += 1);162169163 Self::deposit_event(Event::CollectionCreated {170 Self::deposit_event(Event::CollectionCreated {164 issuer: sender,171 issuer: sender,165 collection_id: collection_id.0,172 collection_id: rmrk_collection_id,166 });173 });167174168 Ok(())175 Ok(())177 let sender = ensure_signed(origin)?;184 let sender = ensure_signed(origin)?;178 let cross_sender = T::CrossAccountId::from_sub(sender.clone());185 let cross_sender = T::CrossAccountId::from_sub(sender.clone());179180 let unique_collection_id = collection_id.into();181186182 let collection = Self::get_typed_nft_collection(187 let collection = Self::get_typed_nft_collection(183 unique_collection_id,188 Self::unique_collection_id(collection_id)?,184 misc::CollectionType::Regular,189 misc::CollectionType::Regular,185 )?;190 )?;186191212 let new_issuer = T::Lookup::lookup(new_issuer)?;217 let new_issuer = T::Lookup::lookup(new_issuer)?;213218214 Self::change_collection_owner(219 Self::change_collection_owner(215 collection_id.into(),220 Self::unique_collection_id(collection_id)?,216 misc::CollectionType::Regular,221 misc::CollectionType::Regular,217 sender.clone(),222 sender.clone(),218 new_issuer.clone(),223 new_issuer.clone(),237 let cross_sender = T::CrossAccountId::from_sub(sender.clone());242 let cross_sender = T::CrossAccountId::from_sub(sender.clone());238243239 let collection = Self::get_typed_nft_collection(244 let collection = Self::get_typed_nft_collection(240 collection_id.into(),245 Self::unique_collection_id(collection_id)?,241 misc::CollectionType::Regular,246 misc::CollectionType::Regular,242 )?;247 )?;243248277 });282 });278283279 let collection = Self::get_typed_nft_collection(284 let collection = Self::get_typed_nft_collection(280 collection_id.into(),285 Self::unique_collection_id(collection_id)?,281 misc::CollectionType::Regular,286 misc::CollectionType::Regular,282 )?;287 )?;283288321326322 Self::destroy_nft(327 Self::destroy_nft(323 cross_sender,328 cross_sender,324 collection_id.into(),329 Self::unique_collection_id(collection_id)?,325 misc::CollectionType::Regular,330 misc::CollectionType::Regular,326 nft_id.into(),331 nft_id.into(),327 )?;332 )?;346 let sender = ensure_signed(origin)?;351 let sender = ensure_signed(origin)?;347 let sender = T::CrossAccountId::from_sub(sender);352 let sender = T::CrossAccountId::from_sub(sender);348353349 let collection_id: CollectionId = rmrk_collection_id.into();354 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;350355351 match maybe_nft_id {356 match maybe_nft_id {352 Some(nft_id) => {357 Some(nft_id) => {488 <CollectionIndex<T>>::get()493 <CollectionIndex<T>>::get()489 }494 }495496 pub fn unique_collection_id(rmrk_collection_id: RmrkCollectionId) -> Result<CollectionId, DispatchError> {497 <CollectionIndexMap<T>>::try_get(rmrk_collection_id).map_err(|_| <Error<T>>::CollectionUnknown.into())498 }490499491 pub fn get_nft_collection(500 pub fn get_nft_collection(492 collection_id: CollectionId,501 collection_id: CollectionId,runtime/common/src/runtime_apis.rsdiffbeforeafterboth146 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {146 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {147 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode, RmrkRebind}};147 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode, RmrkRebind}};148148149 let collection_id = CollectionId(collection_id);149 let collection_id = RmrkCore::unique_collection_id(collection_id)?;150 let collection = match RmrkCore::get_typed_nft_collection(collection_id, CollectionType::Regular) {150 let collection = match RmrkCore::get_typed_nft_collection(collection_id, CollectionType::Regular) {151 Ok(c) => c,151 Ok(c) => c,152 Err(_) => return Ok(None),152 Err(_) => return Ok(None),167 use up_data_structs::mapping::TokenAddressMapping;167 use up_data_structs::mapping::TokenAddressMapping;168 use pallet_proxy_rmrk_core::{RmrkProperty, misc::RmrkDecode};168 use pallet_proxy_rmrk_core::{RmrkProperty, misc::RmrkDecode};169169170 let collection_id = CollectionId(collection_id);170 let collection_id = RmrkCore::unique_collection_id(collection_id)?;171 let nft_id = TokenId(nft_by_id);171 let nft_id = TokenId(nft_by_id);172 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }172 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(None); }173173194 use pallet_proxy_rmrk_core::misc::CollectionType;194 use pallet_proxy_rmrk_core::misc::CollectionType;195195196 let cross_account_id = CrossAccountId::from_sub(account_id);196 let cross_account_id = CrossAccountId::from_sub(account_id);197 let collection_id = CollectionId(collection_id);197 let collection_id = RmrkCore::unique_collection_id(collection_id)?;198 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(Vec::new()); }198 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() { return Ok(Vec::new()); }199199200 Ok(200 Ok(206 }206 }207207208 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {208 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {209 let collection_id = CollectionId(collection_id);209 let collection_id = RmrkCore::unique_collection_id(collection_id)?;210 let nft_id = TokenId(nft_id);210 let nft_id = TokenId(nft_id);211 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }211 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }212212227 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {227 fn collection_properties(collection_id: RmrkCollectionId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {228 use pallet_proxy_rmrk_core::misc::CollectionType;228 use pallet_proxy_rmrk_core::misc::CollectionType;229229230 let collection_id = CollectionId(collection_id);230 let collection_id = RmrkCore::unique_collection_id(collection_id)?;231 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() {231 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Regular).is_err() {232 return Ok(Vec::new());232 return Ok(Vec::new());233 }233 }248 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {248 fn nft_properties(collection_id: RmrkCollectionId, nft_id: RmrkNftId, filter_keys: Option<Vec<RmrkPropertyKey>>) -> Result<Vec<RmrkPropertyInfo>, DispatchError> {249 use pallet_proxy_rmrk_core::misc::NftType;249 use pallet_proxy_rmrk_core::misc::NftType;250250251 let collection_id = CollectionId(collection_id);251 let collection_id = RmrkCore::unique_collection_id(collection_id)?;252 let token_id = TokenId(nft_id);252 let token_id = TokenId(nft_id);253253254 if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {254 if RmrkCore::ensure_nft_type(collection_id, token_id, NftType::Regular).is_err() {272 use frame_support::BoundedVec;272 use frame_support::BoundedVec;273 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};273 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};274274275 let collection_id = CollectionId(collection_id);275 let collection_id = RmrkCore::unique_collection_id(collection_id)?;276 if !RmrkCore::collection_exists(collection_id) { return Ok(Vec::new()); } // todo make sure the collection type doesn't matter276 if !RmrkCore::collection_exists(collection_id) { return Ok(Vec::new()); } // todo make sure the collection type doesn't matter277277278 let nft_id = TokenId(nft_id);278 let nft_id = TokenId(nft_id);307 fn nft_resource_priorities(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceId>, DispatchError> {307 fn nft_resource_priorities(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkResourceId>, DispatchError> {308 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};308 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};309309310 let collection_id = CollectionId(collection_id);310 let collection_id = RmrkCore::unique_collection_id(collection_id)?;311 if !RmrkCore::collection_exists(collection_id) { return Ok(Vec::new()); } // todo ensure the collection type doesn't matter311 if !RmrkCore::collection_exists(collection_id) { return Ok(Vec::new()); } // todo ensure the collection type doesn't matter312312313 let nft_id = TokenId(nft_id);313 let nft_id = TokenId(nft_id);336 RmrkProperty, misc::{CollectionType, RmrkDecode, RmrkRebind},336 RmrkProperty, misc::{CollectionType, RmrkDecode, RmrkRebind},337 };337 };338338339 let collection_id = CollectionId(base_id);339 let collection_id = RmrkCore::unique_collection_id(base_id)?;340 let collection = match RmrkCore::get_typed_nft_collection(collection_id, CollectionType::Base) {340 let collection = match RmrkCore::get_typed_nft_collection(collection_id, CollectionType::Base) {341 Ok(c) => c,341 Ok(c) => c,342 Err(_) => return Ok(None),342 Err(_) => return Ok(None),352 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {352 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {353 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};353 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkDecode}};354354355 let collection_id = CollectionId(base_id);355 let collection_id = RmrkCore::unique_collection_id(base_id)?;356 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() { return Ok(Vec::new()); }356 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() { return Ok(Vec::new()); }357357358 let parts = dispatch_unique_runtime!(collection_id.collection_tokens())?358 let parts = dispatch_unique_runtime!(collection_id.collection_tokens())?383 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {383 fn theme_names(base_id: RmrkBaseId) -> Result<Vec<RmrkThemeName>, DispatchError> {384 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode}};384 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode}};385385386 let collection_id = CollectionId(base_id);386 let collection_id = RmrkCore::unique_collection_id(base_id)?;387 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() {387 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() {388 return Ok(Vec::new());388 return Ok(Vec::new());389 }389 }411 misc::{CollectionType, NftType, RmrkDecode}411 misc::{CollectionType, NftType, RmrkDecode}412 };412 };413413414 let collection_id = CollectionId(base_id);414 let collection_id = RmrkCore::unique_collection_id(base_id)?;415 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() {415 if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() {416 return Ok(None);416 return Ok(None);417 }417 }