carbon-token-program-decoder 1.0.0

Token Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::AuthorityType,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
    solana_pubkey::Pubkey,
};
/// Sets a new authority of a mint or account.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct SetAuthority {
    /// The type of authority to update.
    pub authority_type: AuthorityType,
    /// The new authority
    pub new_authority: Option<Pubkey>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SetAuthorityInstructionAccounts {
    pub owned: solana_pubkey::Pubkey,
    pub owner: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl SetAuthority {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.is_empty() {
            return None;
        }
        let discriminator = &data[0..1];
        if discriminator != [6] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}

impl ArrangeAccounts for SetAuthority {
    type ArrangedAccounts = SetAuthorityInstructionAccounts;

    fn arrange_accounts(
        accounts: &[solana_instruction::AccountMeta],
    ) -> Option<Self::ArrangedAccounts> {
        let mut iter = accounts.iter();

        let owned = next_account(&mut iter)?;
        let owner = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(SetAuthorityInstructionAccounts {
            owned,
            owner,
            remaining: remaining.to_vec(),
        })
    }
}