carbon-mpl-core-decoder 1.0.0

MPL Core Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::CreateGroupV1Args,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CreateGroupV1 {
    pub create_group_v1_args: CreateGroupV1Args,
}

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

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for CreateGroupV1 {
    type ArrangedAccounts = CreateGroupV1InstructionAccounts;

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

        let group = next_account(&mut iter)?;
        let update_authority = next_account(&mut iter);
        let payer = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CreateGroupV1InstructionAccounts {
            group,
            update_authority,
            payer,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}