carbon-token-2022-decoder 1.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::ExtensionType,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Check to see if a token account is large enough for a list of
/// ExtensionTypes, and if not, use reallocation to increase the data
/// size.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Reallocate {
    /// New extension types to include in the reallocated account.
    pub new_extension_types: Vec<ExtensionType>,
}

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

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for Reallocate {
    type ArrangedAccounts = ReallocateInstructionAccounts;

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

        let token = next_account(&mut iter)?;
        let payer = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let owner = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(ReallocateInstructionAccounts {
            token,
            payer,
            system_program,
            owner,
            remaining: remaining.to_vec(),
        })
    }
}