carbon_points_store_decoder/accounts/
mod.rs1use crate::PROGRAM_ID;
3use crate::PointsStoreDecoder;
4
5#[cfg(feature = "postgres")]
6pub mod postgres;
7
8#[cfg(feature = "graphql")]
9pub mod graphql;
10
11pub mod points_store;
12pub mod redemption_config;
13pub mod user_redemption;
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 PointsStoreAccount {
19 PointsStore(Box<points_store::PointsStore>),
20 RedemptionConfig(Box<redemption_config::RedemptionConfig>),
21 UserRedemption(Box<user_redemption::UserRedemption>),
22}
23
24impl<'a> carbon_core::account::AccountDecoder<'a> for PointsStoreDecoder {
25 type AccountType = PointsStoreAccount;
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) = points_store::PointsStore::decode(data) {
39 return Some(carbon_core::account::DecodedAccount {
40 lamports: account.lamports,
41 data: PointsStoreAccount::PointsStore(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) = redemption_config::RedemptionConfig::decode(data) {
50 return Some(carbon_core::account::DecodedAccount {
51 lamports: account.lamports,
52 data: PointsStoreAccount::RedemptionConfig(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) = user_redemption::UserRedemption::decode(data) {
61 return Some(carbon_core::account::DecodedAccount {
62 lamports: account.lamports,
63 data: PointsStoreAccount::UserRedemption(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}