solana_native_programs/system_program/generated/instructions/
assign_with_seed.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12pub struct AssignWithSeed {
14 pub account: solana_program::pubkey::Pubkey,
16 pub base: solana_program::pubkey::Pubkey,
18}
19
20impl AssignWithSeed {
21 pub fn instruction(
22 &self,
23 args: AssignWithSeedInstructionArgs,
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: AssignWithSeedInstructionArgs,
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 = AssignWithSeedInstructionData::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 AssignWithSeedInstructionData {
56 discriminator: u32,
57}
58
59impl AssignWithSeedInstructionData {
60 fn new() -> Self {
61 Self { discriminator: 10 }
62 }
63}
64
65#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67pub struct AssignWithSeedInstructionArgs {
68 pub base_pubkey: Pubkey,
69 pub seed: String,
70 pub owner: Pubkey,
71}
72
73#[derive(Default)]
80pub struct AssignWithSeedBuilder {
81 account: Option<solana_program::pubkey::Pubkey>,
82 base: Option<solana_program::pubkey::Pubkey>,
83 base_pubkey: Option<Pubkey>,
84 seed: Option<String>,
85 owner: Option<Pubkey>,
86 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
87}
88
89impl AssignWithSeedBuilder {
90 pub fn new() -> Self {
91 Self::default()
92 }
93 #[inline(always)]
95 pub fn account(&mut self, account: solana_program::pubkey::Pubkey) -> &mut Self {
96 self.account = Some(account);
97 self
98 }
99 #[inline(always)]
101 pub fn base(&mut self, base: solana_program::pubkey::Pubkey) -> &mut Self {
102 self.base = Some(base);
103 self
104 }
105 #[inline(always)]
106 pub fn base_pubkey(&mut self, base_pubkey: Pubkey) -> &mut Self {
107 self.base_pubkey = Some(base_pubkey);
108 self
109 }
110 #[inline(always)]
111 pub fn seed(&mut self, seed: String) -> &mut Self {
112 self.seed = Some(seed);
113 self
114 }
115 #[inline(always)]
116 pub fn owner(&mut self, owner: Pubkey) -> &mut Self {
117 self.owner = Some(owner);
118 self
119 }
120 #[inline(always)]
122 pub fn add_remaining_account(
123 &mut self,
124 account: solana_program::instruction::AccountMeta,
125 ) -> &mut Self {
126 self.__remaining_accounts.push(account);
127 self
128 }
129 #[inline(always)]
131 pub fn add_remaining_accounts(
132 &mut self,
133 accounts: &[solana_program::instruction::AccountMeta],
134 ) -> &mut Self {
135 self.__remaining_accounts.extend_from_slice(accounts);
136 self
137 }
138 #[allow(clippy::clone_on_copy)]
139 pub fn instruction(&self) -> solana_program::instruction::Instruction {
140 let accounts = AssignWithSeed {
141 account: self.account.expect("account is not set"),
142 base: self.base.expect("base is not set"),
143 };
144 let args = AssignWithSeedInstructionArgs {
145 base_pubkey: self.base_pubkey.clone().expect("base_pubkey is not set"),
146 seed: self.seed.clone().expect("seed is not set"),
147 owner: self.owner.clone().expect("owner is not set"),
148 };
149
150 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
151 }
152}
153
154pub struct AssignWithSeedCpiAccounts<'a, 'b> {
156 pub account: &'b solana_program::account_info::AccountInfo<'a>,
158 pub base: &'b solana_program::account_info::AccountInfo<'a>,
160}
161
162pub struct AssignWithSeedCpi<'a, 'b> {
164 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
166 pub account: &'b solana_program::account_info::AccountInfo<'a>,
168 pub base: &'b solana_program::account_info::AccountInfo<'a>,
170 pub __args: AssignWithSeedInstructionArgs,
172}
173
174impl<'a, 'b> AssignWithSeedCpi<'a, 'b> {
175 pub fn new(
176 program: &'b solana_program::account_info::AccountInfo<'a>,
177 accounts: AssignWithSeedCpiAccounts<'a, 'b>,
178 args: AssignWithSeedInstructionArgs,
179 ) -> Self {
180 Self {
181 __program: program,
182 account: accounts.account,
183 base: accounts.base,
184 __args: args,
185 }
186 }
187 #[inline(always)]
188 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
189 self.invoke_signed_with_remaining_accounts(&[], &[])
190 }
191 #[inline(always)]
192 pub fn invoke_with_remaining_accounts(
193 &self,
194 remaining_accounts: &[(
195 &'b solana_program::account_info::AccountInfo<'a>,
196 bool,
197 bool,
198 )],
199 ) -> solana_program::entrypoint::ProgramResult {
200 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
201 }
202 #[inline(always)]
203 pub fn invoke_signed(
204 &self,
205 signers_seeds: &[&[&[u8]]],
206 ) -> solana_program::entrypoint::ProgramResult {
207 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
208 }
209 #[allow(clippy::clone_on_copy)]
210 #[allow(clippy::vec_init_then_push)]
211 pub fn invoke_signed_with_remaining_accounts(
212 &self,
213 signers_seeds: &[&[&[u8]]],
214 remaining_accounts: &[(
215 &'b solana_program::account_info::AccountInfo<'a>,
216 bool,
217 bool,
218 )],
219 ) -> solana_program::entrypoint::ProgramResult {
220 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
221 accounts.push(solana_program::instruction::AccountMeta::new(
222 *self.account.key,
223 false,
224 ));
225 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
226 *self.base.key,
227 true,
228 ));
229 remaining_accounts.iter().for_each(|remaining_account| {
230 accounts.push(solana_program::instruction::AccountMeta {
231 pubkey: *remaining_account.0.key,
232 is_signer: remaining_account.1,
233 is_writable: remaining_account.2,
234 })
235 });
236 let mut data = AssignWithSeedInstructionData::new().try_to_vec().unwrap();
237 let mut args = self.__args.try_to_vec().unwrap();
238 data.append(&mut args);
239
240 let instruction = solana_program::instruction::Instruction {
241 program_id: crate::SYSTEM_PROGRAM_ID,
242 accounts,
243 data,
244 };
245 let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
246 account_infos.push(self.__program.clone());
247 account_infos.push(self.account.clone());
248 account_infos.push(self.base.clone());
249 remaining_accounts
250 .iter()
251 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
252
253 if signers_seeds.is_empty() {
254 solana_program::program::invoke(&instruction, &account_infos)
255 } else {
256 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
257 }
258 }
259}
260
261pub struct AssignWithSeedCpiBuilder<'a, 'b> {
268 instruction: Box<AssignWithSeedCpiBuilderInstruction<'a, 'b>>,
269}
270
271impl<'a, 'b> AssignWithSeedCpiBuilder<'a, 'b> {
272 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
273 let instruction = Box::new(AssignWithSeedCpiBuilderInstruction {
274 __program: program,
275 account: None,
276 base: None,
277 base_pubkey: None,
278 seed: None,
279 owner: None,
280 __remaining_accounts: Vec::new(),
281 });
282 Self { instruction }
283 }
284 #[inline(always)]
286 pub fn account(
287 &mut self,
288 account: &'b solana_program::account_info::AccountInfo<'a>,
289 ) -> &mut Self {
290 self.instruction.account = Some(account);
291 self
292 }
293 #[inline(always)]
295 pub fn base(&mut self, base: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
296 self.instruction.base = Some(base);
297 self
298 }
299 #[inline(always)]
300 pub fn base_pubkey(&mut self, base_pubkey: Pubkey) -> &mut Self {
301 self.instruction.base_pubkey = Some(base_pubkey);
302 self
303 }
304 #[inline(always)]
305 pub fn seed(&mut self, seed: String) -> &mut Self {
306 self.instruction.seed = Some(seed);
307 self
308 }
309 #[inline(always)]
310 pub fn owner(&mut self, owner: Pubkey) -> &mut Self {
311 self.instruction.owner = Some(owner);
312 self
313 }
314 #[inline(always)]
316 pub fn add_remaining_account(
317 &mut self,
318 account: &'b solana_program::account_info::AccountInfo<'a>,
319 is_writable: bool,
320 is_signer: bool,
321 ) -> &mut Self {
322 self.instruction
323 .__remaining_accounts
324 .push((account, is_writable, is_signer));
325 self
326 }
327 #[inline(always)]
332 pub fn add_remaining_accounts(
333 &mut self,
334 accounts: &[(
335 &'b solana_program::account_info::AccountInfo<'a>,
336 bool,
337 bool,
338 )],
339 ) -> &mut Self {
340 self.instruction
341 .__remaining_accounts
342 .extend_from_slice(accounts);
343 self
344 }
345 #[inline(always)]
346 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
347 self.invoke_signed(&[])
348 }
349 #[allow(clippy::clone_on_copy)]
350 #[allow(clippy::vec_init_then_push)]
351 pub fn invoke_signed(
352 &self,
353 signers_seeds: &[&[&[u8]]],
354 ) -> solana_program::entrypoint::ProgramResult {
355 let args = AssignWithSeedInstructionArgs {
356 base_pubkey: self
357 .instruction
358 .base_pubkey
359 .clone()
360 .expect("base_pubkey is not set"),
361 seed: self.instruction.seed.clone().expect("seed is not set"),
362 owner: self.instruction.owner.clone().expect("owner is not set"),
363 };
364 let instruction = AssignWithSeedCpi {
365 __program: self.instruction.__program,
366
367 account: self.instruction.account.expect("account is not set"),
368
369 base: self.instruction.base.expect("base is not set"),
370 __args: args,
371 };
372 instruction.invoke_signed_with_remaining_accounts(
373 signers_seeds,
374 &self.instruction.__remaining_accounts,
375 )
376 }
377}
378
379struct AssignWithSeedCpiBuilderInstruction<'a, 'b> {
380 __program: &'b solana_program::account_info::AccountInfo<'a>,
381 account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
382 base: Option<&'b solana_program::account_info::AccountInfo<'a>>,
383 base_pubkey: Option<Pubkey>,
384 seed: Option<String>,
385 owner: Option<Pubkey>,
386 __remaining_accounts: Vec<(
388 &'b solana_program::account_info::AccountInfo<'a>,
389 bool,
390 bool,
391 )>,
392}