light_token/instruction/
revoke.rs1use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID;
2use solana_account_info::AccountInfo;
3use solana_cpi::{invoke, invoke_signed};
4use solana_instruction::{AccountMeta, Instruction};
5use solana_program_error::ProgramError;
6use solana_pubkey::Pubkey;
7
8pub struct Revoke {
21 pub token_account: Pubkey,
23 pub owner: Pubkey,
25}
26
27pub struct RevokeCpi<'info> {
43 pub token_account: AccountInfo<'info>,
44 pub owner: AccountInfo<'info>,
45 pub system_program: AccountInfo<'info>,
46}
47
48impl<'info> RevokeCpi<'info> {
49 pub fn instruction(&self) -> Result<Instruction, ProgramError> {
50 Revoke::from(self).instruction()
51 }
52
53 pub fn invoke(self) -> Result<(), ProgramError> {
54 let instruction = Revoke::from(&self).instruction()?;
55 let account_infos = [self.token_account, self.owner, self.system_program];
56 invoke(&instruction, &account_infos)
57 }
58
59 pub fn invoke_signed(self, signer_seeds: &[&[&[u8]]]) -> Result<(), ProgramError> {
60 let instruction = Revoke::from(&self).instruction()?;
61 let account_infos = [self.token_account, self.owner, self.system_program];
62 invoke_signed(&instruction, &account_infos, signer_seeds)
63 }
64}
65
66impl<'info> From<&RevokeCpi<'info>> for Revoke {
67 fn from(cpi: &RevokeCpi<'info>) -> Self {
68 Self {
69 token_account: *cpi.token_account.key,
70 owner: *cpi.owner.key,
71 }
72 }
73}
74
75impl Revoke {
76 pub fn instruction(self) -> Result<Instruction, ProgramError> {
77 Ok(Instruction {
78 program_id: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID),
79 accounts: vec![
80 AccountMeta::new(self.token_account, false),
81 AccountMeta::new(self.owner, true),
82 AccountMeta::new_readonly(Pubkey::default(), false),
83 ],
84 data: vec![5u8], })
86 }
87}