pinocchio_token/instructions/
freeze_account.rs

1use solana_account_view::AccountView;
2use solana_instruction_view::{
3    cpi::{invoke_signed, Signer},
4    InstructionAccount, InstructionView,
5};
6use solana_program_error::ProgramResult;
7
8/// Freeze an initialized account using the Mint's freeze authority.
9///
10/// ### Accounts:
11///   0. `[WRITE]` The account to freeze.
12///   1. `[]` The token mint.
13///   2. `[SIGNER]` The mint freeze authority.
14pub struct FreezeAccount<'a> {
15    /// Token Account to freeze.
16    pub account: &'a AccountView,
17    /// Mint Account.
18    pub mint: &'a AccountView,
19    /// Mint Freeze Authority Account
20    pub freeze_authority: &'a AccountView,
21}
22
23impl FreezeAccount<'_> {
24    #[inline(always)]
25    pub fn invoke(&self) -> ProgramResult {
26        self.invoke_signed(&[])
27    }
28
29    #[inline(always)]
30    pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
31        // Instruction accounts
32        let instruction_accounts: [InstructionAccount; 3] = [
33            InstructionAccount::writable(self.account.address()),
34            InstructionAccount::readonly(self.mint.address()),
35            InstructionAccount::readonly_signer(self.freeze_authority.address()),
36        ];
37
38        let instruction = InstructionView {
39            program_id: &crate::ID,
40            accounts: &instruction_accounts,
41            data: &[10],
42        };
43
44        invoke_signed(
45            &instruction,
46            &[self.account, self.mint, self.freeze_authority],
47            signers,
48        )
49    }
50}