carbon_moonshot_decoder/accounts/
mod.rs1use crate::{MoonshotDecoder, PROGRAM_ID};
3
4#[cfg(feature = "postgres")]
5pub mod postgres;
6
7#[cfg(feature = "graphql")]
8pub mod graphql;
9
10pub mod config_account;
11pub mod curve_account;
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 MoonshotAccount {
17 ConfigAccount(Box<config_account::ConfigAccount>),
18 CurveAccount(Box<curve_account::CurveAccount>),
19}
20
21impl<'a> carbon_core::account::AccountDecoder<'a> for MoonshotDecoder {
22 type AccountType = MoonshotAccount;
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) = config_account::ConfigAccount::decode(data) {
36 return Some(carbon_core::account::DecodedAccount {
37 lamports: account.lamports,
38 data: MoonshotAccount::ConfigAccount(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) = curve_account::CurveAccount::decode(data) {
47 return Some(carbon_core::account::DecodedAccount {
48 lamports: account.lamports,
49 data: MoonshotAccount::CurveAccount(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}