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