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