Skip to main content

mpl_bubblegum/generated/instructions/
set_tree_delegate.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
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12pub struct SetTreeDelegate {
13    pub tree_config: solana_program::pubkey::Pubkey,
14
15    pub tree_creator: solana_program::pubkey::Pubkey,
16
17    pub new_tree_delegate: solana_program::pubkey::Pubkey,
18
19    pub merkle_tree: solana_program::pubkey::Pubkey,
20
21    pub system_program: solana_program::pubkey::Pubkey,
22}
23
24impl SetTreeDelegate {
25    pub fn instruction(&self) -> solana_program::instruction::Instruction {
26        self.instruction_with_remaining_accounts(&[])
27    }
28    #[allow(clippy::vec_init_then_push)]
29    pub fn instruction_with_remaining_accounts(
30        &self,
31        remaining_accounts: &[solana_program::instruction::AccountMeta],
32    ) -> solana_program::instruction::Instruction {
33        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
34        accounts.push(solana_program::instruction::AccountMeta::new(
35            self.tree_config,
36            false,
37        ));
38        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
39            self.tree_creator,
40            true,
41        ));
42        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
43            self.new_tree_delegate,
44            false,
45        ));
46        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
47            self.merkle_tree,
48            false,
49        ));
50        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
51            self.system_program,
52            false,
53        ));
54        accounts.extend_from_slice(remaining_accounts);
55        let data = SetTreeDelegateInstructionData::new().try_to_vec().unwrap();
56
57        solana_program::instruction::Instruction {
58            program_id: crate::MPL_BUBBLEGUM_ID,
59            accounts,
60            data,
61        }
62    }
63}
64
65#[derive(BorshDeserialize, BorshSerialize)]
66struct SetTreeDelegateInstructionData {
67    discriminator: [u8; 8],
68}
69
70impl SetTreeDelegateInstructionData {
71    fn new() -> Self {
72        Self {
73            discriminator: [253, 118, 66, 37, 190, 49, 154, 102],
74        }
75    }
76}
77
78/// Instruction builder.
79#[derive(Default)]
80pub struct SetTreeDelegateBuilder {
81    tree_config: Option<solana_program::pubkey::Pubkey>,
82    tree_creator: Option<solana_program::pubkey::Pubkey>,
83    new_tree_delegate: Option<solana_program::pubkey::Pubkey>,
84    merkle_tree: Option<solana_program::pubkey::Pubkey>,
85    system_program: Option<solana_program::pubkey::Pubkey>,
86    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
87}
88
89impl SetTreeDelegateBuilder {
90    pub fn new() -> Self {
91        Self::default()
92    }
93    #[inline(always)]
94    pub fn tree_config(&mut self, tree_config: solana_program::pubkey::Pubkey) -> &mut Self {
95        self.tree_config = Some(tree_config);
96        self
97    }
98    #[inline(always)]
99    pub fn tree_creator(&mut self, tree_creator: solana_program::pubkey::Pubkey) -> &mut Self {
100        self.tree_creator = Some(tree_creator);
101        self
102    }
103    #[inline(always)]
104    pub fn new_tree_delegate(
105        &mut self,
106        new_tree_delegate: solana_program::pubkey::Pubkey,
107    ) -> &mut Self {
108        self.new_tree_delegate = Some(new_tree_delegate);
109        self
110    }
111    #[inline(always)]
112    pub fn merkle_tree(&mut self, merkle_tree: solana_program::pubkey::Pubkey) -> &mut Self {
113        self.merkle_tree = Some(merkle_tree);
114        self
115    }
116    /// `[optional account, default to '11111111111111111111111111111111']`
117    #[inline(always)]
118    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
119        self.system_program = Some(system_program);
120        self
121    }
122    /// Add an aditional account to the instruction.
123    #[inline(always)]
124    pub fn add_remaining_account(
125        &mut self,
126        account: solana_program::instruction::AccountMeta,
127    ) -> &mut Self {
128        self.__remaining_accounts.push(account);
129        self
130    }
131    /// Add additional accounts to the instruction.
132    #[inline(always)]
133    pub fn add_remaining_accounts(
134        &mut self,
135        accounts: &[solana_program::instruction::AccountMeta],
136    ) -> &mut Self {
137        self.__remaining_accounts.extend_from_slice(accounts);
138        self
139    }
140    #[allow(clippy::clone_on_copy)]
141    pub fn instruction(&self) -> solana_program::instruction::Instruction {
142        let accounts = SetTreeDelegate {
143            tree_config: self.tree_config.expect("tree_config is not set"),
144            tree_creator: self.tree_creator.expect("tree_creator is not set"),
145            new_tree_delegate: self
146                .new_tree_delegate
147                .expect("new_tree_delegate is not set"),
148            merkle_tree: self.merkle_tree.expect("merkle_tree is not set"),
149            system_program: self
150                .system_program
151                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
152        };
153
154        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
155    }
156}
157
158/// `set_tree_delegate` CPI accounts.
159pub struct SetTreeDelegateCpiAccounts<'a, 'b> {
160    pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
161
162    pub tree_creator: &'b solana_program::account_info::AccountInfo<'a>,
163
164    pub new_tree_delegate: &'b solana_program::account_info::AccountInfo<'a>,
165
166    pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
167
168    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
169}
170
171/// `set_tree_delegate` CPI instruction.
172pub struct SetTreeDelegateCpi<'a, 'b> {
173    /// The program to invoke.
174    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
175
176    pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
177
178    pub tree_creator: &'b solana_program::account_info::AccountInfo<'a>,
179
180    pub new_tree_delegate: &'b solana_program::account_info::AccountInfo<'a>,
181
182    pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
183
184    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
185}
186
187impl<'a, 'b> SetTreeDelegateCpi<'a, 'b> {
188    pub fn new(
189        program: &'b solana_program::account_info::AccountInfo<'a>,
190        accounts: SetTreeDelegateCpiAccounts<'a, 'b>,
191    ) -> Self {
192        Self {
193            __program: program,
194            tree_config: accounts.tree_config,
195            tree_creator: accounts.tree_creator,
196            new_tree_delegate: accounts.new_tree_delegate,
197            merkle_tree: accounts.merkle_tree,
198            system_program: accounts.system_program,
199        }
200    }
201    #[inline(always)]
202    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
203        self.invoke_signed_with_remaining_accounts(&[], &[])
204    }
205    #[inline(always)]
206    pub fn invoke_with_remaining_accounts(
207        &self,
208        remaining_accounts: &[(
209            &'b solana_program::account_info::AccountInfo<'a>,
210            bool,
211            bool,
212        )],
213    ) -> solana_program::entrypoint::ProgramResult {
214        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
215    }
216    #[inline(always)]
217    pub fn invoke_signed(
218        &self,
219        signers_seeds: &[&[&[u8]]],
220    ) -> solana_program::entrypoint::ProgramResult {
221        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
222    }
223    #[allow(clippy::clone_on_copy)]
224    #[allow(clippy::vec_init_then_push)]
225    pub fn invoke_signed_with_remaining_accounts(
226        &self,
227        signers_seeds: &[&[&[u8]]],
228        remaining_accounts: &[(
229            &'b solana_program::account_info::AccountInfo<'a>,
230            bool,
231            bool,
232        )],
233    ) -> solana_program::entrypoint::ProgramResult {
234        let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
235        accounts.push(solana_program::instruction::AccountMeta::new(
236            *self.tree_config.key,
237            false,
238        ));
239        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
240            *self.tree_creator.key,
241            true,
242        ));
243        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
244            *self.new_tree_delegate.key,
245            false,
246        ));
247        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
248            *self.merkle_tree.key,
249            false,
250        ));
251        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
252            *self.system_program.key,
253            false,
254        ));
255        remaining_accounts.iter().for_each(|remaining_account| {
256            accounts.push(solana_program::instruction::AccountMeta {
257                pubkey: *remaining_account.0.key,
258                is_signer: remaining_account.1,
259                is_writable: remaining_account.2,
260            })
261        });
262        let data = SetTreeDelegateInstructionData::new().try_to_vec().unwrap();
263
264        let instruction = solana_program::instruction::Instruction {
265            program_id: crate::MPL_BUBBLEGUM_ID,
266            accounts,
267            data,
268        };
269        let mut account_infos = Vec::with_capacity(5 + 1 + remaining_accounts.len());
270        account_infos.push(self.__program.clone());
271        account_infos.push(self.tree_config.clone());
272        account_infos.push(self.tree_creator.clone());
273        account_infos.push(self.new_tree_delegate.clone());
274        account_infos.push(self.merkle_tree.clone());
275        account_infos.push(self.system_program.clone());
276        remaining_accounts
277            .iter()
278            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
279
280        if signers_seeds.is_empty() {
281            solana_program::program::invoke(&instruction, &account_infos)
282        } else {
283            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
284        }
285    }
286}
287
288/// `set_tree_delegate` CPI instruction builder.
289pub struct SetTreeDelegateCpiBuilder<'a, 'b> {
290    instruction: Box<SetTreeDelegateCpiBuilderInstruction<'a, 'b>>,
291}
292
293impl<'a, 'b> SetTreeDelegateCpiBuilder<'a, 'b> {
294    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
295        let instruction = Box::new(SetTreeDelegateCpiBuilderInstruction {
296            __program: program,
297            tree_config: None,
298            tree_creator: None,
299            new_tree_delegate: None,
300            merkle_tree: None,
301            system_program: None,
302            __remaining_accounts: Vec::new(),
303        });
304        Self { instruction }
305    }
306    #[inline(always)]
307    pub fn tree_config(
308        &mut self,
309        tree_config: &'b solana_program::account_info::AccountInfo<'a>,
310    ) -> &mut Self {
311        self.instruction.tree_config = Some(tree_config);
312        self
313    }
314    #[inline(always)]
315    pub fn tree_creator(
316        &mut self,
317        tree_creator: &'b solana_program::account_info::AccountInfo<'a>,
318    ) -> &mut Self {
319        self.instruction.tree_creator = Some(tree_creator);
320        self
321    }
322    #[inline(always)]
323    pub fn new_tree_delegate(
324        &mut self,
325        new_tree_delegate: &'b solana_program::account_info::AccountInfo<'a>,
326    ) -> &mut Self {
327        self.instruction.new_tree_delegate = Some(new_tree_delegate);
328        self
329    }
330    #[inline(always)]
331    pub fn merkle_tree(
332        &mut self,
333        merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
334    ) -> &mut Self {
335        self.instruction.merkle_tree = Some(merkle_tree);
336        self
337    }
338    #[inline(always)]
339    pub fn system_program(
340        &mut self,
341        system_program: &'b solana_program::account_info::AccountInfo<'a>,
342    ) -> &mut Self {
343        self.instruction.system_program = Some(system_program);
344        self
345    }
346    /// Add an additional account to the instruction.
347    #[inline(always)]
348    pub fn add_remaining_account(
349        &mut self,
350        account: &'b solana_program::account_info::AccountInfo<'a>,
351        is_writable: bool,
352        is_signer: bool,
353    ) -> &mut Self {
354        self.instruction
355            .__remaining_accounts
356            .push((account, is_writable, is_signer));
357        self
358    }
359    /// Add additional accounts to the instruction.
360    ///
361    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
362    /// and a `bool` indicating whether the account is a signer or not.
363    #[inline(always)]
364    pub fn add_remaining_accounts(
365        &mut self,
366        accounts: &[(
367            &'b solana_program::account_info::AccountInfo<'a>,
368            bool,
369            bool,
370        )],
371    ) -> &mut Self {
372        self.instruction
373            .__remaining_accounts
374            .extend_from_slice(accounts);
375        self
376    }
377    #[inline(always)]
378    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
379        self.invoke_signed(&[])
380    }
381    #[allow(clippy::clone_on_copy)]
382    #[allow(clippy::vec_init_then_push)]
383    pub fn invoke_signed(
384        &self,
385        signers_seeds: &[&[&[u8]]],
386    ) -> solana_program::entrypoint::ProgramResult {
387        let instruction = SetTreeDelegateCpi {
388            __program: self.instruction.__program,
389
390            tree_config: self
391                .instruction
392                .tree_config
393                .expect("tree_config is not set"),
394
395            tree_creator: self
396                .instruction
397                .tree_creator
398                .expect("tree_creator is not set"),
399
400            new_tree_delegate: self
401                .instruction
402                .new_tree_delegate
403                .expect("new_tree_delegate is not set"),
404
405            merkle_tree: self
406                .instruction
407                .merkle_tree
408                .expect("merkle_tree is not set"),
409
410            system_program: self
411                .instruction
412                .system_program
413                .expect("system_program is not set"),
414        };
415        instruction.invoke_signed_with_remaining_accounts(
416            signers_seeds,
417            &self.instruction.__remaining_accounts,
418        )
419    }
420}
421
422struct SetTreeDelegateCpiBuilderInstruction<'a, 'b> {
423    __program: &'b solana_program::account_info::AccountInfo<'a>,
424    tree_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
425    tree_creator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
426    new_tree_delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
427    merkle_tree: Option<&'b solana_program::account_info::AccountInfo<'a>>,
428    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
429    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
430    __remaining_accounts: Vec<(
431        &'b solana_program::account_info::AccountInfo<'a>,
432        bool,
433        bool,
434    )>,
435}