carbon-bubblegum-decoder 2.0.0

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

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

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

pub mod tree_config;
pub mod voucher;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum BubblegumAccount {
    TreeConfig(Box<tree_config::TreeConfig>),
    Voucher(Box<voucher::Voucher>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for BubblegumDecoder {
    type AccountType = BubblegumAccount;

    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) = tree_config::TreeConfig::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: BubblegumAccount::TreeConfig(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = voucher::Voucher::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: BubblegumAccount::Voucher(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}