Skip to main content

mpl_distro/generated/instructions/
update_distribution.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;
10use solana_program::pubkey::Pubkey;
11
12/// Accounts.
13pub struct UpdateDistribution {
14    /// The address of the new distribution
15    pub distribution: solana_program::pubkey::Pubkey,
16    /// The account paying for the storage fees
17    pub payer: solana_program::pubkey::Pubkey,
18    /// The authority of the distribution
19    pub authority: Option<solana_program::pubkey::Pubkey>,
20    /// The wallet where fees are sent
21    pub fee_wallet: solana_program::pubkey::Pubkey,
22    /// The system program
23    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/// Instruction builder for `UpdateDistribution`.
105///
106/// ### Accounts:
107///
108///   0. `[writable]` distribution
109///   1. `[writable, signer]` payer
110///   2. `[signer, optional]` authority
111///   3. `[writable, optional]` fee_wallet (default to `9kFjQsxtpBsaw8s7aUyiY3wazYDNgFP4Lj5rsBVVF8tb`)
112///   4. `[optional]` system_program (default to `11111111111111111111111111111111`)
113#[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    /// The address of the new distribution
136    #[inline(always)]
137    pub fn distribution(&mut self, distribution: solana_program::pubkey::Pubkey) -> &mut Self {
138        self.distribution = Some(distribution);
139        self
140    }
141    /// The account paying for the storage fees
142    #[inline(always)]
143    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
144        self.payer = Some(payer);
145        self
146    }
147    /// `[optional account]`
148    /// The authority of the distribution
149    #[inline(always)]
150    pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
151        self.authority = authority;
152        self
153    }
154    /// `[optional account, default to '9kFjQsxtpBsaw8s7aUyiY3wazYDNgFP4Lj5rsBVVF8tb']`
155    /// The wallet where fees are sent
156    #[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    /// `[optional account, default to '11111111111111111111111111111111']`
162    /// The system program
163    #[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    /// `[optional argument]`
169    #[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    /// `[optional argument]`
175    #[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    /// `[optional argument]`
181    #[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    /// `[optional argument]`
187    #[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    /// `[optional argument]`
193    #[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    /// `[optional argument]`
199    #[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    /// `[optional argument]`
205    #[inline(always)]
206    pub fn name(&mut self, name: String) -> &mut Self {
207        self.name = Some(name);
208        self
209    }
210    /// `[optional argument]`
211    #[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    /// Add an aditional account to the instruction.
220    #[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    /// Add additional accounts to the instruction.
229    #[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
265/// `update_distribution` CPI accounts.
266pub struct UpdateDistributionCpiAccounts<'a, 'b> {
267    /// The address of the new distribution
268    pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
269    /// The account paying for the storage fees
270    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
271    /// The authority of the distribution
272    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
273    /// The wallet where fees are sent
274    pub fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
275    /// The system program
276    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
277}
278
279/// `update_distribution` CPI instruction.
280pub struct UpdateDistributionCpi<'a, 'b> {
281    /// The program to invoke.
282    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
283    /// The address of the new distribution
284    pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
285    /// The account paying for the storage fees
286    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
287    /// The authority of the distribution
288    pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
289    /// The wallet where fees are sent
290    pub fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
291    /// The system program
292    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
293    /// The arguments for the instruction.
294    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
413/// Instruction builder for `UpdateDistribution` via CPI.
414///
415/// ### Accounts:
416///
417///   0. `[writable]` distribution
418///   1. `[writable, signer]` payer
419///   2. `[signer, optional]` authority
420///   3. `[writable]` fee_wallet
421///   4. `[]` system_program
422pub 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    /// The address of the new distribution
448    #[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    /// The account paying for the storage fees
457    #[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    /// `[optional account]`
463    /// The authority of the distribution
464    #[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    /// The wallet where fees are sent
473    #[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    /// The system program
482    #[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    /// `[optional argument]`
491    #[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    /// `[optional argument]`
497    #[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    /// `[optional argument]`
503    #[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    /// `[optional argument]`
509    #[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    /// `[optional argument]`
515    #[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    /// `[optional argument]`
521    #[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    /// `[optional argument]`
527    #[inline(always)]
528    pub fn name(&mut self, name: String) -> &mut Self {
529        self.instruction.name = Some(name);
530        self
531    }
532    /// `[optional argument]`
533    #[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    /// Add an additional account to the instruction.
542    #[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    /// Add additional accounts to the instruction.
555    ///
556    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
557    /// and a `bool` indicating whether the account is a signer or not.
558    #[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    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
635    __remaining_accounts: Vec<(
636        &'b solana_program::account_info::AccountInfo<'a>,
637        bool,
638        bool,
639    )>,
640}