浏览代码

spl: Add support for the spl_token revoke (#1493)

Rohan Kapur 3 年之前
父节点
当前提交
4e8bb08cc4
共有 2 个文件被更改,包括 22 次插入0 次删除
  1. 1 0
      CHANGELOG.md
  2. 21 0
      spl/src/token.rs

+ 1 - 0
CHANGELOG.md

@@ -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
 

+ 21 - 0
spl/src/token.rs

@@ -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<()> {
@@ -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>,