批准和撤銷指令
批准授予代理人代表帳戶擁有者轉移特定數量代幣的權限。這使得程式化的代幣轉移成為可能,而無需授予完整的帳戶控制權。
撤銷會移除當前代理人對帳戶的權限,將完整的控制權返回給帳戶擁有者。
在我們可以代理或撤銷任何代幣帳戶之前,我們需要已經完成以下操作:
初始化了一個
Mint帳戶。初始化了一個
Token帳戶或Associated Token帳戶,這是我們將要控制的帳戶
以下是對approve()指令的CPI的樣子:
rust
approve(
CpiContext::new(
ctx.accounts.token_program.to_account_info(),
Approve {
to: ctx.accounts.token_account.to_account_info(),
delegate: ctx.accounts.delegate.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
},
),
&1_000_000,
)?;以下是對revoke()指令的CPI的樣子:
rust
revoke(
CpiContext::new(
ctx.accounts.token_program.to_account_info(),
Revoke {
pub source: ctx.accounts.token_account.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
},
),
)?;