Skip to main content

carbon_token_program_decoder/instructions/
set_authority.rs

1//! This code was AUTOGENERATED using the Codama library.
2use {
3    crate::types::AuthorityType,
4    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
5    solana_pubkey::Pubkey,
6};
7/// Sets a new authority of a mint or account.
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
10pub struct SetAuthority {
11    /// The type of authority to update.
12    pub authority_type: AuthorityType,
13    /// The new authority
14    pub new_authority: Option<Pubkey>,
15}
16
17#[derive(Debug, Clone, PartialEq)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub struct SetAuthorityInstructionAccounts {
20    pub owned: solana_pubkey::Pubkey,
21    pub owner: solana_pubkey::Pubkey,
22    pub remaining: Vec<solana_instruction::AccountMeta>,
23}
24
25impl SetAuthority {
26    pub fn decode(data: &[u8]) -> Option<Self> {
27        if data.is_empty() {
28            return None;
29        }
30        let discriminator = &data[0..1];
31        if discriminator != [6] {
32            return None;
33        }
34
35        let mut data_slice = data;
36
37        data_slice = &data_slice[1..];
38
39        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
40    }
41}
42
43impl ArrangeAccounts for SetAuthority {
44    type ArrangedAccounts = SetAuthorityInstructionAccounts;
45
46    fn arrange_accounts(
47        accounts: &[solana_instruction::AccountMeta],
48    ) -> Option<Self::ArrangedAccounts> {
49        let mut iter = accounts.iter();
50
51        let owned = next_account(&mut iter)?;
52        let owner = next_account(&mut iter)?;
53
54        let remaining = iter.as_slice();
55
56        Some(SetAuthorityInstructionAccounts {
57            owned,
58            owner,
59            remaining: remaining.to_vec(),
60        })
61    }
62}