token_acl_client/generated/instructions/
set_authority.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_pubkey::Pubkey;
11
12pub const SET_AUTHORITY_DISCRIMINATOR: u8 = 1;
13
14#[derive(Debug)]
16pub struct SetAuthority {
17 pub authority: solana_pubkey::Pubkey,
18
19 pub mint_config: solana_pubkey::Pubkey,
20}
21
22impl SetAuthority {
23 pub fn instruction(
24 &self,
25 args: SetAuthorityInstructionArgs,
26 ) -> solana_instruction::Instruction {
27 self.instruction_with_remaining_accounts(args, &[])
28 }
29 #[allow(clippy::arithmetic_side_effects)]
30 #[allow(clippy::vec_init_then_push)]
31 pub fn instruction_with_remaining_accounts(
32 &self,
33 args: SetAuthorityInstructionArgs,
34 remaining_accounts: &[solana_instruction::AccountMeta],
35 ) -> solana_instruction::Instruction {
36 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
37 accounts.push(solana_instruction::AccountMeta::new_readonly(
38 self.authority,
39 true,
40 ));
41 accounts.push(solana_instruction::AccountMeta::new(
42 self.mint_config,
43 false,
44 ));
45 accounts.extend_from_slice(remaining_accounts);
46 let mut data = SetAuthorityInstructionData::new().try_to_vec().unwrap();
47 let mut args = args.try_to_vec().unwrap();
48 data.append(&mut args);
49
50 solana_instruction::Instruction {
51 program_id: crate::TOKEN_ACL_ID,
52 accounts,
53 data,
54 }
55 }
56}
57
58#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
59#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
60pub struct SetAuthorityInstructionData {
61 discriminator: u8,
62}
63
64impl SetAuthorityInstructionData {
65 pub fn new() -> Self {
66 Self { discriminator: 1 }
67 }
68
69 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
70 borsh::to_vec(self)
71 }
72}
73
74impl Default for SetAuthorityInstructionData {
75 fn default() -> Self {
76 Self::new()
77 }
78}
79
80#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
81#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
82pub struct SetAuthorityInstructionArgs {
83 pub new_authority: Pubkey,
84}
85
86impl SetAuthorityInstructionArgs {
87 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
88 borsh::to_vec(self)
89 }
90}
91
92#[derive(Clone, Debug, Default)]
99pub struct SetAuthorityBuilder {
100 authority: Option<solana_pubkey::Pubkey>,
101 mint_config: Option<solana_pubkey::Pubkey>,
102 new_authority: Option<Pubkey>,
103 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
104}
105
106impl SetAuthorityBuilder {
107 pub fn new() -> Self {
108 Self::default()
109 }
110 #[inline(always)]
111 pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
112 self.authority = Some(authority);
113 self
114 }
115 #[inline(always)]
116 pub fn mint_config(&mut self, mint_config: solana_pubkey::Pubkey) -> &mut Self {
117 self.mint_config = Some(mint_config);
118 self
119 }
120 #[inline(always)]
121 pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
122 self.new_authority = Some(new_authority);
123 self
124 }
125 #[inline(always)]
127 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
128 self.__remaining_accounts.push(account);
129 self
130 }
131 #[inline(always)]
133 pub fn add_remaining_accounts(
134 &mut self,
135 accounts: &[solana_instruction::AccountMeta],
136 ) -> &mut Self {
137 self.__remaining_accounts.extend_from_slice(accounts);
138 self
139 }
140 #[allow(clippy::clone_on_copy)]
141 pub fn instruction(&self) -> solana_instruction::Instruction {
142 let accounts = SetAuthority {
143 authority: self.authority.expect("authority is not set"),
144 mint_config: self.mint_config.expect("mint_config is not set"),
145 };
146 let args = SetAuthorityInstructionArgs {
147 new_authority: self
148 .new_authority
149 .clone()
150 .expect("new_authority is not set"),
151 };
152
153 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
154 }
155}
156
157pub struct SetAuthorityCpiAccounts<'a, 'b> {
159 pub authority: &'b solana_account_info::AccountInfo<'a>,
160
161 pub mint_config: &'b solana_account_info::AccountInfo<'a>,
162}
163
164pub struct SetAuthorityCpi<'a, 'b> {
166 pub __program: &'b solana_account_info::AccountInfo<'a>,
168
169 pub authority: &'b solana_account_info::AccountInfo<'a>,
170
171 pub mint_config: &'b solana_account_info::AccountInfo<'a>,
172 pub __args: SetAuthorityInstructionArgs,
174}
175
176impl<'a, 'b> SetAuthorityCpi<'a, 'b> {
177 pub fn new(
178 program: &'b solana_account_info::AccountInfo<'a>,
179 accounts: SetAuthorityCpiAccounts<'a, 'b>,
180 args: SetAuthorityInstructionArgs,
181 ) -> Self {
182 Self {
183 __program: program,
184 authority: accounts.authority,
185 mint_config: accounts.mint_config,
186 __args: args,
187 }
188 }
189 #[inline(always)]
190 pub fn invoke(&self) -> solana_program_error::ProgramResult {
191 self.invoke_signed_with_remaining_accounts(&[], &[])
192 }
193 #[inline(always)]
194 pub fn invoke_with_remaining_accounts(
195 &self,
196 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
197 ) -> solana_program_error::ProgramResult {
198 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
199 }
200 #[inline(always)]
201 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
202 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
203 }
204 #[allow(clippy::arithmetic_side_effects)]
205 #[allow(clippy::clone_on_copy)]
206 #[allow(clippy::vec_init_then_push)]
207 pub fn invoke_signed_with_remaining_accounts(
208 &self,
209 signers_seeds: &[&[&[u8]]],
210 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
211 ) -> solana_program_error::ProgramResult {
212 let mut accounts = Vec::with_capacity(2 + remaining_accounts.len());
213 accounts.push(solana_instruction::AccountMeta::new_readonly(
214 *self.authority.key,
215 true,
216 ));
217 accounts.push(solana_instruction::AccountMeta::new(
218 *self.mint_config.key,
219 false,
220 ));
221 remaining_accounts.iter().for_each(|remaining_account| {
222 accounts.push(solana_instruction::AccountMeta {
223 pubkey: *remaining_account.0.key,
224 is_signer: remaining_account.1,
225 is_writable: remaining_account.2,
226 })
227 });
228 let mut data = SetAuthorityInstructionData::new().try_to_vec().unwrap();
229 let mut args = self.__args.try_to_vec().unwrap();
230 data.append(&mut args);
231
232 let instruction = solana_instruction::Instruction {
233 program_id: crate::TOKEN_ACL_ID,
234 accounts,
235 data,
236 };
237 let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
238 account_infos.push(self.__program.clone());
239 account_infos.push(self.authority.clone());
240 account_infos.push(self.mint_config.clone());
241 remaining_accounts
242 .iter()
243 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
244
245 if signers_seeds.is_empty() {
246 solana_cpi::invoke(&instruction, &account_infos)
247 } else {
248 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
249 }
250 }
251}
252
253#[derive(Clone, Debug)]
260pub struct SetAuthorityCpiBuilder<'a, 'b> {
261 instruction: Box<SetAuthorityCpiBuilderInstruction<'a, 'b>>,
262}
263
264impl<'a, 'b> SetAuthorityCpiBuilder<'a, 'b> {
265 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
266 let instruction = Box::new(SetAuthorityCpiBuilderInstruction {
267 __program: program,
268 authority: None,
269 mint_config: None,
270 new_authority: None,
271 __remaining_accounts: Vec::new(),
272 });
273 Self { instruction }
274 }
275 #[inline(always)]
276 pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
277 self.instruction.authority = Some(authority);
278 self
279 }
280 #[inline(always)]
281 pub fn mint_config(
282 &mut self,
283 mint_config: &'b solana_account_info::AccountInfo<'a>,
284 ) -> &mut Self {
285 self.instruction.mint_config = Some(mint_config);
286 self
287 }
288 #[inline(always)]
289 pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
290 self.instruction.new_authority = Some(new_authority);
291 self
292 }
293 #[inline(always)]
295 pub fn add_remaining_account(
296 &mut self,
297 account: &'b solana_account_info::AccountInfo<'a>,
298 is_writable: bool,
299 is_signer: bool,
300 ) -> &mut Self {
301 self.instruction
302 .__remaining_accounts
303 .push((account, is_writable, is_signer));
304 self
305 }
306 #[inline(always)]
311 pub fn add_remaining_accounts(
312 &mut self,
313 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
314 ) -> &mut Self {
315 self.instruction
316 .__remaining_accounts
317 .extend_from_slice(accounts);
318 self
319 }
320 #[inline(always)]
321 pub fn invoke(&self) -> solana_program_error::ProgramResult {
322 self.invoke_signed(&[])
323 }
324 #[allow(clippy::clone_on_copy)]
325 #[allow(clippy::vec_init_then_push)]
326 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
327 let args = SetAuthorityInstructionArgs {
328 new_authority: self
329 .instruction
330 .new_authority
331 .clone()
332 .expect("new_authority is not set"),
333 };
334 let instruction = SetAuthorityCpi {
335 __program: self.instruction.__program,
336
337 authority: self.instruction.authority.expect("authority is not set"),
338
339 mint_config: self
340 .instruction
341 .mint_config
342 .expect("mint_config is not set"),
343 __args: args,
344 };
345 instruction.invoke_signed_with_remaining_accounts(
346 signers_seeds,
347 &self.instruction.__remaining_accounts,
348 )
349 }
350}
351
352#[derive(Clone, Debug)]
353struct SetAuthorityCpiBuilderInstruction<'a, 'b> {
354 __program: &'b solana_account_info::AccountInfo<'a>,
355 authority: Option<&'b solana_account_info::AccountInfo<'a>>,
356 mint_config: Option<&'b solana_account_info::AccountInfo<'a>>,
357 new_authority: Option<Pubkey>,
358 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
360}