carbon-mpl-token-metadata-decoder 1.0.0

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

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MintNewEditionFromMasterEditionViaTokenInstructionAccounts {
    pub new_metadata: solana_pubkey::Pubkey,
    pub new_edition: solana_pubkey::Pubkey,
    pub master_edition: solana_pubkey::Pubkey,
    pub new_mint: solana_pubkey::Pubkey,
    pub edition_mark_pda: solana_pubkey::Pubkey,
    pub new_mint_authority: solana_pubkey::Pubkey,
    pub payer: solana_pubkey::Pubkey,
    pub token_account_owner: solana_pubkey::Pubkey,
    pub token_account: solana_pubkey::Pubkey,
    pub new_metadata_update_authority: solana_pubkey::Pubkey,
    pub metadata: solana_pubkey::Pubkey,
    pub token_program: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub rent: Option<solana_pubkey::Pubkey>,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for MintNewEditionFromMasterEditionViaToken {
    type ArrangedAccounts = MintNewEditionFromMasterEditionViaTokenInstructionAccounts;

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

        let new_metadata = next_account(&mut iter)?;
        let new_edition = next_account(&mut iter)?;
        let master_edition = next_account(&mut iter)?;
        let new_mint = next_account(&mut iter)?;
        let edition_mark_pda = next_account(&mut iter)?;
        let new_mint_authority = next_account(&mut iter)?;
        let payer = next_account(&mut iter)?;
        let token_account_owner = next_account(&mut iter)?;
        let token_account = next_account(&mut iter)?;
        let new_metadata_update_authority = next_account(&mut iter)?;
        let metadata = next_account(&mut iter)?;
        let token_program = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let rent = next_account(&mut iter);

        let remaining = iter.as_slice();

        Some(MintNewEditionFromMasterEditionViaTokenInstructionAccounts {
            new_metadata,
            new_edition,
            master_edition,
            new_mint,
            edition_mark_pda,
            new_mint_authority,
            payer,
            token_account_owner,
            token_account,
            new_metadata_update_authority,
            metadata,
            token_program,
            system_program,
            rent,
            remaining: remaining.to_vec(),
        })
    }
}