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},
    solana_pubkey::Pubkey,
};
/// Initializes confidential transfers for a mint.
/// The `ConfidentialTransferInstruction::InitializeMint` instruction
/// requires no signers and MUST be included within the same Transaction
/// as `TokenInstruction::InitializeMint`. Otherwise another party can
/// initialize the configuration.
/// The instruction fails if the `TokenInstruction::InitializeMint`
/// instruction has already executed for the mint.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitializeConfidentialTransferMint {
    /// Authority to modify the `ConfidentialTransferMint` configuration and to
    /// approve new accounts.
    pub authority: Option<Pubkey>,
    /// Determines if newly configured accounts must be approved by the
    /// `authority` before they may be used by the user.
    pub auto_approve_new_accounts: bool,
    /// New authority to decode any transfer amount in a confidential transfer.
    pub auditor_elgamal_pubkey: Option<Pubkey>,
}

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

impl InitializeConfidentialTransferMint {
    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 != 0 {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for InitializeConfidentialTransferMint {
    type ArrangedAccounts = InitializeConfidentialTransferMintInstructionAccounts;

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

        let mint = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializeConfidentialTransferMintInstructionAccounts {
            mint,
            remaining: remaining.to_vec(),
        })
    }
}