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};
/// Empty the available balance in a confidential token account.
/// A token account that is extended for confidential transfers can only be
/// closed if the pending and available balance ciphertexts are emptied.
/// The pending balance can be emptied
/// via the `ConfidentialTransferInstruction::ApplyPendingBalance`
/// instruction. Use the `ConfidentialTransferInstruction::EmptyAccount`
/// instruction to empty the available balance ciphertext.
/// Note that a newly configured account is always empty, so this
/// instruction is not required prior to account closing if no
/// instructions beyond
/// `ConfidentialTransferInstruction::ConfigureAccount` have affected the
/// token account.
/// In order for this instruction to be successfully processed, it must be
/// accompanied by the `VerifyZeroCiphertext` instruction of the
/// `zk_elgamal_proof` program in the same transaction or the address of a
/// context state account for the proof must be provided.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct EmptyConfidentialTransferAccount {
    /// Relative location of the `ProofInstruction::VerifyCloseAccount`
    /// instruction to the `EmptyAccount` instruction in the transaction. If
    /// the offset is `0`, then use a context state account for the proof.
    pub proof_instruction_offset: i8,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EmptyConfidentialTransferAccountInstructionAccounts {
    pub token: solana_pubkey::Pubkey,
    pub instructions_sysvar_or_context_state: solana_pubkey::Pubkey,
    pub record: Option<solana_pubkey::Pubkey>,
    pub authority: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl EmptyConfidentialTransferAccount {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 2 {
            return None;
        }
        let discriminator = data[0];
        if discriminator != 27 {
            return None;
        }
        let confidential_transfer_discriminator = data[1];
        if confidential_transfer_discriminator != 4 {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for EmptyConfidentialTransferAccount {
    type ArrangedAccounts = EmptyConfidentialTransferAccountInstructionAccounts;

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

        let token = next_account(&mut iter)?;
        let instructions_sysvar_or_context_state = next_account(&mut iter)?;
        let record = next_account(&mut iter);
        let authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(EmptyConfidentialTransferAccountInstructionAccounts {
            token,
            instructions_sysvar_or_context_state,
            record,
            authority,
            remaining: remaining.to_vec(),
        })
    }
}