Skip to content

Commit

Permalink
feat: delete_linkdrop (#105)
Browse files Browse the repository at this point in the history
Now you can delete a linkdrop's key and get the pending token back.
  • Loading branch information
willemneal authored Jul 9, 2024
1 parent 1b62467 commit 0e7b362
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 7 additions & 4 deletions contracts/tenk/src/linkdrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,16 @@ impl Contract {
)
}

fn delete_current_access_key(&mut self) -> (bool, Promise) {
let key = env::signer_account_pk();
let mint_for_free = self.accounts.remove(&key);
pub(crate) fn delete_access_key(&mut self, public_key: PublicKey) -> (bool, Promise) {
let mint_for_free = self.accounts.remove(&public_key);
require!(mint_for_free.is_some(), "Can't use a full access key.");
(
mint_for_free.unwrap(),
Promise::new(env::current_account_id()).delete_key(key),
Promise::new(env::current_account_id()).delete_key(public_key),
)
}

fn delete_current_access_key(&mut self) -> (bool, Promise) {
self.delete_access_key(env::signer_account_pk())
}
}
10 changes: 10 additions & 0 deletions contracts/tenk/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,14 @@ impl Contract {
GAS_REQUIRED_TO_CREATE_LINKDROP,
))
}

#[payable]
/// Delete an linkdrop and decrease the number of pending tokens.
/// @allow ["::admins", "::owner"]
pub fn delete_linkdrop(&mut self, public_key: PublicKey) -> Promise {
self.assert_owner_or_admin();
let promise = self.delete_access_key(public_key).1;
self.pending_tokens -= 1;
promise
}
}

0 comments on commit 0e7b362

Please sign in to comment.