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.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -54,6 +54,11 @@
#[pallet::getter(fn collection_index)]
pub type CollectionIndex<T: Config> = StorageValue<_, RmrkCollectionId, ValueQuery>;
+ #[pallet::storage]
+ #[pallet::getter(fn collection_index_map)]
+ pub type CollectionIndexMap<T: Config> =
+ StorageMap<_, Twox64Concat, RmrkCollectionId, CollectionId, ValueQuery>;
+
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
@@ -146,10 +151,14 @@
return Err(<Error<T>>::NoAvailableCollectionId.into());
}
- let collection_id = collection_id_res?;
+ let unique_collection_id = collection_id_res?;
+ let rmrk_collection_id = <CollectionIndex<T>>::get();
+
+ <CollectionIndex<T>>::mutate(|n| *n += 1);
+ <CollectionIndexMap<T>>::insert(rmrk_collection_id, unique_collection_id);
<PalletCommon<T>>::set_scoped_collection_properties(
- collection_id,
+ unique_collection_id,
PropertyScope::Rmrk,
[
Self::rmrk_property(Metadata, &metadata)?,
@@ -158,11 +167,9 @@
.into_iter(),
)?;
- <CollectionIndex<T>>::mutate(|n| *n += 1);
-
Self::deposit_event(Event::CollectionCreated {
issuer: sender,
- collection_id: collection_id.0,
+ collection_id: rmrk_collection_id,
});
Ok(())
@@ -177,10 +184,8 @@
let sender = ensure_signed(origin)?;
let cross_sender = T::CrossAccountId::from_sub(sender.clone());
- let unique_collection_id = collection_id.into();
-
let collection = Self::get_typed_nft_collection(
- unique_collection_id,
+ Self::unique_collection_id(collection_id)?,
misc::CollectionType::Regular,
)?;
@@ -212,7 +217,7 @@
let new_issuer = T::Lookup::lookup(new_issuer)?;
Self::change_collection_owner(
- collection_id.into(),
+ Self::unique_collection_id(collection_id)?,
misc::CollectionType::Regular,
sender.clone(),
new_issuer.clone(),
@@ -237,7 +242,7 @@
let cross_sender = T::CrossAccountId::from_sub(sender.clone());
let collection = Self::get_typed_nft_collection(
- collection_id.into(),
+ Self::unique_collection_id(collection_id)?,
misc::CollectionType::Regular,
)?;
@@ -277,7 +282,7 @@
});
let collection = Self::get_typed_nft_collection(
- collection_id.into(),
+ Self::unique_collection_id(collection_id)?,
misc::CollectionType::Regular,
)?;
@@ -321,7 +326,7 @@
Self::destroy_nft(
cross_sender,
- collection_id.into(),
+ Self::unique_collection_id(collection_id)?,
misc::CollectionType::Regular,
nft_id.into(),
)?;
@@ -346,7 +351,7 @@
let sender = ensure_signed(origin)?;
let sender = T::CrossAccountId::from_sub(sender);
- let collection_id: CollectionId = rmrk_collection_id.into();
+ let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
match maybe_nft_id {
Some(nft_id) => {
@@ -488,6 +493,10 @@
<CollectionIndex<T>>::get()
}
+ pub fn unique_collection_id(rmrk_collection_id: RmrkCollectionId) -> Result<CollectionId, DispatchError> {
+ <CollectionIndexMap<T>>::try_get(rmrk_collection_id).map_err(|_| <Error<T>>::CollectionUnknown.into())
+ }
+
pub fn get_nft_collection(
collection_id: CollectionId,
) -> Result<NonfungibleHandle<T>, DispatchError> {
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 }