carbon-mpl-core-decoder 1.0.0

MPL Core Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::UpdateCollectionPluginV1Args,
    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 UpdateCollectionPluginV1 {
    pub update_collection_plugin_v1_args: UpdateCollectionPluginV1Args,
}

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

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for UpdateCollectionPluginV1 {
    type ArrangedAccounts = UpdateCollectionPluginV1InstructionAccounts;

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

        let collection = next_account(&mut iter)?;
        let payer = next_account(&mut iter)?;
        let authority = next_account(&mut iter);
        let system_program = next_account(&mut iter)?;
        let log_wrapper = next_account(&mut iter);

        let remaining = iter.as_slice();

        Some(UpdateCollectionPluginV1InstructionAccounts {
            collection,
            payer,
            authority,
            system_program,
            log_wrapper,
            remaining: remaining.to_vec(),
        })
    }
}