Skip to main content

carbon_token_program_decoder/accounts/
mod.rs

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