Skip to main content

mpl_core/generated/instructions/
close_group_v1.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! [https://github.com/metaplex-foundation/kinobi]
6//!
7
8#[cfg(feature = "anchor")]
9use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
10#[cfg(not(feature = "anchor"))]
11use borsh::{BorshDeserialize, BorshSerialize};
12
13/// Accounts.
14pub struct CloseGroupV1 {
15    /// The address of the group to close
16    pub group: solana_program::pubkey::Pubkey,
17    /// The account receiving reclaimed lamports
18    pub payer: solana_program::pubkey::Pubkey,
19    /// The update authority of the group
20    pub authority: Option<solana_program::pubkey::Pubkey>,
21}
22
23impl CloseGroupV1 {
24    pub fn instruction(&self) -> solana_program::instruction::Instruction {
25        self.instruction_with_remaining_accounts(&[])
26    }
27    #[allow(clippy::vec_init_then_push)]
28    pub fn instruction_with_remaining_accounts(
29        &self,
30        remaining_accounts: &[solana_program::instruction::AccountMeta],
31    ) -> solana_program::instruction::Instruction {
32        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
33        accounts.push(solana_program::instruction::AccountMeta::new(
34            self.group, false,
35        ));
36        accounts.push(solana_program::instruction::AccountMeta::new(
37            self.payer, true,
38        ));
39        if let Some(authority) = self.authority {
40            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
41                authority, true,
42            ));
43        } else {
44            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
45                crate::MPL_CORE_ID,
46                false,
47            ));
48        }
49        accounts.extend_from_slice(remaining_accounts);
50        let data = borsh::to_vec(&(CloseGroupV1InstructionData::new())).unwrap();
51
52        solana_program::instruction::Instruction {
53            program_id: crate::MPL_CORE_ID,
54            accounts,
55            data,
56        }
57    }
58}
59
60#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
61#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
62pub struct CloseGroupV1InstructionData {
63    discriminator: u8,
64}
65
66impl CloseGroupV1InstructionData {
67    pub fn new() -> Self {
68        Self { discriminator: 40 }
69    }
70}
71
72/// Instruction builder for `CloseGroupV1`.
73///
74/// ### Accounts:
75///
76///   0. `[writable]` group
77///   1. `[writable, signer]` payer
78///   2. `[signer, optional]` authority
79#[derive(Default)]
80pub struct CloseGroupV1Builder {
81    group: Option<solana_program::pubkey::Pubkey>,
82    payer: Option<solana_program::pubkey::Pubkey>,
83    authority: Option<solana_program::pubkey::Pubkey>,
84    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
85}
86
87impl CloseGroupV1Builder {
88    pub fn new() -> Self {
89        Self::default()
90    }
91    /// The address of the group to close
92    #[inline(always)]
93    pub fn group(&mut self, group: solana_program::pubkey::Pubkey) -> &mut Self {
94        self.group = Some(group);
95        self
96    }
97    /// The account receiving reclaimed lamports
98    #[inline(always)]
99    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
100        self.payer = Some(payer);
101        self
102    }
103    /// `[optional account]`
104    /// The update authority of the group
105    #[inline(always)]
106    pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
107        self.authority = authority;
108        self
109    }
110    /// Add an aditional account to the instruction.
111    #[inline(always)]
112    pub fn add_remaining_account(
113        &mut self,
114        account: solana_program::instruction::AccountMeta,
115    ) -> &mut Self {
116        self.__remaining_accounts.push(account);
117        self
118    }
119    /// Add additional accounts to the instruction.
120    #[inline(always)]
121    pub fn add_remaining_accounts(
122        &mut self,
123        accounts: &[solana_program::instruction::AccountMeta],
124    ) -> &mut Self {
125        self.__remaining_accounts.extend_from_slice(accounts);
126        self
127    }
128    #[allow(clippy::clone_on_copy)]
129    pub fn instruction(&self) -> solana_program::instruction::Instruction {
130        let accounts = CloseGroupV1 {
131            group: self.group.expect("group is not set"),
132            payer: self.payer.expect("payer is not set"),
133            authority: self.authority,
134        };
135
136        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
137    }
138}
139
140/// `close_group_v1` CPI accounts.
141pub struct CloseGroupV1CpiAccounts<'a, 'b> {
142    /// The address of the group to close
143    pub group: &'b solana_program::account_info::AccountInfo<'a>,
144    /// The account receiving reclaimed lamports
145    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
146    /// The update authority of the group
147    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
148}
149
150/// `close_group_v1` CPI instruction.
151pub struct CloseGroupV1Cpi<'a, 'b> {
152    /// The program to invoke.
153    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
154    /// The address of the group to close
155    pub group: &'b solana_program::account_info::AccountInfo<'a>,
156    /// The account receiving reclaimed lamports
157    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
158    /// The update authority of the group
159    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
160}
161
162impl<'a, 'b> CloseGroupV1Cpi<'a, 'b> {
163    pub fn new(
164        program: &'b solana_program::account_info::AccountInfo<'a>,
165        accounts: CloseGroupV1CpiAccounts<'a, 'b>,
166    ) -> Self {
167        Self {
168            __program: program,
169            group: accounts.group,
170            payer: accounts.payer,
171            authority: accounts.authority,
172        }
173    }
174    #[inline(always)]
175    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
176        self.invoke_signed_with_remaining_accounts(&[], &[])
177    }
178    #[inline(always)]
179    pub fn invoke_with_remaining_accounts(
180        &self,
181        remaining_accounts: &[(
182            &'b solana_program::account_info::AccountInfo<'a>,
183            bool,
184            bool,
185        )],
186    ) -> solana_program::entrypoint::ProgramResult {
187        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
188    }
189    #[inline(always)]
190    pub fn invoke_signed(
191        &self,
192        signers_seeds: &[&[&[u8]]],
193    ) -> solana_program::entrypoint::ProgramResult {
194        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
195    }
196    #[allow(clippy::clone_on_copy)]
197    #[allow(clippy::vec_init_then_push)]
198    pub fn invoke_signed_with_remaining_accounts(
199        &self,
200        signers_seeds: &[&[&[u8]]],
201        remaining_accounts: &[(
202            &'b solana_program::account_info::AccountInfo<'a>,
203            bool,
204            bool,
205        )],
206    ) -> solana_program::entrypoint::ProgramResult {
207        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
208        accounts.push(solana_program::instruction::AccountMeta::new(
209            *self.group.key,
210            false,
211        ));
212        accounts.push(solana_program::instruction::AccountMeta::new(
213            *self.payer.key,
214            true,
215        ));
216        if let Some(authority) = self.authority {
217            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
218                *authority.key,
219                true,
220            ));
221        } else {
222            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
223                crate::MPL_CORE_ID,
224                false,
225            ));
226        }
227        remaining_accounts.iter().for_each(|remaining_account| {
228            accounts.push(solana_program::instruction::AccountMeta {
229                pubkey: *remaining_account.0.key,
230                is_writable: remaining_account.1,
231                is_signer: remaining_account.2,
232            })
233        });
234        let data = borsh::to_vec(&(CloseGroupV1InstructionData::new())).unwrap();
235
236        let instruction = solana_program::instruction::Instruction {
237            program_id: crate::MPL_CORE_ID,
238            accounts,
239            data,
240        };
241        let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
242        account_infos.push(self.__program.clone());
243        account_infos.push(self.group.clone());
244        account_infos.push(self.payer.clone());
245        if let Some(authority) = self.authority {
246            account_infos.push(authority.clone());
247        }
248        remaining_accounts
249            .iter()
250            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
251
252        if signers_seeds.is_empty() {
253            solana_program::program::invoke(&instruction, &account_infos)
254        } else {
255            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
256        }
257    }
258}
259
260/// Instruction builder for `CloseGroupV1` via CPI.
261///
262/// ### Accounts:
263///
264///   0. `[writable]` group
265///   1. `[writable, signer]` payer
266///   2. `[signer, optional]` authority
267pub struct CloseGroupV1CpiBuilder<'a, 'b> {
268    instruction: Box<CloseGroupV1CpiBuilderInstruction<'a, 'b>>,
269}
270
271impl<'a, 'b> CloseGroupV1CpiBuilder<'a, 'b> {
272    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
273        let instruction = Box::new(CloseGroupV1CpiBuilderInstruction {
274            __program: program,
275            group: None,
276            payer: None,
277            authority: None,
278            __remaining_accounts: Vec::new(),
279        });
280        Self { instruction }
281    }
282    /// The address of the group to close
283    #[inline(always)]
284    pub fn group(&mut self, group: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
285        self.instruction.group = Some(group);
286        self
287    }
288    /// The account receiving reclaimed lamports
289    #[inline(always)]
290    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
291        self.instruction.payer = Some(payer);
292        self
293    }
294    /// `[optional account]`
295    /// The update authority of the group
296    #[inline(always)]
297    pub fn authority(
298        &mut self,
299        authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
300    ) -> &mut Self {
301        self.instruction.authority = authority;
302        self
303    }
304    /// Add an additional account to the instruction.
305    #[inline(always)]
306    pub fn add_remaining_account(
307        &mut self,
308        account: &'b solana_program::account_info::AccountInfo<'a>,
309        is_writable: bool,
310        is_signer: bool,
311    ) -> &mut Self {
312        self.instruction
313            .__remaining_accounts
314            .push((account, is_writable, is_signer));
315        self
316    }
317    /// Add additional accounts to the instruction.
318    ///
319    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
320    /// and a `bool` indicating whether the account is a signer or not.
321    #[inline(always)]
322    pub fn add_remaining_accounts(
323        &mut self,
324        accounts: &[(
325            &'b solana_program::account_info::AccountInfo<'a>,
326            bool,
327            bool,
328        )],
329    ) -> &mut Self {
330        self.instruction
331            .__remaining_accounts
332            .extend_from_slice(accounts);
333        self
334    }
335    #[inline(always)]
336    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
337        self.invoke_signed(&[])
338    }
339    #[allow(clippy::clone_on_copy)]
340    #[allow(clippy::vec_init_then_push)]
341    pub fn invoke_signed(
342        &self,
343        signers_seeds: &[&[&[u8]]],
344    ) -> solana_program::entrypoint::ProgramResult {
345        let instruction = CloseGroupV1Cpi {
346            __program: self.instruction.__program,
347
348            group: self.instruction.group.expect("group is not set"),
349
350            payer: self.instruction.payer.expect("payer is not set"),
351
352            authority: self.instruction.authority,
353        };
354        instruction.invoke_signed_with_remaining_accounts(
355            signers_seeds,
356            &self.instruction.__remaining_accounts,
357        )
358    }
359}
360
361struct CloseGroupV1CpiBuilderInstruction<'a, 'b> {
362    __program: &'b solana_program::account_info::AccountInfo<'a>,
363    group: Option<&'b solana_program::account_info::AccountInfo<'a>>,
364    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
365    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
366    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
367    __remaining_accounts: Vec<(
368        &'b solana_program::account_info::AccountInfo<'a>,
369        bool,
370        bool,
371    )>,
372}