carbon-sharky-decoder 2.0.0

Sharky Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use crate::{SharkyDecoder, PROGRAM_ID};

#[cfg(feature = "postgres")]
pub mod postgres;

#[cfg(feature = "graphql")]
pub mod graphql;

pub mod escrow_p_d_a;
pub mod loan;
pub mod n_f_t_list;
pub mod order_book;
pub mod price_update_v2;
pub mod program_version;
pub mod token_lending_loan;
pub mod token_lending_order_book;
pub mod token_lending_pool;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum SharkyAccount {
    EscrowPDA(Box<escrow_p_d_a::EscrowPDA>),
    Loan(Box<loan::Loan>),
    NFTList(Box<n_f_t_list::NFTList>),
    OrderBook(Box<order_book::OrderBook>),
    PriceUpdateV2(Box<price_update_v2::PriceUpdateV2>),
    ProgramVersion(Box<program_version::ProgramVersion>),
    TokenLendingLoan(Box<token_lending_loan::TokenLendingLoan>),
    TokenLendingOrderBook(Box<token_lending_order_book::TokenLendingOrderBook>),
    TokenLendingPool(Box<token_lending_pool::TokenLendingPool>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for SharkyDecoder {
    type AccountType = SharkyAccount;

    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) = escrow_p_d_a::EscrowPDA::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::EscrowPDA(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = loan::Loan::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::Loan(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = n_f_t_list::NFTList::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::NFTList(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = order_book::OrderBook::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::OrderBook(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = price_update_v2::PriceUpdateV2::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::PriceUpdateV2(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = program_version::ProgramVersion::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::ProgramVersion(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = token_lending_loan::TokenLendingLoan::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::TokenLendingLoan(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = token_lending_order_book::TokenLendingOrderBook::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::TokenLendingOrderBook(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = token_lending_pool::TokenLendingPool::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: SharkyAccount::TokenLendingPool(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}