solana_system_client/generated/instructions/
create_account.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12pub struct CreateAccount {
14 pub payer: solana_program::pubkey::Pubkey,
15
16 pub new_account: solana_program::pubkey::Pubkey,
17}
18
19impl CreateAccount {
20 pub fn instruction(
21 &self,
22 args: CreateAccountInstructionArgs,
23 ) -> solana_program::instruction::Instruction {
24 self.instruction_with_remaining_accounts(args, &[])
25 }
26 #[allow(clippy::vec_init_then_push)]
27 pub fn instruction_with_remaining_accounts(
28 &self,
29 args: CreateAccountInstructionArgs,
30 remaining_accounts: &[solana_program::instruction::AccountMeta],
31 ) -> solana_program::instruction::Instruction {
32 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
33 accounts.push(solana_program::instruction::AccountMeta::new(
34 self.payer, true,
35 ));
36 accounts.push(solana_program::instruction::AccountMeta::new(
37 self.new_account,
38 true,
39 ));
40 accounts.extend_from_slice(remaining_accounts);
41 let mut data = CreateAccountInstructionData::new().try_to_vec().unwrap();
42 let mut args = args.try_to_vec().unwrap();
43 data.append(&mut args);
44
45 solana_program::instruction::Instruction {
46 program_id: crate::SYSTEM_ID,
47 accounts,
48 data,
49 }
50 }
51}
52
53#[derive(BorshDeserialize, BorshSerialize)]
54pub struct CreateAccountInstructionData {
55 discriminator: u32,
56}
57
58impl CreateAccountInstructionData {
59 pub fn new() -> Self {
60 Self { discriminator: 0 }
61 }
62}
63
64impl Default for CreateAccountInstructionData {
65 fn default() -> Self {
66 Self::new()
67 }
68}
69
70#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72pub struct CreateAccountInstructionArgs {
73 pub lamports: u64,
74 pub space: u64,
75 pub program_address: Pubkey,
76}
77
78#[derive(Clone, Debug, Default)]
85pub struct CreateAccountBuilder {
86 payer: Option<solana_program::pubkey::Pubkey>,
87 new_account: Option<solana_program::pubkey::Pubkey>,
88 lamports: Option<u64>,
89 space: Option<u64>,
90 program_address: Option<Pubkey>,
91 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
92}
93
94impl CreateAccountBuilder {
95 pub fn new() -> Self {
96 Self::default()
97 }
98 #[inline(always)]
99 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
100 self.payer = Some(payer);
101 self
102 }
103 #[inline(always)]
104 pub fn new_account(&mut self, new_account: solana_program::pubkey::Pubkey) -> &mut Self {
105 self.new_account = Some(new_account);
106 self
107 }
108 #[inline(always)]
109 pub fn lamports(&mut self, lamports: u64) -> &mut Self {
110 self.lamports = Some(lamports);
111 self
112 }
113 #[inline(always)]
114 pub fn space(&mut self, space: u64) -> &mut Self {
115 self.space = Some(space);
116 self
117 }
118 #[inline(always)]
119 pub fn program_address(&mut self, program_address: Pubkey) -> &mut Self {
120 self.program_address = Some(program_address);
121 self
122 }
123 #[inline(always)]
125 pub fn add_remaining_account(
126 &mut self,
127 account: solana_program::instruction::AccountMeta,
128 ) -> &mut Self {
129 self.__remaining_accounts.push(account);
130 self
131 }
132 #[inline(always)]
134 pub fn add_remaining_accounts(
135 &mut self,
136 accounts: &[solana_program::instruction::AccountMeta],
137 ) -> &mut Self {
138 self.__remaining_accounts.extend_from_slice(accounts);
139 self
140 }
141 #[allow(clippy::clone_on_copy)]
142 pub fn instruction(&self) -> solana_program::instruction::Instruction {
143 let accounts = CreateAccount {
144 payer: self.payer.expect("payer is not set"),
145 new_account: self.new_account.expect("new_account is not set"),
146 };
147 let args = CreateAccountInstructionArgs {
148 lamports: self.lamports.clone().expect("lamports is not set"),
149 space: self.space.clone().expect("space is not set"),
150 program_address: self
151 .program_address
152 .clone()
153 .expect("program_address is not set"),
154 };
155
156 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
157 }
158}
159
160pub struct CreateAccountCpiAccounts<'a, 'b> {
162 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
163
164 pub new_account: &'b solana_program::account_info::AccountInfo<'a>,
165}
166
167pub struct CreateAccountCpi<'a, 'b> {
169 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
171
172 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
173
174 pub new_account: &'b solana_program::account_info::AccountInfo<'a>,
175 pub __args: CreateAccountInstructionArgs,
177}
178
179impl<'a, 'b> CreateAccountCpi<'a, 'b> {
180 pub fn new(
181 program: &'b solana_program::account_info::AccountInfo<'a>,
182 accounts: CreateAccountCpiAccounts<'a, 'b>,
183 args: CreateAccountInstructionArgs,
184 ) -> Self {
185 Self {
186 __program: program,
187 payer: accounts.payer,
188 new_account: accounts.new_account,
189 __args: args,
190 }
191 }
192 #[inline(always)]
193 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
194 self.invoke_signed_with_remaining_accounts(&[], &[])
195 }
196 #[inline(always)]
197 pub fn invoke_with_remaining_accounts(
198 &self,
199 remaining_accounts: &[(
200 &'b solana_program::account_info::AccountInfo<'a>,
201 bool,
202 bool,
203 )],
204 ) -> solana_program::entrypoint::ProgramResult {
205 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
206 }
207 #[inline(always)]
208 pub fn invoke_signed(
209 &self,
210 signers_seeds: &[&[&[u8]]],
211 ) -> solana_program::entrypoint::ProgramResult {
212 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
213 }
214 #[allow(clippy::clone_on_copy)]
215 #[allow(clippy::vec_init_then_push)]
216 pub fn invoke_signed_with_remaining_accounts(
217 &self,
218 signers_seeds: &[&[&[u8]]],
219 remaining_accounts: &[(
220 &'b solana_program::account_info::AccountInfo<'a>,
221 bool,
222 bool,
223 )],
224 ) -> solana_program::entrypoint::ProgramResult {
225 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
226 accounts.push(solana_program::instruction::AccountMeta::new(
227 *self.payer.key,
228 true,
229 ));
230 accounts.push(solana_program::instruction::AccountMeta::new(
231 *self.new_account.key,
232 true,
233 ));
234 remaining_accounts.iter().for_each(|remaining_account| {
235 accounts.push(solana_program::instruction::AccountMeta {
236 pubkey: *remaining_account.0.key,
237 is_signer: remaining_account.1,
238 is_writable: remaining_account.2,
239 })
240 });
241 let mut data = CreateAccountInstructionData::new().try_to_vec().unwrap();
242 let mut args = self.__args.try_to_vec().unwrap();
243 data.append(&mut args);
244
245 let instruction = solana_program::instruction::Instruction {
246 program_id: crate::SYSTEM_ID,
247 accounts,
248 data,
249 };
250 let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
251 account_infos.push(self.__program.clone());
252 account_infos.push(self.payer.clone());
253 account_infos.push(self.new_account.clone());
254 remaining_accounts
255 .iter()
256 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
257
258 if signers_seeds.is_empty() {
259 solana_program::program::invoke(&instruction, &account_infos)
260 } else {
261 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
262 }
263 }
264}
265
266#[derive(Clone, Debug)]
273pub struct CreateAccountCpiBuilder<'a, 'b> {
274 instruction: Box<CreateAccountCpiBuilderInstruction<'a, 'b>>,
275}
276
277impl<'a, 'b> CreateAccountCpiBuilder<'a, 'b> {
278 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
279 let instruction = Box::new(CreateAccountCpiBuilderInstruction {
280 __program: program,
281 payer: None,
282 new_account: None,
283 lamports: None,
284 space: None,
285 program_address: None,
286 __remaining_accounts: Vec::new(),
287 });
288 Self { instruction }
289 }
290 #[inline(always)]
291 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
292 self.instruction.payer = Some(payer);
293 self
294 }
295 #[inline(always)]
296 pub fn new_account(
297 &mut self,
298 new_account: &'b solana_program::account_info::AccountInfo<'a>,
299 ) -> &mut Self {
300 self.instruction.new_account = Some(new_account);
301 self
302 }
303 #[inline(always)]
304 pub fn lamports(&mut self, lamports: u64) -> &mut Self {
305 self.instruction.lamports = Some(lamports);
306 self
307 }
308 #[inline(always)]
309 pub fn space(&mut self, space: u64) -> &mut Self {
310 self.instruction.space = Some(space);
311 self
312 }
313 #[inline(always)]
314 pub fn program_address(&mut self, program_address: Pubkey) -> &mut Self {
315 self.instruction.program_address = Some(program_address);
316 self
317 }
318 #[inline(always)]
320 pub fn add_remaining_account(
321 &mut self,
322 account: &'b solana_program::account_info::AccountInfo<'a>,
323 is_writable: bool,
324 is_signer: bool,
325 ) -> &mut Self {
326 self.instruction
327 .__remaining_accounts
328 .push((account, is_writable, is_signer));
329 self
330 }
331 #[inline(always)]
336 pub fn add_remaining_accounts(
337 &mut self,
338 accounts: &[(
339 &'b solana_program::account_info::AccountInfo<'a>,
340 bool,
341 bool,
342 )],
343 ) -> &mut Self {
344 self.instruction
345 .__remaining_accounts
346 .extend_from_slice(accounts);
347 self
348 }
349 #[inline(always)]
350 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
351 self.invoke_signed(&[])
352 }
353 #[allow(clippy::clone_on_copy)]
354 #[allow(clippy::vec_init_then_push)]
355 pub fn invoke_signed(
356 &self,
357 signers_seeds: &[&[&[u8]]],
358 ) -> solana_program::entrypoint::ProgramResult {
359 let args = CreateAccountInstructionArgs {
360 lamports: self
361 .instruction
362 .lamports
363 .clone()
364 .expect("lamports is not set"),
365 space: self.instruction.space.clone().expect("space is not set"),
366 program_address: self
367 .instruction
368 .program_address
369 .clone()
370 .expect("program_address is not set"),
371 };
372 let instruction = CreateAccountCpi {
373 __program: self.instruction.__program,
374
375 payer: self.instruction.payer.expect("payer is not set"),
376
377 new_account: self
378 .instruction
379 .new_account
380 .expect("new_account is not set"),
381 __args: args,
382 };
383 instruction.invoke_signed_with_remaining_accounts(
384 signers_seeds,
385 &self.instruction.__remaining_accounts,
386 )
387 }
388}
389
390#[derive(Clone, Debug)]
391struct CreateAccountCpiBuilderInstruction<'a, 'b> {
392 __program: &'b solana_program::account_info::AccountInfo<'a>,
393 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
394 new_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
395 lamports: Option<u64>,
396 space: Option<u64>,
397 program_address: Option<Pubkey>,
398 __remaining_accounts: Vec<(
400 &'b solana_program::account_info::AccountInfo<'a>,
401 bool,
402 bool,
403 )>,
404}