carbon_points_decoder/accounts/
mod.rs1use crate::PROGRAM_ID;
3use crate::PointsDecoder;
4
5#[cfg(feature = "postgres")]
6pub mod postgres;
7
8#[cfg(feature = "graphql")]
9pub mod graphql;
10
11pub mod point_category;
12pub mod points_modifier;
13pub mod user_points_account;
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 PointsAccount {
19 PointCategory(Box<point_category::PointCategory>),
20 PointsModifier(Box<points_modifier::PointsModifier>),
21 UserPointsAccount(Box<user_points_account::UserPointsAccount>),
22}
23
24impl<'a> carbon_core::account::AccountDecoder<'a> for PointsDecoder {
25 type AccountType = PointsAccount;
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) = point_category::PointCategory::decode(data) {
39 return Some(carbon_core::account::DecodedAccount {
40 lamports: account.lamports,
41 data: PointsAccount::PointCategory(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) = points_modifier::PointsModifier::decode(data) {
50 return Some(carbon_core::account::DecodedAccount {
51 lamports: account.lamports,
52 data: PointsAccount::PointsModifier(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_points_account::UserPointsAccount::decode(data) {
61 return Some(carbon_core::account::DecodedAccount {
62 lamports: account.lamports,
63 data: PointsAccount::UserPointsAccount(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}