1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12pub struct UpdateDistribution {
14 pub distribution: solana_program::pubkey::Pubkey,
16 pub payer: solana_program::pubkey::Pubkey,
18 pub authority: Option<solana_program::pubkey::Pubkey>,
20 pub fee_wallet: solana_program::pubkey::Pubkey,
22 pub system_program: solana_program::pubkey::Pubkey,
24}
25
26impl UpdateDistribution {
27 pub fn instruction(
28 &self,
29 args: UpdateDistributionInstructionArgs,
30 ) -> solana_program::instruction::Instruction {
31 self.instruction_with_remaining_accounts(args, &[])
32 }
33 #[allow(clippy::vec_init_then_push)]
34 pub fn instruction_with_remaining_accounts(
35 &self,
36 args: UpdateDistributionInstructionArgs,
37 remaining_accounts: &[solana_program::instruction::AccountMeta],
38 ) -> solana_program::instruction::Instruction {
39 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
40 accounts.push(solana_program::instruction::AccountMeta::new(
41 self.distribution,
42 false,
43 ));
44 accounts.push(solana_program::instruction::AccountMeta::new(
45 self.payer, true,
46 ));
47 if let Some(authority) = self.authority {
48 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
49 authority, true,
50 ));
51 } else {
52 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
53 crate::MPL_DISTRO_ID,
54 false,
55 ));
56 }
57 accounts.push(solana_program::instruction::AccountMeta::new(
58 self.fee_wallet,
59 false,
60 ));
61 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
62 self.system_program,
63 false,
64 ));
65 accounts.extend_from_slice(remaining_accounts);
66 let mut data = UpdateDistributionInstructionData::new()
67 .try_to_vec()
68 .unwrap();
69 let mut args = args.try_to_vec().unwrap();
70 data.append(&mut args);
71
72 solana_program::instruction::Instruction {
73 program_id: crate::MPL_DISTRO_ID,
74 accounts,
75 data,
76 }
77 }
78}
79
80#[derive(BorshDeserialize, BorshSerialize)]
81struct UpdateDistributionInstructionData {
82 discriminator: u8,
83}
84
85impl UpdateDistributionInstructionData {
86 fn new() -> Self {
87 Self { discriminator: 1 }
88 }
89}
90
91#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93pub struct UpdateDistributionInstructionArgs {
94 pub merkle_root: Option<[u8; 32]>,
95 pub tree_height: Option<u8>,
96 pub start_time: Option<i64>,
97 pub end_time: Option<i64>,
98 pub total_claimants: Option<u64>,
99 pub new_authority: Option<Pubkey>,
100 pub name: Option<String>,
101 pub new_permissioned_distributor: Option<Pubkey>,
102}
103
104#[derive(Default)]
114pub struct UpdateDistributionBuilder {
115 distribution: Option<solana_program::pubkey::Pubkey>,
116 payer: Option<solana_program::pubkey::Pubkey>,
117 authority: Option<solana_program::pubkey::Pubkey>,
118 fee_wallet: Option<solana_program::pubkey::Pubkey>,
119 system_program: Option<solana_program::pubkey::Pubkey>,
120 merkle_root: Option<[u8; 32]>,
121 tree_height: Option<u8>,
122 start_time: Option<i64>,
123 end_time: Option<i64>,
124 total_claimants: Option<u64>,
125 new_authority: Option<Pubkey>,
126 name: Option<String>,
127 new_permissioned_distributor: Option<Pubkey>,
128 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
129}
130
131impl UpdateDistributionBuilder {
132 pub fn new() -> Self {
133 Self::default()
134 }
135 #[inline(always)]
137 pub fn distribution(&mut self, distribution: solana_program::pubkey::Pubkey) -> &mut Self {
138 self.distribution = Some(distribution);
139 self
140 }
141 #[inline(always)]
143 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
144 self.payer = Some(payer);
145 self
146 }
147 #[inline(always)]
150 pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
151 self.authority = authority;
152 self
153 }
154 #[inline(always)]
157 pub fn fee_wallet(&mut self, fee_wallet: solana_program::pubkey::Pubkey) -> &mut Self {
158 self.fee_wallet = Some(fee_wallet);
159 self
160 }
161 #[inline(always)]
164 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
165 self.system_program = Some(system_program);
166 self
167 }
168 #[inline(always)]
170 pub fn merkle_root(&mut self, merkle_root: [u8; 32]) -> &mut Self {
171 self.merkle_root = Some(merkle_root);
172 self
173 }
174 #[inline(always)]
176 pub fn tree_height(&mut self, tree_height: u8) -> &mut Self {
177 self.tree_height = Some(tree_height);
178 self
179 }
180 #[inline(always)]
182 pub fn start_time(&mut self, start_time: i64) -> &mut Self {
183 self.start_time = Some(start_time);
184 self
185 }
186 #[inline(always)]
188 pub fn end_time(&mut self, end_time: i64) -> &mut Self {
189 self.end_time = Some(end_time);
190 self
191 }
192 #[inline(always)]
194 pub fn total_claimants(&mut self, total_claimants: u64) -> &mut Self {
195 self.total_claimants = Some(total_claimants);
196 self
197 }
198 #[inline(always)]
200 pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
201 self.new_authority = Some(new_authority);
202 self
203 }
204 #[inline(always)]
206 pub fn name(&mut self, name: String) -> &mut Self {
207 self.name = Some(name);
208 self
209 }
210 #[inline(always)]
212 pub fn new_permissioned_distributor(
213 &mut self,
214 new_permissioned_distributor: Pubkey,
215 ) -> &mut Self {
216 self.new_permissioned_distributor = Some(new_permissioned_distributor);
217 self
218 }
219 #[inline(always)]
221 pub fn add_remaining_account(
222 &mut self,
223 account: solana_program::instruction::AccountMeta,
224 ) -> &mut Self {
225 self.__remaining_accounts.push(account);
226 self
227 }
228 #[inline(always)]
230 pub fn add_remaining_accounts(
231 &mut self,
232 accounts: &[solana_program::instruction::AccountMeta],
233 ) -> &mut Self {
234 self.__remaining_accounts.extend_from_slice(accounts);
235 self
236 }
237 #[allow(clippy::clone_on_copy)]
238 pub fn instruction(&self) -> solana_program::instruction::Instruction {
239 let accounts = UpdateDistribution {
240 distribution: self.distribution.expect("distribution is not set"),
241 payer: self.payer.expect("payer is not set"),
242 authority: self.authority,
243 fee_wallet: self.fee_wallet.unwrap_or(solana_program::pubkey!(
244 "9kFjQsxtpBsaw8s7aUyiY3wazYDNgFP4Lj5rsBVVF8tb"
245 )),
246 system_program: self
247 .system_program
248 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
249 };
250 let args = UpdateDistributionInstructionArgs {
251 merkle_root: self.merkle_root.clone(),
252 tree_height: self.tree_height.clone(),
253 start_time: self.start_time.clone(),
254 end_time: self.end_time.clone(),
255 total_claimants: self.total_claimants.clone(),
256 new_authority: self.new_authority.clone(),
257 name: self.name.clone(),
258 new_permissioned_distributor: self.new_permissioned_distributor.clone(),
259 };
260
261 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
262 }
263}
264
265pub struct UpdateDistributionCpiAccounts<'a, 'b> {
267 pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
269 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
271 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
273 pub fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
275 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
277}
278
279pub struct UpdateDistributionCpi<'a, 'b> {
281 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
283 pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
285 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
287 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
289 pub fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
291 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
293 pub __args: UpdateDistributionInstructionArgs,
295}
296
297impl<'a, 'b> UpdateDistributionCpi<'a, 'b> {
298 pub fn new(
299 program: &'b solana_program::account_info::AccountInfo<'a>,
300 accounts: UpdateDistributionCpiAccounts<'a, 'b>,
301 args: UpdateDistributionInstructionArgs,
302 ) -> Self {
303 Self {
304 __program: program,
305 distribution: accounts.distribution,
306 payer: accounts.payer,
307 authority: accounts.authority,
308 fee_wallet: accounts.fee_wallet,
309 system_program: accounts.system_program,
310 __args: args,
311 }
312 }
313 #[inline(always)]
314 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
315 self.invoke_signed_with_remaining_accounts(&[], &[])
316 }
317 #[inline(always)]
318 pub fn invoke_with_remaining_accounts(
319 &self,
320 remaining_accounts: &[(
321 &'b solana_program::account_info::AccountInfo<'a>,
322 bool,
323 bool,
324 )],
325 ) -> solana_program::entrypoint::ProgramResult {
326 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
327 }
328 #[inline(always)]
329 pub fn invoke_signed(
330 &self,
331 signers_seeds: &[&[&[u8]]],
332 ) -> solana_program::entrypoint::ProgramResult {
333 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
334 }
335 #[allow(clippy::clone_on_copy)]
336 #[allow(clippy::vec_init_then_push)]
337 pub fn invoke_signed_with_remaining_accounts(
338 &self,
339 signers_seeds: &[&[&[u8]]],
340 remaining_accounts: &[(
341 &'b solana_program::account_info::AccountInfo<'a>,
342 bool,
343 bool,
344 )],
345 ) -> solana_program::entrypoint::ProgramResult {
346 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
347 accounts.push(solana_program::instruction::AccountMeta::new(
348 *self.distribution.key,
349 false,
350 ));
351 accounts.push(solana_program::instruction::AccountMeta::new(
352 *self.payer.key,
353 true,
354 ));
355 if let Some(authority) = self.authority {
356 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
357 *authority.key,
358 true,
359 ));
360 } else {
361 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
362 crate::MPL_DISTRO_ID,
363 false,
364 ));
365 }
366 accounts.push(solana_program::instruction::AccountMeta::new(
367 *self.fee_wallet.key,
368 false,
369 ));
370 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
371 *self.system_program.key,
372 false,
373 ));
374 remaining_accounts.iter().for_each(|remaining_account| {
375 accounts.push(solana_program::instruction::AccountMeta {
376 pubkey: *remaining_account.0.key,
377 is_signer: remaining_account.1,
378 is_writable: remaining_account.2,
379 })
380 });
381 let mut data = UpdateDistributionInstructionData::new()
382 .try_to_vec()
383 .unwrap();
384 let mut args = self.__args.try_to_vec().unwrap();
385 data.append(&mut args);
386
387 let instruction = solana_program::instruction::Instruction {
388 program_id: crate::MPL_DISTRO_ID,
389 accounts,
390 data,
391 };
392 let mut account_infos = Vec::with_capacity(5 + 1 + remaining_accounts.len());
393 account_infos.push(self.__program.clone());
394 account_infos.push(self.distribution.clone());
395 account_infos.push(self.payer.clone());
396 if let Some(authority) = self.authority {
397 account_infos.push(authority.clone());
398 }
399 account_infos.push(self.fee_wallet.clone());
400 account_infos.push(self.system_program.clone());
401 remaining_accounts
402 .iter()
403 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
404
405 if signers_seeds.is_empty() {
406 solana_program::program::invoke(&instruction, &account_infos)
407 } else {
408 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
409 }
410 }
411}
412
413pub struct UpdateDistributionCpiBuilder<'a, 'b> {
423 instruction: Box<UpdateDistributionCpiBuilderInstruction<'a, 'b>>,
424}
425
426impl<'a, 'b> UpdateDistributionCpiBuilder<'a, 'b> {
427 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
428 let instruction = Box::new(UpdateDistributionCpiBuilderInstruction {
429 __program: program,
430 distribution: None,
431 payer: None,
432 authority: None,
433 fee_wallet: None,
434 system_program: None,
435 merkle_root: None,
436 tree_height: None,
437 start_time: None,
438 end_time: None,
439 total_claimants: None,
440 new_authority: None,
441 name: None,
442 new_permissioned_distributor: None,
443 __remaining_accounts: Vec::new(),
444 });
445 Self { instruction }
446 }
447 #[inline(always)]
449 pub fn distribution(
450 &mut self,
451 distribution: &'b solana_program::account_info::AccountInfo<'a>,
452 ) -> &mut Self {
453 self.instruction.distribution = Some(distribution);
454 self
455 }
456 #[inline(always)]
458 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
459 self.instruction.payer = Some(payer);
460 self
461 }
462 #[inline(always)]
465 pub fn authority(
466 &mut self,
467 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
468 ) -> &mut Self {
469 self.instruction.authority = authority;
470 self
471 }
472 #[inline(always)]
474 pub fn fee_wallet(
475 &mut self,
476 fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
477 ) -> &mut Self {
478 self.instruction.fee_wallet = Some(fee_wallet);
479 self
480 }
481 #[inline(always)]
483 pub fn system_program(
484 &mut self,
485 system_program: &'b solana_program::account_info::AccountInfo<'a>,
486 ) -> &mut Self {
487 self.instruction.system_program = Some(system_program);
488 self
489 }
490 #[inline(always)]
492 pub fn merkle_root(&mut self, merkle_root: [u8; 32]) -> &mut Self {
493 self.instruction.merkle_root = Some(merkle_root);
494 self
495 }
496 #[inline(always)]
498 pub fn tree_height(&mut self, tree_height: u8) -> &mut Self {
499 self.instruction.tree_height = Some(tree_height);
500 self
501 }
502 #[inline(always)]
504 pub fn start_time(&mut self, start_time: i64) -> &mut Self {
505 self.instruction.start_time = Some(start_time);
506 self
507 }
508 #[inline(always)]
510 pub fn end_time(&mut self, end_time: i64) -> &mut Self {
511 self.instruction.end_time = Some(end_time);
512 self
513 }
514 #[inline(always)]
516 pub fn total_claimants(&mut self, total_claimants: u64) -> &mut Self {
517 self.instruction.total_claimants = Some(total_claimants);
518 self
519 }
520 #[inline(always)]
522 pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
523 self.instruction.new_authority = Some(new_authority);
524 self
525 }
526 #[inline(always)]
528 pub fn name(&mut self, name: String) -> &mut Self {
529 self.instruction.name = Some(name);
530 self
531 }
532 #[inline(always)]
534 pub fn new_permissioned_distributor(
535 &mut self,
536 new_permissioned_distributor: Pubkey,
537 ) -> &mut Self {
538 self.instruction.new_permissioned_distributor = Some(new_permissioned_distributor);
539 self
540 }
541 #[inline(always)]
543 pub fn add_remaining_account(
544 &mut self,
545 account: &'b solana_program::account_info::AccountInfo<'a>,
546 is_writable: bool,
547 is_signer: bool,
548 ) -> &mut Self {
549 self.instruction
550 .__remaining_accounts
551 .push((account, is_writable, is_signer));
552 self
553 }
554 #[inline(always)]
559 pub fn add_remaining_accounts(
560 &mut self,
561 accounts: &[(
562 &'b solana_program::account_info::AccountInfo<'a>,
563 bool,
564 bool,
565 )],
566 ) -> &mut Self {
567 self.instruction
568 .__remaining_accounts
569 .extend_from_slice(accounts);
570 self
571 }
572 #[inline(always)]
573 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
574 self.invoke_signed(&[])
575 }
576 #[allow(clippy::clone_on_copy)]
577 #[allow(clippy::vec_init_then_push)]
578 pub fn invoke_signed(
579 &self,
580 signers_seeds: &[&[&[u8]]],
581 ) -> solana_program::entrypoint::ProgramResult {
582 let args = UpdateDistributionInstructionArgs {
583 merkle_root: self.instruction.merkle_root.clone(),
584 tree_height: self.instruction.tree_height.clone(),
585 start_time: self.instruction.start_time.clone(),
586 end_time: self.instruction.end_time.clone(),
587 total_claimants: self.instruction.total_claimants.clone(),
588 new_authority: self.instruction.new_authority.clone(),
589 name: self.instruction.name.clone(),
590 new_permissioned_distributor: self.instruction.new_permissioned_distributor.clone(),
591 };
592 let instruction = UpdateDistributionCpi {
593 __program: self.instruction.__program,
594
595 distribution: self
596 .instruction
597 .distribution
598 .expect("distribution is not set"),
599
600 payer: self.instruction.payer.expect("payer is not set"),
601
602 authority: self.instruction.authority,
603
604 fee_wallet: self.instruction.fee_wallet.expect("fee_wallet is not set"),
605
606 system_program: self
607 .instruction
608 .system_program
609 .expect("system_program is not set"),
610 __args: args,
611 };
612 instruction.invoke_signed_with_remaining_accounts(
613 signers_seeds,
614 &self.instruction.__remaining_accounts,
615 )
616 }
617}
618
619struct UpdateDistributionCpiBuilderInstruction<'a, 'b> {
620 __program: &'b solana_program::account_info::AccountInfo<'a>,
621 distribution: Option<&'b solana_program::account_info::AccountInfo<'a>>,
622 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
623 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
624 fee_wallet: Option<&'b solana_program::account_info::AccountInfo<'a>>,
625 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
626 merkle_root: Option<[u8; 32]>,
627 tree_height: Option<u8>,
628 start_time: Option<i64>,
629 end_time: Option<i64>,
630 total_claimants: Option<u64>,
631 new_authority: Option<Pubkey>,
632 name: Option<String>,
633 new_permissioned_distributor: Option<Pubkey>,
634 __remaining_accounts: Vec<(
636 &'b solana_program::account_info::AccountInfo<'a>,
637 bool,
638 bool,
639 )>,
640}