carbon-token-2022-decoder 2.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Initializes a TLV entry with the basic token-metadata fields.
/// Assumes that the provided mint is an SPL token mint, that the metadata
/// account is allocated and assigned to the program, and that the metadata
/// account has enough lamports to cover the rent-exempt reserve.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitializeTokenMetadata {
    /// Longer name of the token.
    pub name: String,
    /// Shortened symbol of the token.
    pub symbol: String,
    /// URI pointing to more metadata (image, video, etc.).
    pub uri: String,
}

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

impl InitializeTokenMetadata {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [210, 225, 30, 162, 88, 184, 77, 141] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for InitializeTokenMetadata {
    type ArrangedAccounts = InitializeTokenMetadataInstructionAccounts;

    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 mint = next_account(&mut iter)?;
        let mint_authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializeTokenMetadataInstructionAccounts {
            metadata,
            update_authority,
            mint,
            mint_authority,
            remaining: remaining.to_vec(),
        })
    }
}