Skip to content

Commit c5f208c

Browse files
authored
allow revoke with live_until_ledger 0 (#174)
1 parent c5f050c commit c5f208c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/tokens/non-fungible/src/non_fungible.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ pub trait NonFungibleToken {
174174
///
175175
/// Only a single account can be approved at a time for a `token_id`.
176176
/// To remove an approval, the approver can approve their own address,
177-
/// effectively removing the previous approved address.
177+
/// effectively removing the previous approved address. Alternatively,
178+
/// setting the `live_until_ledger` to `0` will also revoke the approval.
178179
///
179180
/// # Arguments
180181
///
@@ -184,7 +185,7 @@ pub trait NonFungibleToken {
184185
/// * `approved` - The address receiving the approval.
185186
/// * `token_id` - Token id as a number.
186187
/// * `live_until_ledger` - The ledger number at which the allowance
187-
/// expires.
188+
/// expires. If `live_until_ledger` is `0`, the approval is revoked.
188189
///
189190
/// # Errors
190191
///

packages/tokens/non-fungible/src/storage.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ impl Base {
322322
/// `operator`).
323323
/// * `approved` - The address receiving the approval.
324324
/// * `token_id` - The identifier of the token to be approved.
325-
/// * `live_until_ledger` - The ledger number at which the approval expires.
325+
/// * `live_until_ledger` - The ledger number at which the allowance
326+
/// expires. If `live_until_ledger` is `0`, the approval is revoked.
326327
///
327328
/// # Errors
328329
///
@@ -497,12 +498,19 @@ impl Base {
497498
panic_with_error!(e, NonFungibleTokenError::InvalidApprover);
498499
}
499500

501+
let key = StorageKey::Approval(token_id);
502+
503+
if live_until_ledger == 0 {
504+
e.storage().temporary().remove(&key);
505+
506+
emit_approve(e, approver, approved, token_id, live_until_ledger);
507+
return;
508+
}
509+
500510
if live_until_ledger < e.ledger().sequence() {
501511
panic_with_error!(e, NonFungibleTokenError::InvalidLiveUntilLedger);
502512
}
503513

504-
let key = StorageKey::Approval(token_id);
505-
506514
let approval_data = ApprovalData { approved: approved.clone(), live_until_ledger };
507515

508516
e.storage().temporary().set(&key, &approval_data);

0 commit comments

Comments
 (0)