solana_native_programs/system_program/generated/instructions/
allocate.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct Allocate {
13 pub account: solana_program::pubkey::Pubkey,
15}
16
17impl Allocate {
18 pub fn instruction(
19 &self,
20 args: AllocateInstructionArgs,
21 ) -> solana_program::instruction::Instruction {
22 self.instruction_with_remaining_accounts(args, &[])
23 }
24 #[allow(clippy::vec_init_then_push)]
25 pub fn instruction_with_remaining_accounts(
26 &self,
27 args: AllocateInstructionArgs,
28 remaining_accounts: &[solana_program::instruction::AccountMeta],
29 ) -> solana_program::instruction::Instruction {
30 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
31 accounts.push(solana_program::instruction::AccountMeta::new(
32 self.account,
33 true,
34 ));
35 accounts.extend_from_slice(remaining_accounts);
36 let mut data = AllocateInstructionData::new().try_to_vec().unwrap();
37 let mut args = args.try_to_vec().unwrap();
38 data.append(&mut args);
39
40 solana_program::instruction::Instruction {
41 program_id: crate::SYSTEM_PROGRAM_ID,
42 accounts,
43 data,
44 }
45 }
46}
47
48#[derive(BorshDeserialize, BorshSerialize)]
49struct AllocateInstructionData {
50 discriminator: u32,
51}
52
53impl AllocateInstructionData {
54 fn new() -> Self {
55 Self { discriminator: 8 }
56 }
57}
58
59#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
60#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61pub struct AllocateInstructionArgs {
62 pub space: u64,
63}
64
65#[derive(Default)]
71pub struct AllocateBuilder {
72 account: Option<solana_program::pubkey::Pubkey>,
73 space: Option<u64>,
74 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
75}
76
77impl AllocateBuilder {
78 pub fn new() -> Self {
79 Self::default()
80 }
81 #[inline(always)]
83 pub fn account(&mut self, account: solana_program::pubkey::Pubkey) -> &mut Self {
84 self.account = Some(account);
85 self
86 }
87 #[inline(always)]
88 pub fn space(&mut self, space: u64) -> &mut Self {
89 self.space = Some(space);
90 self
91 }
92 #[inline(always)]
94 pub fn add_remaining_account(
95 &mut self,
96 account: solana_program::instruction::AccountMeta,
97 ) -> &mut Self {
98 self.__remaining_accounts.push(account);
99 self
100 }
101 #[inline(always)]
103 pub fn add_remaining_accounts(
104 &mut self,
105 accounts: &[solana_program::instruction::AccountMeta],
106 ) -> &mut Self {
107 self.__remaining_accounts.extend_from_slice(accounts);
108 self
109 }
110 #[allow(clippy::clone_on_copy)]
111 pub fn instruction(&self) -> solana_program::instruction::Instruction {
112 let accounts = Allocate {
113 account: self.account.expect("account is not set"),
114 };
115 let args = AllocateInstructionArgs {
116 space: self.space.clone().expect("space is not set"),
117 };
118
119 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
120 }
121}
122
123pub struct AllocateCpiAccounts<'a, 'b> {
125 pub account: &'b solana_program::account_info::AccountInfo<'a>,
127}
128
129pub struct AllocateCpi<'a, 'b> {
131 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
133 pub account: &'b solana_program::account_info::AccountInfo<'a>,
135 pub __args: AllocateInstructionArgs,
137}
138
139impl<'a, 'b> AllocateCpi<'a, 'b> {
140 pub fn new(
141 program: &'b solana_program::account_info::AccountInfo<'a>,
142 accounts: AllocateCpiAccounts<'a, 'b>,
143 args: AllocateInstructionArgs,
144 ) -> Self {
145 Self {
146 __program: program,
147 account: accounts.account,
148 __args: args,
149 }
150 }
151 #[inline(always)]
152 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
153 self.invoke_signed_with_remaining_accounts(&[], &[])
154 }
155 #[inline(always)]
156 pub fn invoke_with_remaining_accounts(
157 &self,
158 remaining_accounts: &[(
159 &'b solana_program::account_info::AccountInfo<'a>,
160 bool,
161 bool,
162 )],
163 ) -> solana_program::entrypoint::ProgramResult {
164 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
165 }
166 #[inline(always)]
167 pub fn invoke_signed(
168 &self,
169 signers_seeds: &[&[&[u8]]],
170 ) -> solana_program::entrypoint::ProgramResult {
171 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
172 }
173 #[allow(clippy::clone_on_copy)]
174 #[allow(clippy::vec_init_then_push)]
175 pub fn invoke_signed_with_remaining_accounts(
176 &self,
177 signers_seeds: &[&[&[u8]]],
178 remaining_accounts: &[(
179 &'b solana_program::account_info::AccountInfo<'a>,
180 bool,
181 bool,
182 )],
183 ) -> solana_program::entrypoint::ProgramResult {
184 let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
185 accounts.push(solana_program::instruction::AccountMeta::new(
186 *self.account.key,
187 true,
188 ));
189 remaining_accounts.iter().for_each(|remaining_account| {
190 accounts.push(solana_program::instruction::AccountMeta {
191 pubkey: *remaining_account.0.key,
192 is_signer: remaining_account.1,
193 is_writable: remaining_account.2,
194 })
195 });
196 let mut data = AllocateInstructionData::new().try_to_vec().unwrap();
197 let mut args = self.__args.try_to_vec().unwrap();
198 data.append(&mut args);
199
200 let instruction = solana_program::instruction::Instruction {
201 program_id: crate::SYSTEM_PROGRAM_ID,
202 accounts,
203 data,
204 };
205 let mut account_infos = Vec::with_capacity(1 + 1 + remaining_accounts.len());
206 account_infos.push(self.__program.clone());
207 account_infos.push(self.account.clone());
208 remaining_accounts
209 .iter()
210 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
211
212 if signers_seeds.is_empty() {
213 solana_program::program::invoke(&instruction, &account_infos)
214 } else {
215 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
216 }
217 }
218}
219
220pub struct AllocateCpiBuilder<'a, 'b> {
226 instruction: Box<AllocateCpiBuilderInstruction<'a, 'b>>,
227}
228
229impl<'a, 'b> AllocateCpiBuilder<'a, 'b> {
230 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
231 let instruction = Box::new(AllocateCpiBuilderInstruction {
232 __program: program,
233 account: None,
234 space: None,
235 __remaining_accounts: Vec::new(),
236 });
237 Self { instruction }
238 }
239 #[inline(always)]
241 pub fn account(
242 &mut self,
243 account: &'b solana_program::account_info::AccountInfo<'a>,
244 ) -> &mut Self {
245 self.instruction.account = Some(account);
246 self
247 }
248 #[inline(always)]
249 pub fn space(&mut self, space: u64) -> &mut Self {
250 self.instruction.space = Some(space);
251 self
252 }
253 #[inline(always)]
255 pub fn add_remaining_account(
256 &mut self,
257 account: &'b solana_program::account_info::AccountInfo<'a>,
258 is_writable: bool,
259 is_signer: bool,
260 ) -> &mut Self {
261 self.instruction
262 .__remaining_accounts
263 .push((account, is_writable, is_signer));
264 self
265 }
266 #[inline(always)]
271 pub fn add_remaining_accounts(
272 &mut self,
273 accounts: &[(
274 &'b solana_program::account_info::AccountInfo<'a>,
275 bool,
276 bool,
277 )],
278 ) -> &mut Self {
279 self.instruction
280 .__remaining_accounts
281 .extend_from_slice(accounts);
282 self
283 }
284 #[inline(always)]
285 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
286 self.invoke_signed(&[])
287 }
288 #[allow(clippy::clone_on_copy)]
289 #[allow(clippy::vec_init_then_push)]
290 pub fn invoke_signed(
291 &self,
292 signers_seeds: &[&[&[u8]]],
293 ) -> solana_program::entrypoint::ProgramResult {
294 let args = AllocateInstructionArgs {
295 space: self.instruction.space.clone().expect("space is not set"),
296 };
297 let instruction = AllocateCpi {
298 __program: self.instruction.__program,
299
300 account: self.instruction.account.expect("account is not set"),
301 __args: args,
302 };
303 instruction.invoke_signed_with_remaining_accounts(
304 signers_seeds,
305 &self.instruction.__remaining_accounts,
306 )
307 }
308}
309
310struct AllocateCpiBuilderInstruction<'a, 'b> {
311 __program: &'b solana_program::account_info::AccountInfo<'a>,
312 account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
313 space: Option<u64>,
314 __remaining_accounts: Vec<(
316 &'b solana_program::account_info::AccountInfo<'a>,
317 bool,
318 bool,
319 )>,
320}