git.delta.rocks / unique-network / refs/commits / 3ffbf1dba649

difftreelog

feat(rmrk) add reject_nft

Daniel Shiposha2022-06-05parent: #866e42a.patch.diff
in: master

1 file changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
133 ResourceDoesntExist,133 ResourceDoesntExist,
134 CannotSendToDescendentOrSelf,134 CannotSendToDescendentOrSelf,
135 CannotAcceptNonOwnedNft,135 CannotAcceptNonOwnedNft,
136 CannotRejectNonOwnedNft,
136 }137 }
137138
138 #[pallet::call]139 #[pallet::call]
353 Self::destroy_nft(354 Self::destroy_nft(
354 cross_sender,355 cross_sender,
355 Self::unique_collection_id(collection_id)?,356 Self::unique_collection_id(collection_id)?,
356 misc::CollectionType::Regular,
357 nft_id.into(),357 nft_id.into(),
358 )?;358 ).map_err(Self::map_unique_err_to_proxy)?;
359359
360 Self::deposit_event(Event::NFTBurned {360 Self::deposit_event(Event::NFTBurned {
361 owner: sender,361 owner: sender,
505 Ok(())505 Ok(())
506 }506 }
507
508 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
509 #[transactional]
510 pub fn reject_nft(
511 origin: OriginFor<T>,
512 collection_id: RmrkCollectionId,
513 nft_id: RmrkNftId,
514 ) -> DispatchResult {
515 let sender = ensure_signed(origin)?;
516 let cross_sender = T::CrossAccountId::from_sub(sender);
517
518 let collection_id = Self::unique_collection_id(collection_id)?;
519 let nft_id = nft_id.into();
520
521 Self::destroy_nft(
522 cross_sender,
523 collection_id,
524 nft_id
525 ).map_err(|err| {
526 if err == <CommonError<T>>::NoPermission.into()
527 || err == <CommonError<T>>::ApprovedValueTooLow.into() {
528 <Error<T>>::CannotRejectNonOwnedNft.into()
529 } else {
530 Self::map_unique_err_to_proxy(err)
531 }
532 })?;
533
534 Ok(())
535 }
507536
508 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]537 #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]
509 #[transactional]538 #[transactional]
778 fn destroy_nft(807 fn destroy_nft(
779 sender: T::CrossAccountId,808 sender: T::CrossAccountId,
780 collection_id: CollectionId,809 collection_id: CollectionId,
781 collection_type: misc::CollectionType,
782 token_id: TokenId,810 token_id: TokenId,
783 ) -> DispatchResult {811 ) -> DispatchResult {
784 let collection = Self::get_typed_nft_collection(collection_id, collection_type)?;812 let collection = Self::get_typed_nft_collection(collection_id, misc::CollectionType::Regular)?;
785813
786 <PalletNft<T>>::burn(&collection, &sender, token_id)814 let token_data = <TokenData<T>>::get((collection_id, token_id))
787 .map_err(Self::map_unique_err_to_proxy)?;815 .ok_or(<Error<T>>::NoAvailableNftId)?;
816
817 let from = token_data.owner;
788818
789 Ok(())819 let budget = budget::Value::new(NESTING_BUDGET);
820
821 <PalletNft<T>>::burn_from(&collection, &sender, &from, token_id, &budget)
790 }822 }
791823
792 fn resource_add(824 fn resource_add(