yellowstone_shield_client/generated/instructions/
remove_identity.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub const REMOVE_IDENTITY_DISCRIMINATOR: u8 = 2;
12
13/// Accounts.
14#[derive(Debug)]
15pub struct RemoveIdentity {
16    /// The token extensions mint account linked to the policy
17    pub mint: solana_pubkey::Pubkey,
18    /// The authority over the policy based on token ownership of the mint
19    pub token_account: solana_pubkey::Pubkey,
20    /// The shield policy account
21    pub policy: solana_pubkey::Pubkey,
22    /// The owner of the token account
23    pub owner: solana_pubkey::Pubkey,
24}
25
26impl RemoveIdentity {
27    pub fn instruction(
28        &self,
29        args: RemoveIdentityInstructionArgs,
30    ) -> solana_instruction::Instruction {
31        self.instruction_with_remaining_accounts(args, &[])
32    }
33    #[allow(clippy::arithmetic_side_effects)]
34    #[allow(clippy::vec_init_then_push)]
35    pub fn instruction_with_remaining_accounts(
36        &self,
37        args: RemoveIdentityInstructionArgs,
38        remaining_accounts: &[solana_instruction::AccountMeta],
39    ) -> solana_instruction::Instruction {
40        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
41        accounts.push(solana_instruction::AccountMeta::new_readonly(
42            self.mint, false,
43        ));
44        accounts.push(solana_instruction::AccountMeta::new_readonly(
45            self.token_account,
46            false,
47        ));
48        accounts.push(solana_instruction::AccountMeta::new(self.policy, false));
49        accounts.push(solana_instruction::AccountMeta::new(self.owner, true));
50        accounts.extend_from_slice(remaining_accounts);
51        let mut data = RemoveIdentityInstructionData::new().try_to_vec().unwrap();
52        let mut args = args.try_to_vec().unwrap();
53        data.append(&mut args);
54
55        solana_instruction::Instruction {
56            program_id: crate::SHIELD_ID,
57            accounts,
58            data,
59        }
60    }
61}
62
63#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
64#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
65pub struct RemoveIdentityInstructionData {
66    discriminator: u8,
67}
68
69impl RemoveIdentityInstructionData {
70    pub fn new() -> Self {
71        Self { discriminator: 2 }
72    }
73
74    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
75        borsh::to_vec(self)
76    }
77}
78
79impl Default for RemoveIdentityInstructionData {
80    fn default() -> Self {
81        Self::new()
82    }
83}
84
85#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
86#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
87pub struct RemoveIdentityInstructionArgs {
88    pub index: u64,
89}
90
91impl RemoveIdentityInstructionArgs {
92    pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
93        borsh::to_vec(self)
94    }
95}
96
97/// Instruction builder for `RemoveIdentity`.
98///
99/// ### Accounts:
100///
101///   0. `[]` mint
102///   1. `[]` token_account
103///   2. `[writable]` policy
104///   3. `[writable, signer]` owner
105#[derive(Clone, Debug, Default)]
106pub struct RemoveIdentityBuilder {
107    mint: Option<solana_pubkey::Pubkey>,
108    token_account: Option<solana_pubkey::Pubkey>,
109    policy: Option<solana_pubkey::Pubkey>,
110    owner: Option<solana_pubkey::Pubkey>,
111    index: Option<u64>,
112    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
113}
114
115impl RemoveIdentityBuilder {
116    pub fn new() -> Self {
117        Self::default()
118    }
119    /// The token extensions mint account linked to the policy
120    #[inline(always)]
121    pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self {
122        self.mint = Some(mint);
123        self
124    }
125    /// The authority over the policy based on token ownership of the mint
126    #[inline(always)]
127    pub fn token_account(&mut self, token_account: solana_pubkey::Pubkey) -> &mut Self {
128        self.token_account = Some(token_account);
129        self
130    }
131    /// The shield policy account
132    #[inline(always)]
133    pub fn policy(&mut self, policy: solana_pubkey::Pubkey) -> &mut Self {
134        self.policy = Some(policy);
135        self
136    }
137    /// The owner of the token account
138    #[inline(always)]
139    pub fn owner(&mut self, owner: solana_pubkey::Pubkey) -> &mut Self {
140        self.owner = Some(owner);
141        self
142    }
143    #[inline(always)]
144    pub fn index(&mut self, index: u64) -> &mut Self {
145        self.index = Some(index);
146        self
147    }
148    /// Add an additional account to the instruction.
149    #[inline(always)]
150    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
151        self.__remaining_accounts.push(account);
152        self
153    }
154    /// Add additional accounts to the instruction.
155    #[inline(always)]
156    pub fn add_remaining_accounts(
157        &mut self,
158        accounts: &[solana_instruction::AccountMeta],
159    ) -> &mut Self {
160        self.__remaining_accounts.extend_from_slice(accounts);
161        self
162    }
163    #[allow(clippy::clone_on_copy)]
164    pub fn instruction(&self) -> solana_instruction::Instruction {
165        let accounts = RemoveIdentity {
166            mint: self.mint.expect("mint is not set"),
167            token_account: self.token_account.expect("token_account is not set"),
168            policy: self.policy.expect("policy is not set"),
169            owner: self.owner.expect("owner is not set"),
170        };
171        let args = RemoveIdentityInstructionArgs {
172            index: self.index.clone().expect("index is not set"),
173        };
174
175        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
176    }
177}
178
179/// `remove_identity` CPI accounts.
180pub struct RemoveIdentityCpiAccounts<'a, 'b> {
181    /// The token extensions mint account linked to the policy
182    pub mint: &'b solana_account_info::AccountInfo<'a>,
183    /// The authority over the policy based on token ownership of the mint
184    pub token_account: &'b solana_account_info::AccountInfo<'a>,
185    /// The shield policy account
186    pub policy: &'b solana_account_info::AccountInfo<'a>,
187    /// The owner of the token account
188    pub owner: &'b solana_account_info::AccountInfo<'a>,
189}
190
191/// `remove_identity` CPI instruction.
192pub struct RemoveIdentityCpi<'a, 'b> {
193    /// The program to invoke.
194    pub __program: &'b solana_account_info::AccountInfo<'a>,
195    /// The token extensions mint account linked to the policy
196    pub mint: &'b solana_account_info::AccountInfo<'a>,
197    /// The authority over the policy based on token ownership of the mint
198    pub token_account: &'b solana_account_info::AccountInfo<'a>,
199    /// The shield policy account
200    pub policy: &'b solana_account_info::AccountInfo<'a>,
201    /// The owner of the token account
202    pub owner: &'b solana_account_info::AccountInfo<'a>,
203    /// The arguments for the instruction.
204    pub __args: RemoveIdentityInstructionArgs,
205}
206
207impl<'a, 'b> RemoveIdentityCpi<'a, 'b> {
208    pub fn new(
209        program: &'b solana_account_info::AccountInfo<'a>,
210        accounts: RemoveIdentityCpiAccounts<'a, 'b>,
211        args: RemoveIdentityInstructionArgs,
212    ) -> Self {
213        Self {
214            __program: program,
215            mint: accounts.mint,
216            token_account: accounts.token_account,
217            policy: accounts.policy,
218            owner: accounts.owner,
219            __args: args,
220        }
221    }
222    #[inline(always)]
223    pub fn invoke(&self) -> solana_program_error::ProgramResult {
224        self.invoke_signed_with_remaining_accounts(&[], &[])
225    }
226    #[inline(always)]
227    pub fn invoke_with_remaining_accounts(
228        &self,
229        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
230    ) -> solana_program_error::ProgramResult {
231        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
232    }
233    #[inline(always)]
234    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
235        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
236    }
237    #[allow(clippy::arithmetic_side_effects)]
238    #[allow(clippy::clone_on_copy)]
239    #[allow(clippy::vec_init_then_push)]
240    pub fn invoke_signed_with_remaining_accounts(
241        &self,
242        signers_seeds: &[&[&[u8]]],
243        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
244    ) -> solana_program_error::ProgramResult {
245        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
246        accounts.push(solana_instruction::AccountMeta::new_readonly(
247            *self.mint.key,
248            false,
249        ));
250        accounts.push(solana_instruction::AccountMeta::new_readonly(
251            *self.token_account.key,
252            false,
253        ));
254        accounts.push(solana_instruction::AccountMeta::new(
255            *self.policy.key,
256            false,
257        ));
258        accounts.push(solana_instruction::AccountMeta::new(*self.owner.key, true));
259        remaining_accounts.iter().for_each(|remaining_account| {
260            accounts.push(solana_instruction::AccountMeta {
261                pubkey: *remaining_account.0.key,
262                is_signer: remaining_account.1,
263                is_writable: remaining_account.2,
264            })
265        });
266        let mut data = RemoveIdentityInstructionData::new().try_to_vec().unwrap();
267        let mut args = self.__args.try_to_vec().unwrap();
268        data.append(&mut args);
269
270        let instruction = solana_instruction::Instruction {
271            program_id: crate::SHIELD_ID,
272            accounts,
273            data,
274        };
275        let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
276        account_infos.push(self.__program.clone());
277        account_infos.push(self.mint.clone());
278        account_infos.push(self.token_account.clone());
279        account_infos.push(self.policy.clone());
280        account_infos.push(self.owner.clone());
281        remaining_accounts
282            .iter()
283            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
284
285        if signers_seeds.is_empty() {
286            solana_cpi::invoke(&instruction, &account_infos)
287        } else {
288            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
289        }
290    }
291}
292
293/// Instruction builder for `RemoveIdentity` via CPI.
294///
295/// ### Accounts:
296///
297///   0. `[]` mint
298///   1. `[]` token_account
299///   2. `[writable]` policy
300///   3. `[writable, signer]` owner
301#[derive(Clone, Debug)]
302pub struct RemoveIdentityCpiBuilder<'a, 'b> {
303    instruction: Box<RemoveIdentityCpiBuilderInstruction<'a, 'b>>,
304}
305
306impl<'a, 'b> RemoveIdentityCpiBuilder<'a, 'b> {
307    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
308        let instruction = Box::new(RemoveIdentityCpiBuilderInstruction {
309            __program: program,
310            mint: None,
311            token_account: None,
312            policy: None,
313            owner: None,
314            index: None,
315            __remaining_accounts: Vec::new(),
316        });
317        Self { instruction }
318    }
319    /// The token extensions mint account linked to the policy
320    #[inline(always)]
321    pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
322        self.instruction.mint = Some(mint);
323        self
324    }
325    /// The authority over the policy based on token ownership of the mint
326    #[inline(always)]
327    pub fn token_account(
328        &mut self,
329        token_account: &'b solana_account_info::AccountInfo<'a>,
330    ) -> &mut Self {
331        self.instruction.token_account = Some(token_account);
332        self
333    }
334    /// The shield policy account
335    #[inline(always)]
336    pub fn policy(&mut self, policy: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
337        self.instruction.policy = Some(policy);
338        self
339    }
340    /// The owner of the token account
341    #[inline(always)]
342    pub fn owner(&mut self, owner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
343        self.instruction.owner = Some(owner);
344        self
345    }
346    #[inline(always)]
347    pub fn index(&mut self, index: u64) -> &mut Self {
348        self.instruction.index = Some(index);
349        self
350    }
351    /// Add an additional account to the instruction.
352    #[inline(always)]
353    pub fn add_remaining_account(
354        &mut self,
355        account: &'b solana_account_info::AccountInfo<'a>,
356        is_writable: bool,
357        is_signer: bool,
358    ) -> &mut Self {
359        self.instruction
360            .__remaining_accounts
361            .push((account, is_writable, is_signer));
362        self
363    }
364    /// Add additional accounts to the instruction.
365    ///
366    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
367    /// and a `bool` indicating whether the account is a signer or not.
368    #[inline(always)]
369    pub fn add_remaining_accounts(
370        &mut self,
371        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
372    ) -> &mut Self {
373        self.instruction
374            .__remaining_accounts
375            .extend_from_slice(accounts);
376        self
377    }
378    #[inline(always)]
379    pub fn invoke(&self) -> solana_program_error::ProgramResult {
380        self.invoke_signed(&[])
381    }
382    #[allow(clippy::clone_on_copy)]
383    #[allow(clippy::vec_init_then_push)]
384    pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
385        let args = RemoveIdentityInstructionArgs {
386            index: self.instruction.index.clone().expect("index is not set"),
387        };
388        let instruction = RemoveIdentityCpi {
389            __program: self.instruction.__program,
390
391            mint: self.instruction.mint.expect("mint is not set"),
392
393            token_account: self
394                .instruction
395                .token_account
396                .expect("token_account is not set"),
397
398            policy: self.instruction.policy.expect("policy is not set"),
399
400            owner: self.instruction.owner.expect("owner is not set"),
401            __args: args,
402        };
403        instruction.invoke_signed_with_remaining_accounts(
404            signers_seeds,
405            &self.instruction.__remaining_accounts,
406        )
407    }
408}
409
410#[derive(Clone, Debug)]
411struct RemoveIdentityCpiBuilderInstruction<'a, 'b> {
412    __program: &'b solana_account_info::AccountInfo<'a>,
413    mint: Option<&'b solana_account_info::AccountInfo<'a>>,
414    token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
415    policy: Option<&'b solana_account_info::AccountInfo<'a>>,
416    owner: Option<&'b solana_account_info::AccountInfo<'a>>,
417    index: Option<u64>,
418    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
419    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
420}