Skip to content

Commit

Permalink
spl: Add support for the spl_token revoke (coral-xyz#1493)
Browse files Browse the repository at this point in the history
  • Loading branch information
RohanKapurDEV authored and NBNARADHYA committed Mar 9, 2022
1 parent 1e3eee3 commit 4cac112
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 4cac112

Please sign in to comment.