--- a/pallets/proxy-rmrk-core/src/lib.rs +++ b/pallets/proxy-rmrk-core/src/lib.rs @@ -161,7 +161,8 @@ ensure!(collection.total_supply() == 0, >::CollectionNotEmpty); - >::destroy_collection(collection, &cross_sender)?; + >::destroy_collection(collection, &cross_sender) + .map_err(Self::map_common_err_to_proxy)?; Self::deposit_event(Event::CollectionDestroyed { issuer: sender, collection_id }); @@ -208,8 +209,9 @@ collection_id.into(), CollectionType::Regular )?; - collection.check_is_owner(&cross_sender)?; + Self::check_collection_owner(&collection, &cross_sender)?; + let token_count = collection.total_supply(); let mut collection = collection.into_inner(); @@ -295,14 +297,7 @@ &sender, data, &budget, - ).map_err(|err| { - map_common_err_to_proxy!( - match err { - NoPermission => NoPermission, - CollectionTokenLimitExceeded => CollectionFullOrLocked - } - ) - })?; + ).map_err(Self::map_common_err_to_proxy)?; let nft_id = >::current_token_id(&collection); @@ -322,16 +317,23 @@ sender: T::AccountId, new_owner: T::AccountId, ) -> DispatchResult { - let mut collection = Self::get_typed_nft_collection( + let collection = Self::get_typed_nft_collection( collection_id, collection_type - )?.into_inner(); - collection.check_is_owner(&T::CrossAccountId::from_sub(sender))?; + )?; + Self::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))?; + let mut collection = collection.into_inner(); + collection.owner = new_owner; collection.save() } + fn check_collection_owner(collection: &NonfungibleHandle, account: &T::CrossAccountId) -> DispatchResult { + collection.check_is_owner(account) + .map_err(Self::map_common_err_to_proxy) + } + pub fn get_nft_collection(collection_id: CollectionId) -> Result, DispatchError> { let collection = >::try_get(collection_id) .map_err(|_| >::CollectionUnknown)? @@ -382,4 +384,13 @@ Self::get_nft_collection(collection_id) } + + fn map_common_err_to_proxy(err: DispatchError) -> DispatchError { + map_common_err_to_proxy! { + match err { + NoPermission => NoPermission, + CollectionTokenLimitExceeded => CollectionFullOrLocked + } + } + } }