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};
/// Removes a key-value pair in a token-metadata account.
/// This only applies to additional fields, and not the base name / symbol /
/// URI fields.
/// By the end of the instruction, the metadata account must be properly
/// resized at the end based on the new size of the TLV entry.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct RemoveTokenMetadataKey {
    /// If the idempotent flag is set to true, then the instruction will not
    /// error if the key does not exist
    pub idempotent: bool,
    /// Key to remove in the additional metadata portion.
    pub key: String,
}

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

impl RemoveTokenMetadataKey {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [234, 18, 32, 56, 89, 141, 37, 181] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for RemoveTokenMetadataKey {
    type ArrangedAccounts = RemoveTokenMetadataKeyInstructionAccounts;

    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(RemoveTokenMetadataKeyInstructionAccounts {
            metadata,
            update_authority,
            remaining: remaining.to_vec(),
        })
    }
}