carbon-mpl-token-metadata-decoder 2.0.0

MPL Token Metadata Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::UpdateMetadataAccountArgsV2,
    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 UpdateMetadataAccountV2 {
    pub update_metadata_account_args_v2: UpdateMetadataAccountArgsV2,
}

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

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for UpdateMetadataAccountV2 {
    type ArrangedAccounts = UpdateMetadataAccountV2InstructionAccounts;

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

        let metadata = next_account(&mut iter)?;
        let update_authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(UpdateMetadataAccountV2InstructionAccounts {
            metadata,
            update_authority,
            remaining: remaining.to_vec(),
        })
    }
}