Skip to content

Commit f83bdc5

Browse files
committed
feat: not require deposit for force_approve_collection_transfer
1 parent 3e2620a commit f83bdc5

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

pallets/nfts/src/features/approvals.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
204204
/// - `owner`: The owner of the collection items.
205205
/// - `collection`: The identifier of the collection.
206206
/// - `delegate`: The account that will be approved to take control of the collection items.
207+
/// - `deposit`: The reserved amount for granting a collection approval.
207208
/// - `maybe_deadline`: The optional deadline (in block numbers) specifying the time limit for
208209
/// the approval.
209210
pub(crate) fn do_approve_collection_transfer(
210211
owner: T::AccountId,
211212
collection: T::CollectionId,
212213
delegate: T::AccountId,
214+
deposit: DepositBalanceOf<T, I>,
213215
maybe_deadline: Option<BlockNumberFor<T>>,
214216
) -> DispatchResult {
215217
ensure!(
@@ -234,11 +236,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
234236
CollectionApprovals::<T, I>::try_mutate_exists(
235237
(&collection, &owner, &delegate),
236238
|maybe_approval| -> DispatchResult {
237-
let deposit_required = T::CollectionApprovalDeposit::get();
238239
let current_deposit =
239240
maybe_approval.map(|(_, deposit)| deposit).unwrap_or_default();
240-
T::Currency::reserve(&owner, deposit_required.saturating_sub(current_deposit))?;
241-
*maybe_approval = Some((deadline, deposit_required));
241+
T::Currency::reserve(&owner, deposit.saturating_sub(current_deposit))?;
242+
*maybe_approval = Some((deadline, deposit));
242243
Ok(())
243244
},
244245
)?;

pallets/nfts/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,15 +2033,22 @@ pub mod pallet {
20332033
) -> DispatchResult {
20342034
let origin = ensure_signed(origin)?;
20352035
let delegate = T::Lookup::lookup(delegate)?;
2036-
Self::do_approve_collection_transfer(origin, collection, delegate, maybe_deadline)
2036+
Self::do_approve_collection_transfer(
2037+
origin,
2038+
collection,
2039+
delegate,
2040+
T::CollectionApprovalDeposit::get(),
2041+
maybe_deadline,
2042+
)
20372043
}
20382044

20392045
/// Force-approve collection items owned by the `owner` to be transferred by a delegated
2040-
/// third-party account. This function reserves the required deposit
2041-
/// `CollectionApprovalDeposit` from the `owner` account.
2046+
/// third-party account.
20422047
///
20432048
/// Origin must be the `ForceOrigin`.
20442049
///
2050+
/// Any deposit is left alone.
2051+
///
20452052
/// - `owner`: The owner of the collection items to be force-approved by the `origin`.
20462053
/// - `collection`: The collection of the items to be approved for delegated transfer.
20472054
/// - `delegate`: The account to delegate permission to transfer collection items owned by
@@ -2064,7 +2071,13 @@ pub mod pallet {
20642071
T::ForceOrigin::ensure_origin(origin)?;
20652072
let delegate = T::Lookup::lookup(delegate)?;
20662073
let owner = T::Lookup::lookup(owner)?;
2067-
Self::do_approve_collection_transfer(owner, collection, delegate, maybe_deadline)
2074+
Self::do_approve_collection_transfer(
2075+
owner,
2076+
collection,
2077+
delegate,
2078+
Zero::zero(),
2079+
maybe_deadline,
2080+
)
20682081
}
20692082

20702083
/// Cancel a collection approval.

pallets/nfts/src/tests.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,7 +4815,6 @@ fn force_approve_collection_transfer_works() {
48154815
let collection_owner = account(1);
48164816
let deadline: BlockNumberFor<Test> = 20;
48174817
let delegate = account(3);
4818-
let deposit = CollectionApprovalDeposit::get();
48194818
let item_id = 42;
48204819
let item_owner = account(2);
48214820

@@ -4866,16 +4865,13 @@ fn force_approve_collection_transfer_works() {
48664865
default_item_config()
48674866
));
48684867
// Approve collection without balance.
4869-
assert_noop!(
4870-
Nfts::force_approve_collection_transfer(
4871-
RuntimeOrigin::root(),
4872-
item_owner.clone(),
4873-
collection_id,
4874-
delegate.clone(),
4875-
None
4876-
),
4877-
BalancesError::<Test, _>::InsufficientBalance,
4878-
);
4868+
assert_ok!(Nfts::force_approve_collection_transfer(
4869+
RuntimeOrigin::root(),
4870+
item_owner.clone(),
4871+
collection_id,
4872+
delegate.clone(),
4873+
None
4874+
));
48794875

48804876
Balances::make_free_balance_be(&item_owner, 100);
48814877
// Approving a collection to a delegate with:
@@ -4909,10 +4905,10 @@ fn force_approve_collection_transfer_works() {
49094905
}
49104906
.into(),
49114907
);
4912-
assert_eq!(Balances::reserved_balance(&item_owner), deposit);
4908+
assert_eq!(Balances::reserved_balance(&item_owner), 0);
49134909
assert_eq!(
49144910
CollectionApprovals::get((collection_id, &item_owner, &delegate)),
4915-
Some((deadline, deposit))
4911+
Some((deadline, 0))
49164912
);
49174913
}
49184914

0 commit comments

Comments
 (0)