Skip to content

Commit

Permalink
chore: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Dec 9, 2024
1 parent c62dd83 commit c76f66b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
38 changes: 18 additions & 20 deletions pallets/nfts/src/features/approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// determine the absolute deadline for the approval. After approving the transfer, the
/// function emits the `TransferApproved` event.
///
/// This function reserves the required deposit from the `owner` account. If an approval
/// already exists, the deposit amount is incremented, and the approval's existing deadline is
/// overridden.
/// This function reserves the necessary deposit from the owner account. If an approval already
/// exists, additional funds are reserved only if the updated deposit exceeds the currently
/// reserved amount. The existing approval's deadline is also updated.
///
/// - `owner`: The owner of the collection items.
/// - `collection`: The identifier of the collection.
Expand Down Expand Up @@ -345,23 +345,21 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
delegate: &T::AccountId,
) -> DispatchResult {
// Check if `delegate` has permission to transfer `owner`'s collection items.
match Self::check_collection_approval(collection, owner, delegate) {
Ok(()) => Ok(()),
Err(error) => {
// Check if a `delegate` has permission to transfer the given collection item.
if let Some(item) = maybe_item {
let details =
Item::<T, I>::get(collection, item).ok_or(Error::<T, I>::UnknownItem)?;
let maybe_deadline =
details.approvals.get(delegate).ok_or(Error::<T, I>::NoPermission)?;
if let Some(deadline) = maybe_deadline {
let block_number = frame_system::Pallet::<T>::block_number();
ensure!(block_number <= *deadline, Error::<T, I>::ApprovalExpired);
}
return Ok(());
};
Err(error)
},
if let Err(error) = Self::check_collection_approval(collection, owner, delegate) {
// Check if a `delegate` has permission to transfer the given collection item.
if let Some(item) = maybe_item {
let details =
Item::<T, I>::get(collection, item).ok_or(Error::<T, I>::UnknownItem)?;
let maybe_deadline =
details.approvals.get(delegate).ok_or(Error::<T, I>::NoPermission)?;
if let Some(deadline) = maybe_deadline {
let block_number = frame_system::Pallet::<T>::block_number();
ensure!(block_number <= *deadline, Error::<T, I>::ApprovalExpired);
}
return Ok(());
};
return Err(error);
}
Ok(())
}
}
3 changes: 1 addition & 2 deletions pallets/nfts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,6 @@ pub mod pallet {
/// Origin must be Signed.
///
/// - `collection`: The collection of the item to be approved for delegated transfer.
/// - `item`: The item to be approved for delegated transfer.
/// - `delegate`: The account to delegate permission to transfer collection items owned by
/// the origin.
/// - `maybe_deadline`: Optional deadline for the approval. Specified by providing the
Expand All @@ -1392,7 +1391,7 @@ pub mod pallet {
Self::do_approve_collection_transfer(origin, collection, delegate, maybe_deadline)
}

/// Force-approve collection items owned by the origin to be transferred by a delegated
/// Force-approve collection items owned by the `owner` to be transferred by a delegated
/// third-party account. This function reserves the required deposit
/// `CollectionApprovalDeposit` from the `owner` account.
///
Expand Down
4 changes: 2 additions & 2 deletions pallets/nfts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3061,7 +3061,7 @@ fn collection_item_works() {
let user_id = account(1);
let total_items = 10;

// no collection.
// No collection.
assert_eq!(Nfts::collection_items(collection_id), None);

assert_ok!(Nfts::force_create(
Expand All @@ -3070,7 +3070,7 @@ fn collection_item_works() {
default_collection_config()
));

// mint items and validate the total supply.
// Mint items and validate the total supply.
(0..total_items).into_iter().for_each(|i| {
assert_ok!(Nfts::force_mint(
RuntimeOrigin::root(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/nfts/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Autogenerated weights for `pallet_nfts`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 40.0.0
//! DATE: 2024-11-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-12-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `R0GUE`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
Expand Down

0 comments on commit c76f66b

Please sign in to comment.