carbon-moonshot-decoder 1.0.0

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

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

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

pub mod config_account;
pub mod curve_account;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum MoonshotAccount {
    ConfigAccount(Box<config_account::ConfigAccount>),
    CurveAccount(Box<curve_account::CurveAccount>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for MoonshotDecoder {
    type AccountType = MoonshotAccount;

    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) = config_account::ConfigAccount::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MoonshotAccount::ConfigAccount(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = curve_account::CurveAccount::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MoonshotAccount::CurveAccount(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}