git.delta.rocks / unique-network / refs/commits / 47e3bf21a896

difftreelog

feat(rmrk-proxy) separate collection ids for unique and rmrk and their mapping

Fahrrader2022-05-31parent: #5d01a90.patch.diff
in: master

2 files changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
54 #[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>;
56
57 #[pallet::storage]
58 #[pallet::getter(fn collection_index_map)]
59 pub type CollectionIndexMap<T: Config> =
60 StorageMap<_, Twox64Concat, RmrkCollectionId, CollectionId, ValueQuery>;
5661
57 #[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 }
148153
149 let collection_id = collection_id_res?;154 let unique_collection_id = collection_id_res?;
155 let rmrk_collection_id = <CollectionIndex<T>>::get();
156
157 <CollectionIndex<T>>::mutate(|n| *n += 1);
158 <CollectionIndexMap<T>>::insert(rmrk_collection_id, unique_collection_id);
150159
151 <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 )?;
160
161 <CollectionIndex<T>>::mutate(|n| *n += 1);
162169
163 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 });
167174
168 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());
179
180 let unique_collection_id = collection_id.into();
181186
182 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 )?;
186191
212 let new_issuer = T::Lookup::lookup(new_issuer)?;217 let new_issuer = T::Lookup::lookup(new_issuer)?;
213218
214 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());
238243
239 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 )?;
243248
277 });282 });
278283
279 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 )?;
283288
321326
322 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);
348353
349 let collection_id: CollectionId = rmrk_collection_id.into();354 let collection_id = Self::unique_collection_id(rmrk_collection_id)?;
350355
351 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 }
495
496 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 }
490499
491 pub fn get_nft_collection(500 pub fn get_nft_collection(
492 collection_id: CollectionId,501 collection_id: CollectionId,
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
146 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}};
148148
149 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};
169169
170 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); }
173173
194 use pallet_proxy_rmrk_core::misc::CollectionType;194 use pallet_proxy_rmrk_core::misc::CollectionType;
195195
196 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()); }
199199
200 Ok(200 Ok(
206 }206 }
207207
208 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()); }
212212
227 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;
229229
230 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;
250250
251 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);
253253
254 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}};
274274
275 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 matter
277277
278 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}};
309309
310 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 matter
312312
313 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 };
338338
339 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}};
354354
355 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()); }
357357
358 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}};
385385
386 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 };
413413
414 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 }