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