Skip to main content

carbon_bubblegum_decoder/accounts/
mod.rs

1//! This code was AUTOGENERATED using the Codama library.
2use crate::{BubblegumDecoder, PROGRAM_ID};
3
4#[cfg(feature = "postgres")]
5pub mod postgres;
6
7#[cfg(feature = "graphql")]
8pub mod graphql;
9
10pub mod tree_config;
11pub mod voucher;
12
13#[derive(Debug, Clone, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
16pub enum BubblegumAccount {
17    TreeConfig(Box<tree_config::TreeConfig>),
18    Voucher(Box<voucher::Voucher>),
19}
20
21impl<'a> carbon_core::account::AccountDecoder<'a> for BubblegumDecoder {
22    type AccountType = BubblegumAccount;
23
24    fn decode_account(
25        &self,
26        account: &'a solana_account::Account,
27    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
28        if account.owner != PROGRAM_ID {
29            return None;
30        }
31
32        let data = account.data.as_slice();
33
34        {
35            if let Some(decoded) = tree_config::TreeConfig::decode(data) {
36                return Some(carbon_core::account::DecodedAccount {
37                    lamports: account.lamports,
38                    data: BubblegumAccount::TreeConfig(Box::new(decoded)),
39                    owner: account.owner,
40                    executable: account.executable,
41                    rent_epoch: account.rent_epoch,
42                });
43            }
44        }
45        {
46            if let Some(decoded) = voucher::Voucher::decode(data) {
47                return Some(carbon_core::account::DecodedAccount {
48                    lamports: account.lamports,
49                    data: BubblegumAccount::Voucher(Box::new(decoded)),
50                    owner: account.owner,
51                    executable: account.executable,
52                    rent_epoch: account.rent_epoch,
53                });
54            }
55        }
56
57        None
58    }
59}