carbon-tcomp-decoder 0.12.1

Rust decoder for Tensor cNFT Compressed program on Solana
Documentation
//! This code was AUTOGENERATED using the Codama library.
use crate::PROGRAM_ID;
use crate::TcompDecoder;

pub mod bid_state;
pub mod list_state;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum TcompAccount {
    BidState(Box<bid_state::BidState>),
    ListState(Box<list_state::ListState>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for TcompDecoder {
    type AccountType = TcompAccount;

    fn decode_account(
        &self,
        account: &'a solana_account::Account,
    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
        if account.owner != PROGRAM_ID {
            return None;
        }

        let data = account.data.as_slice();

        {
            if let Some(decoded) = list_state::ListState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: TcompAccount::ListState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = bid_state::BidState::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: TcompAccount::BidState(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}