use crate::{TokenProgramDecoder, PROGRAM_ID};
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "graphql")]
pub mod graphql;
pub mod mint;
pub mod multisig;
pub mod token;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum TokenProgramAccount {
Mint(Box<mint::Mint>),
Multisig(Box<multisig::Multisig>),
Token(Box<token::Token>),
}
impl<'a> carbon_core::account::AccountDecoder<'a> for TokenProgramDecoder {
type AccountType = TokenProgramAccount;
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) = mint::Mint::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: TokenProgramAccount::Mint(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
{
if let Some(decoded) = token::Token::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: TokenProgramAccount::Token(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
{
if let Some(decoded) = multisig::Multisig::decode(data) {
return Some(carbon_core::account::DecodedAccount {
lamports: account.lamports,
data: TokenProgramAccount::Multisig(Box::new(decoded)),
owner: account.owner,
executable: account.executable,
rent_epoch: account.rent_epoch,
});
}
}
None
}
}