mpl_core/generated/instructions/
collect.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 Collect {
15    /// The address of the recipient 1
16    pub recipient1: solana_program::pubkey::Pubkey,
17    /// The address of the recipient 2
18    pub recipient2: solana_program::pubkey::Pubkey,
19}
20
21impl Collect {
22    pub fn instruction(&self) -> solana_program::instruction::Instruction {
23        self.instruction_with_remaining_accounts(&[])
24    }
25    #[allow(clippy::vec_init_then_push)]
26    pub fn instruction_with_remaining_accounts(
27        &self,
28        remaining_accounts: &[solana_program::instruction::AccountMeta],
29    ) -> solana_program::instruction::Instruction {
30        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
31        accounts.push(solana_program::instruction::AccountMeta::new(
32            self.recipient1,
33            false,
34        ));
35        accounts.push(solana_program::instruction::AccountMeta::new(
36            self.recipient2,
37            false,
38        ));
39        accounts.extend_from_slice(remaining_accounts);
40        let data = CollectInstructionData::new().try_to_vec().unwrap();
41
42        solana_program::instruction::Instruction {
43            program_id: crate::MPL_CORE_ID,
44            accounts,
45            data,
46        }
47    }
48}
49
50#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
51#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
52pub struct CollectInstructionData {
53    discriminator: u8,
54}
55
56impl CollectInstructionData {
57    pub fn new() -> Self {
58        Self { discriminator: 19 }
59    }
60}
61
62/// Instruction builder for `Collect`.
63///
64/// ### Accounts:
65///
66///   0. `[writable, optional]` recipient1 (default to `8AT6o8Qk5T9QnZvPThMrF9bcCQLTGkyGvVZZzHgCw11v`)
67///   1. `[writable, optional]` recipient2 (default to `MmHsqX4LxTfifxoH8BVRLUKrwDn1LPCac6YcCZTHhwt`)
68#[derive(Default)]
69pub struct CollectBuilder {
70    recipient1: Option<solana_program::pubkey::Pubkey>,
71    recipient2: Option<solana_program::pubkey::Pubkey>,
72    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
73}
74
75impl CollectBuilder {
76    pub fn new() -> Self {
77        Self::default()
78    }
79    /// `[optional account, default to '8AT6o8Qk5T9QnZvPThMrF9bcCQLTGkyGvVZZzHgCw11v']`
80    /// The address of the recipient 1
81    #[inline(always)]
82    pub fn recipient1(&mut self, recipient1: solana_program::pubkey::Pubkey) -> &mut Self {
83        self.recipient1 = Some(recipient1);
84        self
85    }
86    /// `[optional account, default to 'MmHsqX4LxTfifxoH8BVRLUKrwDn1LPCac6YcCZTHhwt']`
87    /// The address of the recipient 2
88    #[inline(always)]
89    pub fn recipient2(&mut self, recipient2: solana_program::pubkey::Pubkey) -> &mut Self {
90        self.recipient2 = Some(recipient2);
91        self
92    }
93    /// Add an aditional account to the instruction.
94    #[inline(always)]
95    pub fn add_remaining_account(
96        &mut self,
97        account: solana_program::instruction::AccountMeta,
98    ) -> &mut Self {
99        self.__remaining_accounts.push(account);
100        self
101    }
102    /// Add additional accounts to the instruction.
103    #[inline(always)]
104    pub fn add_remaining_accounts(
105        &mut self,
106        accounts: &[solana_program::instruction::AccountMeta],
107    ) -> &mut Self {
108        self.__remaining_accounts.extend_from_slice(accounts);
109        self
110    }
111    #[allow(clippy::clone_on_copy)]
112    pub fn instruction(&self) -> solana_program::instruction::Instruction {
113        let accounts = Collect {
114            recipient1: self.recipient1.unwrap_or(solana_program::pubkey!(
115                "8AT6o8Qk5T9QnZvPThMrF9bcCQLTGkyGvVZZzHgCw11v"
116            )),
117            recipient2: self.recipient2.unwrap_or(solana_program::pubkey!(
118                "MmHsqX4LxTfifxoH8BVRLUKrwDn1LPCac6YcCZTHhwt"
119            )),
120        };
121
122        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
123    }
124}
125
126/// `collect` CPI accounts.
127pub struct CollectCpiAccounts<'a, 'b> {
128    /// The address of the recipient 1
129    pub recipient1: &'b solana_program::account_info::AccountInfo<'a>,
130    /// The address of the recipient 2
131    pub recipient2: &'b solana_program::account_info::AccountInfo<'a>,
132}
133
134/// `collect` CPI instruction.
135pub struct CollectCpi<'a, 'b> {
136    /// The program to invoke.
137    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
138    /// The address of the recipient 1
139    pub recipient1: &'b solana_program::account_info::AccountInfo<'a>,
140    /// The address of the recipient 2
141    pub recipient2: &'b solana_program::account_info::AccountInfo<'a>,
142}
143
144impl<'a, 'b> CollectCpi<'a, 'b> {
145    pub fn new(
146        program: &'b solana_program::account_info::AccountInfo<'a>,
147        accounts: CollectCpiAccounts<'a, 'b>,
148    ) -> Self {
149        Self {
150            __program: program,
151            recipient1: accounts.recipient1,
152            recipient2: accounts.recipient2,
153        }
154    }
155    #[inline(always)]
156    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
157        self.invoke_signed_with_remaining_accounts(&[], &[])
158    }
159    #[inline(always)]
160    pub fn invoke_with_remaining_accounts(
161        &self,
162        remaining_accounts: &[(
163            &'b solana_program::account_info::AccountInfo<'a>,
164            bool,
165            bool,
166        )],
167    ) -> solana_program::entrypoint::ProgramResult {
168        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
169    }
170    #[inline(always)]
171    pub fn invoke_signed(
172        &self,
173        signers_seeds: &[&[&[u8]]],
174    ) -> solana_program::entrypoint::ProgramResult {
175        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
176    }
177    #[allow(clippy::clone_on_copy)]
178    #[allow(clippy::vec_init_then_push)]
179    pub fn invoke_signed_with_remaining_accounts(
180        &self,
181        signers_seeds: &[&[&[u8]]],
182        remaining_accounts: &[(
183            &'b solana_program::account_info::AccountInfo<'a>,
184            bool,
185            bool,
186        )],
187    ) -> solana_program::entrypoint::ProgramResult {
188        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
189        accounts.push(solana_program::instruction::AccountMeta::new(
190            *self.recipient1.key,
191            false,
192        ));
193        accounts.push(solana_program::instruction::AccountMeta::new(
194            *self.recipient2.key,
195            false,
196        ));
197        remaining_accounts.iter().for_each(|remaining_account| {
198            accounts.push(solana_program::instruction::AccountMeta {
199                pubkey: *remaining_account.0.key,
200                is_signer: remaining_account.1,
201                is_writable: remaining_account.2,
202            })
203        });
204        let data = CollectInstructionData::new().try_to_vec().unwrap();
205
206        let instruction = solana_program::instruction::Instruction {
207            program_id: crate::MPL_CORE_ID,
208            accounts,
209            data,
210        };
211        let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
212        account_infos.push(self.__program.clone());
213        account_infos.push(self.recipient1.clone());
214        account_infos.push(self.recipient2.clone());
215        remaining_accounts
216            .iter()
217            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
218
219        if signers_seeds.is_empty() {
220            solana_program::program::invoke(&instruction, &account_infos)
221        } else {
222            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
223        }
224    }
225}
226
227/// Instruction builder for `Collect` via CPI.
228///
229/// ### Accounts:
230///
231///   0. `[writable]` recipient1
232///   1. `[writable]` recipient2
233pub struct CollectCpiBuilder<'a, 'b> {
234    instruction: Box<CollectCpiBuilderInstruction<'a, 'b>>,
235}
236
237impl<'a, 'b> CollectCpiBuilder<'a, 'b> {
238    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
239        let instruction = Box::new(CollectCpiBuilderInstruction {
240            __program: program,
241            recipient1: None,
242            recipient2: None,
243            __remaining_accounts: Vec::new(),
244        });
245        Self { instruction }
246    }
247    /// The address of the recipient 1
248    #[inline(always)]
249    pub fn recipient1(
250        &mut self,
251        recipient1: &'b solana_program::account_info::AccountInfo<'a>,
252    ) -> &mut Self {
253        self.instruction.recipient1 = Some(recipient1);
254        self
255    }
256    /// The address of the recipient 2
257    #[inline(always)]
258    pub fn recipient2(
259        &mut self,
260        recipient2: &'b solana_program::account_info::AccountInfo<'a>,
261    ) -> &mut Self {
262        self.instruction.recipient2 = Some(recipient2);
263        self
264    }
265    /// Add an additional account to the instruction.
266    #[inline(always)]
267    pub fn add_remaining_account(
268        &mut self,
269        account: &'b solana_program::account_info::AccountInfo<'a>,
270        is_writable: bool,
271        is_signer: bool,
272    ) -> &mut Self {
273        self.instruction
274            .__remaining_accounts
275            .push((account, is_writable, is_signer));
276        self
277    }
278    /// Add additional accounts to the instruction.
279    ///
280    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
281    /// and a `bool` indicating whether the account is a signer or not.
282    #[inline(always)]
283    pub fn add_remaining_accounts(
284        &mut self,
285        accounts: &[(
286            &'b solana_program::account_info::AccountInfo<'a>,
287            bool,
288            bool,
289        )],
290    ) -> &mut Self {
291        self.instruction
292            .__remaining_accounts
293            .extend_from_slice(accounts);
294        self
295    }
296    #[inline(always)]
297    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
298        self.invoke_signed(&[])
299    }
300    #[allow(clippy::clone_on_copy)]
301    #[allow(clippy::vec_init_then_push)]
302    pub fn invoke_signed(
303        &self,
304        signers_seeds: &[&[&[u8]]],
305    ) -> solana_program::entrypoint::ProgramResult {
306        let instruction = CollectCpi {
307            __program: self.instruction.__program,
308
309            recipient1: self.instruction.recipient1.expect("recipient1 is not set"),
310
311            recipient2: self.instruction.recipient2.expect("recipient2 is not set"),
312        };
313        instruction.invoke_signed_with_remaining_accounts(
314            signers_seeds,
315            &self.instruction.__remaining_accounts,
316        )
317    }
318}
319
320struct CollectCpiBuilderInstruction<'a, 'b> {
321    __program: &'b solana_program::account_info::AccountInfo<'a>,
322    recipient1: Option<&'b solana_program::account_info::AccountInfo<'a>>,
323    recipient2: Option<&'b solana_program::account_info::AccountInfo<'a>>,
324    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
325    __remaining_accounts: Vec<(
326        &'b solana_program::account_info::AccountInfo<'a>,
327        bool,
328        bool,
329    )>,
330}