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