Skip to main content

solana_system_client/generated/instructions/
assign.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! <https://github.com/kinobi-so/kinobi>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12/// Accounts.
13pub struct Assign {
14    pub account: solana_program::pubkey::Pubkey,
15}
16
17impl Assign {
18    pub fn instruction(
19        &self,
20        args: AssignInstructionArgs,
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: AssignInstructionArgs,
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 = AssignInstructionData::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_ID,
42            accounts,
43            data,
44        }
45    }
46}
47
48#[derive(BorshDeserialize, BorshSerialize)]
49pub struct AssignInstructionData {
50    discriminator: u32,
51}
52
53impl AssignInstructionData {
54    pub fn new() -> Self {
55        Self { discriminator: 1 }
56    }
57}
58
59impl Default for AssignInstructionData {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
66#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67pub struct AssignInstructionArgs {
68    pub program_address: Pubkey,
69}
70
71/// Instruction builder for `Assign`.
72///
73/// ### Accounts:
74///
75///   0. `[writable, signer]` account
76#[derive(Clone, Debug, Default)]
77pub struct AssignBuilder {
78    account: Option<solana_program::pubkey::Pubkey>,
79    program_address: Option<Pubkey>,
80    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
81}
82
83impl AssignBuilder {
84    pub fn new() -> Self {
85        Self::default()
86    }
87    #[inline(always)]
88    pub fn account(&mut self, account: solana_program::pubkey::Pubkey) -> &mut Self {
89        self.account = Some(account);
90        self
91    }
92    #[inline(always)]
93    pub fn program_address(&mut self, program_address: Pubkey) -> &mut Self {
94        self.program_address = Some(program_address);
95        self
96    }
97    /// Add an aditional account to the instruction.
98    #[inline(always)]
99    pub fn add_remaining_account(
100        &mut self,
101        account: solana_program::instruction::AccountMeta,
102    ) -> &mut Self {
103        self.__remaining_accounts.push(account);
104        self
105    }
106    /// Add additional accounts to the instruction.
107    #[inline(always)]
108    pub fn add_remaining_accounts(
109        &mut self,
110        accounts: &[solana_program::instruction::AccountMeta],
111    ) -> &mut Self {
112        self.__remaining_accounts.extend_from_slice(accounts);
113        self
114    }
115    #[allow(clippy::clone_on_copy)]
116    pub fn instruction(&self) -> solana_program::instruction::Instruction {
117        let accounts = Assign {
118            account: self.account.expect("account is not set"),
119        };
120        let args = AssignInstructionArgs {
121            program_address: self
122                .program_address
123                .clone()
124                .expect("program_address is not set"),
125        };
126
127        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
128    }
129}
130
131/// `assign` CPI accounts.
132pub struct AssignCpiAccounts<'a, 'b> {
133    pub account: &'b solana_program::account_info::AccountInfo<'a>,
134}
135
136/// `assign` CPI instruction.
137pub struct AssignCpi<'a, 'b> {
138    /// The program to invoke.
139    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
140
141    pub account: &'b solana_program::account_info::AccountInfo<'a>,
142    /// The arguments for the instruction.
143    pub __args: AssignInstructionArgs,
144}
145
146impl<'a, 'b> AssignCpi<'a, 'b> {
147    pub fn new(
148        program: &'b solana_program::account_info::AccountInfo<'a>,
149        accounts: AssignCpiAccounts<'a, 'b>,
150        args: AssignInstructionArgs,
151    ) -> Self {
152        Self {
153            __program: program,
154            account: accounts.account,
155            __args: args,
156        }
157    }
158    #[inline(always)]
159    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
160        self.invoke_signed_with_remaining_accounts(&[], &[])
161    }
162    #[inline(always)]
163    pub fn invoke_with_remaining_accounts(
164        &self,
165        remaining_accounts: &[(
166            &'b solana_program::account_info::AccountInfo<'a>,
167            bool,
168            bool,
169        )],
170    ) -> solana_program::entrypoint::ProgramResult {
171        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
172    }
173    #[inline(always)]
174    pub fn invoke_signed(
175        &self,
176        signers_seeds: &[&[&[u8]]],
177    ) -> solana_program::entrypoint::ProgramResult {
178        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
179    }
180    #[allow(clippy::clone_on_copy)]
181    #[allow(clippy::vec_init_then_push)]
182    pub fn invoke_signed_with_remaining_accounts(
183        &self,
184        signers_seeds: &[&[&[u8]]],
185        remaining_accounts: &[(
186            &'b solana_program::account_info::AccountInfo<'a>,
187            bool,
188            bool,
189        )],
190    ) -> solana_program::entrypoint::ProgramResult {
191        let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
192        accounts.push(solana_program::instruction::AccountMeta::new(
193            *self.account.key,
194            true,
195        ));
196        remaining_accounts.iter().for_each(|remaining_account| {
197            accounts.push(solana_program::instruction::AccountMeta {
198                pubkey: *remaining_account.0.key,
199                is_signer: remaining_account.1,
200                is_writable: remaining_account.2,
201            })
202        });
203        let mut data = AssignInstructionData::new().try_to_vec().unwrap();
204        let mut args = self.__args.try_to_vec().unwrap();
205        data.append(&mut args);
206
207        let instruction = solana_program::instruction::Instruction {
208            program_id: crate::SYSTEM_ID,
209            accounts,
210            data,
211        };
212        let mut account_infos = Vec::with_capacity(1 + 1 + remaining_accounts.len());
213        account_infos.push(self.__program.clone());
214        account_infos.push(self.account.clone());
215        remaining_accounts
216            .iter()
217            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
218
219        if signers_seeds.is_empty() {
220            solana_program::program::invoke(&instruction, &account_infos)
221        } else {
222            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
223        }
224    }
225}
226
227/// Instruction builder for `Assign` via CPI.
228///
229/// ### Accounts:
230///
231///   0. `[writable, signer]` account
232#[derive(Clone, Debug)]
233pub struct AssignCpiBuilder<'a, 'b> {
234    instruction: Box<AssignCpiBuilderInstruction<'a, 'b>>,
235}
236
237impl<'a, 'b> AssignCpiBuilder<'a, 'b> {
238    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
239        let instruction = Box::new(AssignCpiBuilderInstruction {
240            __program: program,
241            account: None,
242            program_address: None,
243            __remaining_accounts: Vec::new(),
244        });
245        Self { instruction }
246    }
247    #[inline(always)]
248    pub fn account(
249        &mut self,
250        account: &'b solana_program::account_info::AccountInfo<'a>,
251    ) -> &mut Self {
252        self.instruction.account = Some(account);
253        self
254    }
255    #[inline(always)]
256    pub fn program_address(&mut self, program_address: Pubkey) -> &mut Self {
257        self.instruction.program_address = Some(program_address);
258        self
259    }
260    /// Add an additional account to the instruction.
261    #[inline(always)]
262    pub fn add_remaining_account(
263        &mut self,
264        account: &'b solana_program::account_info::AccountInfo<'a>,
265        is_writable: bool,
266        is_signer: bool,
267    ) -> &mut Self {
268        self.instruction
269            .__remaining_accounts
270            .push((account, is_writable, is_signer));
271        self
272    }
273    /// Add additional accounts to the instruction.
274    ///
275    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
276    /// and a `bool` indicating whether the account is a signer or not.
277    #[inline(always)]
278    pub fn add_remaining_accounts(
279        &mut self,
280        accounts: &[(
281            &'b solana_program::account_info::AccountInfo<'a>,
282            bool,
283            bool,
284        )],
285    ) -> &mut Self {
286        self.instruction
287            .__remaining_accounts
288            .extend_from_slice(accounts);
289        self
290    }
291    #[inline(always)]
292    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
293        self.invoke_signed(&[])
294    }
295    #[allow(clippy::clone_on_copy)]
296    #[allow(clippy::vec_init_then_push)]
297    pub fn invoke_signed(
298        &self,
299        signers_seeds: &[&[&[u8]]],
300    ) -> solana_program::entrypoint::ProgramResult {
301        let args = AssignInstructionArgs {
302            program_address: self
303                .instruction
304                .program_address
305                .clone()
306                .expect("program_address is not set"),
307        };
308        let instruction = AssignCpi {
309            __program: self.instruction.__program,
310
311            account: self.instruction.account.expect("account is not set"),
312            __args: args,
313        };
314        instruction.invoke_signed_with_remaining_accounts(
315            signers_seeds,
316            &self.instruction.__remaining_accounts,
317        )
318    }
319}
320
321#[derive(Clone, Debug)]
322struct AssignCpiBuilderInstruction<'a, 'b> {
323    __program: &'b solana_program::account_info::AccountInfo<'a>,
324    account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
325    program_address: Option<Pubkey>,
326    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
327    __remaining_accounts: Vec<(
328        &'b solana_program::account_info::AccountInfo<'a>,
329        bool,
330        bool,
331    )>,
332}