carbon_crew_decoder/accounts/
mod.rs1use crate::CrewDecoder;
3use crate::PROGRAM_ID;
4
5#[cfg(feature = "postgres")]
6pub mod postgres;
7
8#[cfg(feature = "graphql")]
9pub mod graphql;
10
11pub mod crew_config;
12pub mod pack_tiers;
13pub mod pack_type;
14pub mod sft_redemption;
15pub mod user_redemption;
16
17#[derive(Debug, Clone, PartialEq)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
20pub enum CrewAccount {
21 CrewConfig(Box<crew_config::CrewConfig>),
22 PackTiers(Box<pack_tiers::PackTiers>),
23 PackType(Box<pack_type::PackType>),
24 SftRedemption(Box<sft_redemption::SftRedemption>),
25 UserRedemption(Box<user_redemption::UserRedemption>),
26}
27
28impl<'a> carbon_core::account::AccountDecoder<'a> for CrewDecoder {
29 type AccountType = CrewAccount;
30
31 fn decode_account(
32 &self,
33 account: &'a solana_account::Account,
34 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
35 if account.owner != PROGRAM_ID {
36 return None;
37 }
38
39 let data = account.data.as_slice();
40
41 {
42 if let Some(decoded) = crew_config::CrewConfig::decode(data) {
43 return Some(carbon_core::account::DecodedAccount {
44 lamports: account.lamports,
45 data: CrewAccount::CrewConfig(Box::new(decoded)),
46 owner: account.owner,
47 executable: account.executable,
48 rent_epoch: account.rent_epoch,
49 });
50 }
51 }
52 {
53 if let Some(decoded) = pack_tiers::PackTiers::decode(data) {
54 return Some(carbon_core::account::DecodedAccount {
55 lamports: account.lamports,
56 data: CrewAccount::PackTiers(Box::new(decoded)),
57 owner: account.owner,
58 executable: account.executable,
59 rent_epoch: account.rent_epoch,
60 });
61 }
62 }
63 {
64 if let Some(decoded) = pack_type::PackType::decode(data) {
65 return Some(carbon_core::account::DecodedAccount {
66 lamports: account.lamports,
67 data: CrewAccount::PackType(Box::new(decoded)),
68 owner: account.owner,
69 executable: account.executable,
70 rent_epoch: account.rent_epoch,
71 });
72 }
73 }
74 {
75 if let Some(decoded) = sft_redemption::SftRedemption::decode(data) {
76 return Some(carbon_core::account::DecodedAccount {
77 lamports: account.lamports,
78 data: CrewAccount::SftRedemption(Box::new(decoded)),
79 owner: account.owner,
80 executable: account.executable,
81 rent_epoch: account.rent_epoch,
82 });
83 }
84 }
85 {
86 if let Some(decoded) = user_redemption::UserRedemption::decode(data) {
87 return Some(carbon_core::account::DecodedAccount {
88 lamports: account.lamports,
89 data: CrewAccount::UserRedemption(Box::new(decoded)),
90 owner: account.owner,
91 executable: account.executable,
92 rent_epoch: account.rent_epoch,
93 });
94 }
95 }
96
97 None
98 }
99}