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

difftreelog

fix map common error to proxy errors

Daniel Shiposha2022-05-23parent: #b724450.patch.diff
in: master

1 file changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
162 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);162 ensure!(collection.total_supply() == 0, <Error<T>>::CollectionNotEmpty);
163163
164 <PalletNft<T>>::destroy_collection(collection, &cross_sender)?;164 <PalletNft<T>>::destroy_collection(collection, &cross_sender)
165 .map_err(Self::map_common_err_to_proxy)?;
165166
166 Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });167 Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id });
167168
209 CollectionType::Regular210 CollectionType::Regular
210 )?;211 )?;
212
211 collection.check_is_owner(&cross_sender)?;213 Self::check_collection_owner(&collection, &cross_sender)?;
212214
213 let token_count = collection.total_supply();215 let token_count = collection.total_supply();
214216
295 &sender,297 &sender,
296 data,298 data,
297 &budget,299 &budget,
298 ).map_err(|err| {300 ).map_err(Self::map_common_err_to_proxy)?;
299 map_common_err_to_proxy!(
300 match err {
301 NoPermission => NoPermission,
302 CollectionTokenLimitExceeded => CollectionFullOrLocked
303 }
304 )
305 })?;
306301
307 let nft_id = <PalletNft<T>>::current_token_id(&collection);302 let nft_id = <PalletNft<T>>::current_token_id(&collection);
308303
322 sender: T::AccountId,317 sender: T::AccountId,
323 new_owner: T::AccountId,318 new_owner: T::AccountId,
324 ) -> DispatchResult {319 ) -> DispatchResult {
325 let mut collection = Self::get_typed_nft_collection(320 let collection = Self::get_typed_nft_collection(
326 collection_id,321 collection_id,
327 collection_type322 collection_type
328 )?.into_inner();323 )?;
329 collection.check_is_owner(&T::CrossAccountId::from_sub(sender))?;324 Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?;
325
326 let mut collection = collection.into_inner();
330327
331 collection.owner = new_owner;328 collection.owner = new_owner;
332 collection.save()329 collection.save()
333 }330 }
331
332 fn check_collection_owner(collection: &NonfungibleHandle<T>, account: &T::CrossAccountId) -> DispatchResult {
333 collection.check_is_owner(account)
334 .map_err(Self::map_common_err_to_proxy)
335 }
334336
335 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {337 pub fn get_nft_collection(collection_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {
336 let collection = <CollectionHandle<T>>::try_get(collection_id)338 let collection = <CollectionHandle<T>>::try_get(collection_id)
383 Self::get_nft_collection(collection_id)385 Self::get_nft_collection(collection_id)
384 }386 }
387
388 fn map_common_err_to_proxy(err: DispatchError) -> DispatchError {
389 map_common_err_to_proxy! {
390 match err {
391 NoPermission => NoPermission,
392 CollectionTokenLimitExceeded => CollectionFullOrLocked
393 }
394 }
395 }
385}396}
386397