carbon-token-2022-decoder 1.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::TokenMetadataField,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Updates a field in a token-metadata account.
/// The field can be one of the required fields (name, symbol, URI), or a
/// totally new field denoted by a "key" string.
/// By the end of the instruction, the metadata account must be properly
/// resized based on the new size of the TLV entry.
/// * If the new size is larger, the program must first reallocate to
///
/// avoid
/// overwriting other TLV entries.
/// * If the new size is smaller, the program must reallocate at the end
///
/// so that it's possible to iterate over TLV entries
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct UpdateTokenMetadataField {
    /// Field to update in the metadata.
    pub field: TokenMetadataField,
    /// Value to write for the field.
    pub value: String,
}

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

impl UpdateTokenMetadataField {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [221, 233, 49, 45, 181, 202, 220, 200] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for UpdateTokenMetadataField {
    type ArrangedAccounts = UpdateTokenMetadataFieldInstructionAccounts;

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