carbon-token-2022-decoder 2.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::DecryptableBalance,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Applies the pending balance to the available balance, based on the
/// history of `Deposit` and/or `Transfer` instructions.
/// After submitting `ApplyPendingBalance`, the client should compare
/// `ConfidentialTransferAccount::expected_pending_balance_credit_counter`
/// with
/// `ConfidentialTransferAccount::actual_applied_pending_balance_instructions`.
/// If they are equal then the
/// `ConfidentialTransferAccount::decryptable_available_balance` is
/// consistent with `ConfidentialTransferAccount::available_balance`. If
/// they differ then there is more pending balance to be applied.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct ApplyConfidentialPendingBalance {
    /// The expected number of pending balance credits since the last successful
    /// `ApplyPendingBalance` instruction
    pub expected_pending_balance_credit_counter: u64,
    /// The new decryptable balance if the pending balance is applied
    /// successfully
    pub new_decryptable_available_balance: DecryptableBalance,
}

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

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for ApplyConfidentialPendingBalance {
    type ArrangedAccounts = ApplyConfidentialPendingBalanceInstructionAccounts;

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

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

        let remaining = iter.as_slice();

        Some(ApplyConfidentialPendingBalanceInstructionAccounts {
            token,
            authority,
            remaining: remaining.to_vec(),
        })
    }
}