Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the spl_token revoke instruction #1493

Merged
merged 9 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ incremented for features.
### Features

* lang: Add new `AccountSysvarMismatch` error code and test cases for sysvars ([#1535](https://github.com/project-serum/anchor/pull/1535)).
* spl: Add support for revoke instruction ([#1493](https://github.com/project-serum/anchor/pull/1493)).

### Fixes

Expand Down
21 changes: 21 additions & 0 deletions spl/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ pub fn approve<'a, 'b, 'c, 'info>(
.map_err(Into::into)
}

pub fn revoke<'a, 'b, 'c, 'info>(ctx: CpiContext<'a, 'b, 'c, 'info, Revoke<'info>>) -> Result<()> {
let ix = spl_token::instruction::revoke(
&spl_token::ID,
ctx.accounts.source.key,
ctx.accounts.authority.key,
&[],
)?;
solana_program::program::invoke_signed(
&ix,
&[ctx.accounts.source.clone(), ctx.accounts.authority.clone()],
ctx.signer_seeds,
)
.map_err(Into::into)
}

pub fn initialize_account<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, InitializeAccount<'info>>,
) -> Result<()> {
Expand Down Expand Up @@ -270,6 +285,12 @@ pub struct Approve<'info> {
pub authority: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct Revoke<'info> {
pub source: AccountInfo<'info>,
pub authority: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct InitializeAccount<'info> {
pub account: AccountInfo<'info>,
Expand Down