1use crate::generated::types::SetCollectionSizeArgs;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12pub struct SetCollectionSize {
14 pub collection_metadata: solana_program::pubkey::Pubkey,
16 pub collection_authority: solana_program::pubkey::Pubkey,
18 pub collection_mint: solana_program::pubkey::Pubkey,
20 pub collection_authority_record: Option<solana_program::pubkey::Pubkey>,
22}
23
24impl SetCollectionSize {
25 pub fn instruction(
26 &self,
27 args: SetCollectionSizeInstructionArgs,
28 ) -> solana_program::instruction::Instruction {
29 self.instruction_with_remaining_accounts(args, &[])
30 }
31 #[allow(clippy::vec_init_then_push)]
32 pub fn instruction_with_remaining_accounts(
33 &self,
34 args: SetCollectionSizeInstructionArgs,
35 remaining_accounts: &[solana_program::instruction::AccountMeta],
36 ) -> solana_program::instruction::Instruction {
37 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
38 accounts.push(solana_program::instruction::AccountMeta::new(
39 self.collection_metadata,
40 false,
41 ));
42 accounts.push(solana_program::instruction::AccountMeta::new(
43 self.collection_authority,
44 true,
45 ));
46 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
47 self.collection_mint,
48 false,
49 ));
50 if let Some(collection_authority_record) = self.collection_authority_record {
51 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
52 collection_authority_record,
53 false,
54 ));
55 }
56 accounts.extend_from_slice(remaining_accounts);
57 let mut data = SetCollectionSizeInstructionData::new()
58 .try_to_vec()
59 .unwrap();
60 let mut args = args.try_to_vec().unwrap();
61 data.append(&mut args);
62
63 solana_program::instruction::Instruction {
64 program_id: crate::MPL_TOKEN_METADATA_ID,
65 accounts,
66 data,
67 }
68 }
69}
70
71#[derive(BorshDeserialize, BorshSerialize)]
72struct SetCollectionSizeInstructionData {
73 discriminator: u8,
74}
75
76impl SetCollectionSizeInstructionData {
77 fn new() -> Self {
78 Self { discriminator: 34 }
79 }
80}
81
82#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
83#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
84pub struct SetCollectionSizeInstructionArgs {
85 pub set_collection_size_args: SetCollectionSizeArgs,
86}
87
88#[derive(Default)]
97pub struct SetCollectionSizeBuilder {
98 collection_metadata: Option<solana_program::pubkey::Pubkey>,
99 collection_authority: Option<solana_program::pubkey::Pubkey>,
100 collection_mint: Option<solana_program::pubkey::Pubkey>,
101 collection_authority_record: Option<solana_program::pubkey::Pubkey>,
102 set_collection_size_args: Option<SetCollectionSizeArgs>,
103 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
104}
105
106impl SetCollectionSizeBuilder {
107 pub fn new() -> Self {
108 Self::default()
109 }
110 #[inline(always)]
112 pub fn collection_metadata(
113 &mut self,
114 collection_metadata: solana_program::pubkey::Pubkey,
115 ) -> &mut Self {
116 self.collection_metadata = Some(collection_metadata);
117 self
118 }
119 #[inline(always)]
121 pub fn collection_authority(
122 &mut self,
123 collection_authority: solana_program::pubkey::Pubkey,
124 ) -> &mut Self {
125 self.collection_authority = Some(collection_authority);
126 self
127 }
128 #[inline(always)]
130 pub fn collection_mint(
131 &mut self,
132 collection_mint: solana_program::pubkey::Pubkey,
133 ) -> &mut Self {
134 self.collection_mint = Some(collection_mint);
135 self
136 }
137 #[inline(always)]
140 pub fn collection_authority_record(
141 &mut self,
142 collection_authority_record: Option<solana_program::pubkey::Pubkey>,
143 ) -> &mut Self {
144 self.collection_authority_record = collection_authority_record;
145 self
146 }
147 #[inline(always)]
148 pub fn set_collection_size_args(
149 &mut self,
150 set_collection_size_args: SetCollectionSizeArgs,
151 ) -> &mut Self {
152 self.set_collection_size_args = Some(set_collection_size_args);
153 self
154 }
155 #[inline(always)]
157 pub fn add_remaining_account(
158 &mut self,
159 account: solana_program::instruction::AccountMeta,
160 ) -> &mut Self {
161 self.__remaining_accounts.push(account);
162 self
163 }
164 #[inline(always)]
166 pub fn add_remaining_accounts(
167 &mut self,
168 accounts: &[solana_program::instruction::AccountMeta],
169 ) -> &mut Self {
170 self.__remaining_accounts.extend_from_slice(accounts);
171 self
172 }
173 #[allow(clippy::clone_on_copy)]
174 pub fn instruction(&self) -> solana_program::instruction::Instruction {
175 let accounts = SetCollectionSize {
176 collection_metadata: self
177 .collection_metadata
178 .expect("collection_metadata is not set"),
179 collection_authority: self
180 .collection_authority
181 .expect("collection_authority is not set"),
182 collection_mint: self.collection_mint.expect("collection_mint is not set"),
183 collection_authority_record: self.collection_authority_record,
184 };
185 let args = SetCollectionSizeInstructionArgs {
186 set_collection_size_args: self
187 .set_collection_size_args
188 .clone()
189 .expect("set_collection_size_args is not set"),
190 };
191
192 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
193 }
194}
195
196pub struct SetCollectionSizeCpiAccounts<'a, 'b> {
198 pub collection_metadata: &'b solana_program::account_info::AccountInfo<'a>,
200 pub collection_authority: &'b solana_program::account_info::AccountInfo<'a>,
202 pub collection_mint: &'b solana_program::account_info::AccountInfo<'a>,
204 pub collection_authority_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
206}
207
208pub struct SetCollectionSizeCpi<'a, 'b> {
210 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
212 pub collection_metadata: &'b solana_program::account_info::AccountInfo<'a>,
214 pub collection_authority: &'b solana_program::account_info::AccountInfo<'a>,
216 pub collection_mint: &'b solana_program::account_info::AccountInfo<'a>,
218 pub collection_authority_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
220 pub __args: SetCollectionSizeInstructionArgs,
222}
223
224impl<'a, 'b> SetCollectionSizeCpi<'a, 'b> {
225 pub fn new(
226 program: &'b solana_program::account_info::AccountInfo<'a>,
227 accounts: SetCollectionSizeCpiAccounts<'a, 'b>,
228 args: SetCollectionSizeInstructionArgs,
229 ) -> Self {
230 Self {
231 __program: program,
232 collection_metadata: accounts.collection_metadata,
233 collection_authority: accounts.collection_authority,
234 collection_mint: accounts.collection_mint,
235 collection_authority_record: accounts.collection_authority_record,
236 __args: args,
237 }
238 }
239 #[inline(always)]
240 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
241 self.invoke_signed_with_remaining_accounts(&[], &[])
242 }
243 #[inline(always)]
244 pub fn invoke_with_remaining_accounts(
245 &self,
246 remaining_accounts: &[(
247 &'b solana_program::account_info::AccountInfo<'a>,
248 bool,
249 bool,
250 )],
251 ) -> solana_program::entrypoint::ProgramResult {
252 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
253 }
254 #[inline(always)]
255 pub fn invoke_signed(
256 &self,
257 signers_seeds: &[&[&[u8]]],
258 ) -> solana_program::entrypoint::ProgramResult {
259 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
260 }
261 #[allow(clippy::clone_on_copy)]
262 #[allow(clippy::vec_init_then_push)]
263 pub fn invoke_signed_with_remaining_accounts(
264 &self,
265 signers_seeds: &[&[&[u8]]],
266 remaining_accounts: &[(
267 &'b solana_program::account_info::AccountInfo<'a>,
268 bool,
269 bool,
270 )],
271 ) -> solana_program::entrypoint::ProgramResult {
272 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
273 accounts.push(solana_program::instruction::AccountMeta::new(
274 *self.collection_metadata.key,
275 false,
276 ));
277 accounts.push(solana_program::instruction::AccountMeta::new(
278 *self.collection_authority.key,
279 true,
280 ));
281 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
282 *self.collection_mint.key,
283 false,
284 ));
285 if let Some(collection_authority_record) = self.collection_authority_record {
286 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
287 *collection_authority_record.key,
288 false,
289 ));
290 }
291 remaining_accounts.iter().for_each(|remaining_account| {
292 accounts.push(solana_program::instruction::AccountMeta {
293 pubkey: *remaining_account.0.key,
294 is_signer: remaining_account.1,
295 is_writable: remaining_account.2,
296 })
297 });
298 let mut data = SetCollectionSizeInstructionData::new()
299 .try_to_vec()
300 .unwrap();
301 let mut args = self.__args.try_to_vec().unwrap();
302 data.append(&mut args);
303
304 let instruction = solana_program::instruction::Instruction {
305 program_id: crate::MPL_TOKEN_METADATA_ID,
306 accounts,
307 data,
308 };
309 let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
310 account_infos.push(self.__program.clone());
311 account_infos.push(self.collection_metadata.clone());
312 account_infos.push(self.collection_authority.clone());
313 account_infos.push(self.collection_mint.clone());
314 if let Some(collection_authority_record) = self.collection_authority_record {
315 account_infos.push(collection_authority_record.clone());
316 }
317 remaining_accounts
318 .iter()
319 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
320
321 if signers_seeds.is_empty() {
322 solana_program::program::invoke(&instruction, &account_infos)
323 } else {
324 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
325 }
326 }
327}
328
329pub struct SetCollectionSizeCpiBuilder<'a, 'b> {
338 instruction: Box<SetCollectionSizeCpiBuilderInstruction<'a, 'b>>,
339}
340
341impl<'a, 'b> SetCollectionSizeCpiBuilder<'a, 'b> {
342 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
343 let instruction = Box::new(SetCollectionSizeCpiBuilderInstruction {
344 __program: program,
345 collection_metadata: None,
346 collection_authority: None,
347 collection_mint: None,
348 collection_authority_record: None,
349 set_collection_size_args: None,
350 __remaining_accounts: Vec::new(),
351 });
352 Self { instruction }
353 }
354 #[inline(always)]
356 pub fn collection_metadata(
357 &mut self,
358 collection_metadata: &'b solana_program::account_info::AccountInfo<'a>,
359 ) -> &mut Self {
360 self.instruction.collection_metadata = Some(collection_metadata);
361 self
362 }
363 #[inline(always)]
365 pub fn collection_authority(
366 &mut self,
367 collection_authority: &'b solana_program::account_info::AccountInfo<'a>,
368 ) -> &mut Self {
369 self.instruction.collection_authority = Some(collection_authority);
370 self
371 }
372 #[inline(always)]
374 pub fn collection_mint(
375 &mut self,
376 collection_mint: &'b solana_program::account_info::AccountInfo<'a>,
377 ) -> &mut Self {
378 self.instruction.collection_mint = Some(collection_mint);
379 self
380 }
381 #[inline(always)]
384 pub fn collection_authority_record(
385 &mut self,
386 collection_authority_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
387 ) -> &mut Self {
388 self.instruction.collection_authority_record = collection_authority_record;
389 self
390 }
391 #[inline(always)]
392 pub fn set_collection_size_args(
393 &mut self,
394 set_collection_size_args: SetCollectionSizeArgs,
395 ) -> &mut Self {
396 self.instruction.set_collection_size_args = Some(set_collection_size_args);
397 self
398 }
399 #[inline(always)]
401 pub fn add_remaining_account(
402 &mut self,
403 account: &'b solana_program::account_info::AccountInfo<'a>,
404 is_writable: bool,
405 is_signer: bool,
406 ) -> &mut Self {
407 self.instruction
408 .__remaining_accounts
409 .push((account, is_writable, is_signer));
410 self
411 }
412 #[inline(always)]
417 pub fn add_remaining_accounts(
418 &mut self,
419 accounts: &[(
420 &'b solana_program::account_info::AccountInfo<'a>,
421 bool,
422 bool,
423 )],
424 ) -> &mut Self {
425 self.instruction
426 .__remaining_accounts
427 .extend_from_slice(accounts);
428 self
429 }
430 #[inline(always)]
431 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
432 self.invoke_signed(&[])
433 }
434 #[allow(clippy::clone_on_copy)]
435 #[allow(clippy::vec_init_then_push)]
436 pub fn invoke_signed(
437 &self,
438 signers_seeds: &[&[&[u8]]],
439 ) -> solana_program::entrypoint::ProgramResult {
440 let args = SetCollectionSizeInstructionArgs {
441 set_collection_size_args: self
442 .instruction
443 .set_collection_size_args
444 .clone()
445 .expect("set_collection_size_args is not set"),
446 };
447 let instruction = SetCollectionSizeCpi {
448 __program: self.instruction.__program,
449
450 collection_metadata: self
451 .instruction
452 .collection_metadata
453 .expect("collection_metadata is not set"),
454
455 collection_authority: self
456 .instruction
457 .collection_authority
458 .expect("collection_authority is not set"),
459
460 collection_mint: self
461 .instruction
462 .collection_mint
463 .expect("collection_mint is not set"),
464
465 collection_authority_record: self.instruction.collection_authority_record,
466 __args: args,
467 };
468 instruction.invoke_signed_with_remaining_accounts(
469 signers_seeds,
470 &self.instruction.__remaining_accounts,
471 )
472 }
473}
474
475struct SetCollectionSizeCpiBuilderInstruction<'a, 'b> {
476 __program: &'b solana_program::account_info::AccountInfo<'a>,
477 collection_metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
478 collection_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
479 collection_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
480 collection_authority_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
481 set_collection_size_args: Option<SetCollectionSizeArgs>,
482 __remaining_accounts: Vec<(
484 &'b solana_program::account_info::AccountInfo<'a>,
485 bool,
486 bool,
487 )>,
488}