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