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