Skip to main content

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