Skip to main content

release_test_client/generated/instructions/
initiate_authority_transfer.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12/// Accounts.
13#[derive(Debug)]
14pub struct InitiateAuthorityTransfer {
15    /// The whitelist account
16    pub whitelist_account: solana_program::pubkey::Pubkey,
17    /// The whitelist authority
18    pub whitelist_authority: solana_program::pubkey::Pubkey,
19}
20
21impl InitiateAuthorityTransfer {
22    pub fn instruction(
23        &self,
24        args: InitiateAuthorityTransferInstructionArgs,
25    ) -> solana_program::instruction::Instruction {
26        self.instruction_with_remaining_accounts(args, &[])
27    }
28    #[allow(clippy::vec_init_then_push)]
29    pub fn instruction_with_remaining_accounts(
30        &self,
31        args: InitiateAuthorityTransferInstructionArgs,
32        remaining_accounts: &[solana_program::instruction::AccountMeta],
33    ) -> solana_program::instruction::Instruction {
34        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
35        accounts.push(solana_program::instruction::AccountMeta::new(
36            self.whitelist_account,
37            false,
38        ));
39        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
40            self.whitelist_authority,
41            true,
42        ));
43        accounts.extend_from_slice(remaining_accounts);
44        let mut data = borsh::to_vec(&InitiateAuthorityTransferInstructionData::new()).unwrap();
45        let mut args = borsh::to_vec(&args).unwrap();
46        data.append(&mut args);
47
48        solana_program::instruction::Instruction {
49            program_id: crate::RELEASE_TEST_PROGRAM_ID,
50            accounts,
51            data,
52        }
53    }
54}
55
56#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
57#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
58pub struct InitiateAuthorityTransferInstructionData {
59    discriminator: u8,
60}
61
62impl InitiateAuthorityTransferInstructionData {
63    pub fn new() -> Self {
64        Self { discriminator: 1 }
65    }
66}
67
68impl Default for InitiateAuthorityTransferInstructionData {
69    fn default() -> Self {
70        Self::new()
71    }
72}
73
74#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
75#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
76pub struct InitiateAuthorityTransferInstructionArgs {
77    pub new_authority: Pubkey,
78}
79
80/// Instruction builder for `InitiateAuthorityTransfer`.
81///
82/// ### Accounts:
83///
84///   0. `[writable]` whitelist_account
85///   1. `[signer]` whitelist_authority
86#[derive(Clone, Debug, Default)]
87pub struct InitiateAuthorityTransferBuilder {
88    whitelist_account: Option<solana_program::pubkey::Pubkey>,
89    whitelist_authority: Option<solana_program::pubkey::Pubkey>,
90    new_authority: Option<Pubkey>,
91    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
92}
93
94impl InitiateAuthorityTransferBuilder {
95    pub fn new() -> Self {
96        Self::default()
97    }
98    /// The whitelist account
99    #[inline(always)]
100    pub fn whitelist_account(
101        &mut self,
102        whitelist_account: solana_program::pubkey::Pubkey,
103    ) -> &mut Self {
104        self.whitelist_account = Some(whitelist_account);
105        self
106    }
107    /// The whitelist authority
108    #[inline(always)]
109    pub fn whitelist_authority(
110        &mut self,
111        whitelist_authority: solana_program::pubkey::Pubkey,
112    ) -> &mut Self {
113        self.whitelist_authority = Some(whitelist_authority);
114        self
115    }
116    #[inline(always)]
117    pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
118        self.new_authority = Some(new_authority);
119        self
120    }
121    /// Add an additional account to the instruction.
122    #[inline(always)]
123    pub fn add_remaining_account(
124        &mut self,
125        account: solana_program::instruction::AccountMeta,
126    ) -> &mut Self {
127        self.__remaining_accounts.push(account);
128        self
129    }
130    /// Add additional accounts to the instruction.
131    #[inline(always)]
132    pub fn add_remaining_accounts(
133        &mut self,
134        accounts: &[solana_program::instruction::AccountMeta],
135    ) -> &mut Self {
136        self.__remaining_accounts.extend_from_slice(accounts);
137        self
138    }
139    #[allow(clippy::clone_on_copy)]
140    pub fn instruction(&self) -> solana_program::instruction::Instruction {
141        let accounts = InitiateAuthorityTransfer {
142            whitelist_account: self
143                .whitelist_account
144                .expect("whitelist_account is not set"),
145            whitelist_authority: self
146                .whitelist_authority
147                .expect("whitelist_authority is not set"),
148        };
149        let args = InitiateAuthorityTransferInstructionArgs {
150            new_authority: self
151                .new_authority
152                .clone()
153                .expect("new_authority is not set"),
154        };
155
156        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
157    }
158}
159
160/// `initiate_authority_transfer` CPI accounts.
161pub struct InitiateAuthorityTransferCpiAccounts<'a, 'b> {
162    /// The whitelist account
163    pub whitelist_account: &'b solana_program::account_info::AccountInfo<'a>,
164    /// The whitelist authority
165    pub whitelist_authority: &'b solana_program::account_info::AccountInfo<'a>,
166}
167
168/// `initiate_authority_transfer` CPI instruction.
169pub struct InitiateAuthorityTransferCpi<'a, 'b> {
170    /// The program to invoke.
171    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
172    /// The whitelist account
173    pub whitelist_account: &'b solana_program::account_info::AccountInfo<'a>,
174    /// The whitelist authority
175    pub whitelist_authority: &'b solana_program::account_info::AccountInfo<'a>,
176    /// The arguments for the instruction.
177    pub __args: InitiateAuthorityTransferInstructionArgs,
178}
179
180impl<'a, 'b> InitiateAuthorityTransferCpi<'a, 'b> {
181    pub fn new(
182        program: &'b solana_program::account_info::AccountInfo<'a>,
183        accounts: InitiateAuthorityTransferCpiAccounts<'a, 'b>,
184        args: InitiateAuthorityTransferInstructionArgs,
185    ) -> Self {
186        Self {
187            __program: program,
188            whitelist_account: accounts.whitelist_account,
189            whitelist_authority: accounts.whitelist_authority,
190            __args: args,
191        }
192    }
193    #[inline(always)]
194    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
195        self.invoke_signed_with_remaining_accounts(&[], &[])
196    }
197    #[inline(always)]
198    pub fn invoke_with_remaining_accounts(
199        &self,
200        remaining_accounts: &[(
201            &'b solana_program::account_info::AccountInfo<'a>,
202            bool,
203            bool,
204        )],
205    ) -> solana_program::entrypoint::ProgramResult {
206        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
207    }
208    #[inline(always)]
209    pub fn invoke_signed(
210        &self,
211        signers_seeds: &[&[&[u8]]],
212    ) -> solana_program::entrypoint::ProgramResult {
213        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
214    }
215    #[allow(clippy::clone_on_copy)]
216    #[allow(clippy::vec_init_then_push)]
217    pub fn invoke_signed_with_remaining_accounts(
218        &self,
219        signers_seeds: &[&[&[u8]]],
220        remaining_accounts: &[(
221            &'b solana_program::account_info::AccountInfo<'a>,
222            bool,
223            bool,
224        )],
225    ) -> solana_program::entrypoint::ProgramResult {
226        let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
227        accounts.push(solana_program::instruction::AccountMeta::new(
228            *self.whitelist_account.key,
229            false,
230        ));
231        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
232            *self.whitelist_authority.key,
233            true,
234        ));
235        remaining_accounts.iter().for_each(|remaining_account| {
236            accounts.push(solana_program::instruction::AccountMeta {
237                pubkey: *remaining_account.0.key,
238                is_signer: remaining_account.1,
239                is_writable: remaining_account.2,
240            })
241        });
242        let mut data = borsh::to_vec(&InitiateAuthorityTransferInstructionData::new()).unwrap();
243        let mut args = borsh::to_vec(&self.__args).unwrap();
244        data.append(&mut args);
245
246        let instruction = solana_program::instruction::Instruction {
247            program_id: crate::RELEASE_TEST_PROGRAM_ID,
248            accounts,
249            data,
250        };
251        let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
252        account_infos.push(self.__program.clone());
253        account_infos.push(self.whitelist_account.clone());
254        account_infos.push(self.whitelist_authority.clone());
255        remaining_accounts
256            .iter()
257            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
258
259        if signers_seeds.is_empty() {
260            solana_program::program::invoke(&instruction, &account_infos)
261        } else {
262            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
263        }
264    }
265}
266
267/// Instruction builder for `InitiateAuthorityTransfer` via CPI.
268///
269/// ### Accounts:
270///
271///   0. `[writable]` whitelist_account
272///   1. `[signer]` whitelist_authority
273#[derive(Clone, Debug)]
274pub struct InitiateAuthorityTransferCpiBuilder<'a, 'b> {
275    instruction: Box<InitiateAuthorityTransferCpiBuilderInstruction<'a, 'b>>,
276}
277
278impl<'a, 'b> InitiateAuthorityTransferCpiBuilder<'a, 'b> {
279    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
280        let instruction = Box::new(InitiateAuthorityTransferCpiBuilderInstruction {
281            __program: program,
282            whitelist_account: None,
283            whitelist_authority: None,
284            new_authority: None,
285            __remaining_accounts: Vec::new(),
286        });
287        Self { instruction }
288    }
289    /// The whitelist account
290    #[inline(always)]
291    pub fn whitelist_account(
292        &mut self,
293        whitelist_account: &'b solana_program::account_info::AccountInfo<'a>,
294    ) -> &mut Self {
295        self.instruction.whitelist_account = Some(whitelist_account);
296        self
297    }
298    /// The whitelist authority
299    #[inline(always)]
300    pub fn whitelist_authority(
301        &mut self,
302        whitelist_authority: &'b solana_program::account_info::AccountInfo<'a>,
303    ) -> &mut Self {
304        self.instruction.whitelist_authority = Some(whitelist_authority);
305        self
306    }
307    #[inline(always)]
308    pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
309        self.instruction.new_authority = Some(new_authority);
310        self
311    }
312    /// Add an additional account to the instruction.
313    #[inline(always)]
314    pub fn add_remaining_account(
315        &mut self,
316        account: &'b solana_program::account_info::AccountInfo<'a>,
317        is_writable: bool,
318        is_signer: bool,
319    ) -> &mut Self {
320        self.instruction
321            .__remaining_accounts
322            .push((account, is_writable, is_signer));
323        self
324    }
325    /// Add additional accounts to the instruction.
326    ///
327    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
328    /// and a `bool` indicating whether the account is a signer or not.
329    #[inline(always)]
330    pub fn add_remaining_accounts(
331        &mut self,
332        accounts: &[(
333            &'b solana_program::account_info::AccountInfo<'a>,
334            bool,
335            bool,
336        )],
337    ) -> &mut Self {
338        self.instruction
339            .__remaining_accounts
340            .extend_from_slice(accounts);
341        self
342    }
343    #[inline(always)]
344    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
345        self.invoke_signed(&[])
346    }
347    #[allow(clippy::clone_on_copy)]
348    #[allow(clippy::vec_init_then_push)]
349    pub fn invoke_signed(
350        &self,
351        signers_seeds: &[&[&[u8]]],
352    ) -> solana_program::entrypoint::ProgramResult {
353        let args = InitiateAuthorityTransferInstructionArgs {
354            new_authority: self
355                .instruction
356                .new_authority
357                .clone()
358                .expect("new_authority is not set"),
359        };
360        let instruction = InitiateAuthorityTransferCpi {
361            __program: self.instruction.__program,
362
363            whitelist_account: self
364                .instruction
365                .whitelist_account
366                .expect("whitelist_account is not set"),
367
368            whitelist_authority: self
369                .instruction
370                .whitelist_authority
371                .expect("whitelist_authority is not set"),
372            __args: args,
373        };
374        instruction.invoke_signed_with_remaining_accounts(
375            signers_seeds,
376            &self.instruction.__remaining_accounts,
377        )
378    }
379}
380
381#[derive(Clone, Debug)]
382struct InitiateAuthorityTransferCpiBuilderInstruction<'a, 'b> {
383    __program: &'b solana_program::account_info::AccountInfo<'a>,
384    whitelist_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
385    whitelist_authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
386    new_authority: Option<Pubkey>,
387    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
388    __remaining_accounts: Vec<(
389        &'b solana_program::account_info::AccountInfo<'a>,
390        bool,
391        bool,
392    )>,
393}