carbon-token-2022-decoder 1.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Emits the token-metadata as return data
/// The format of the data emitted follows exactly the `TokenMetadata`
/// struct, but it's possible that the account data is stored in another
/// format by the program.
/// With this instruction, a program that implements the token-metadata
/// interface can return `TokenMetadata` without adhering to the specific
/// byte layout of the `TokenMetadata` struct in any accounts.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct EmitTokenMetadata {
    /// Start of range of data to emit
    pub start: Option<u64>,
    /// End of range of data to emit
    pub end: Option<u64>,
}

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

impl EmitTokenMetadata {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [250, 166, 180, 250, 13, 12, 184, 70] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for EmitTokenMetadata {
    type ArrangedAccounts = EmitTokenMetadataInstructionAccounts;

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

        let metadata = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(EmitTokenMetadataInstructionAccounts {
            metadata,
            remaining: remaining.to_vec(),
        })
    }
}