carbon_points_decoder/accounts/
mod.rs1use carbon_core::account::AccountDecoder;
2use carbon_core::deserialize::CarbonDeserialize;
3
4use super::PointsDecoder;
5pub mod point_category;
6pub mod points_modifier;
7pub mod user_points_account;
8
9#[derive(Debug, serde::Serialize)]
10pub enum PointsAccount {
11 PointCategory(point_category::PointCategory),
12 PointsModifier(points_modifier::PointsModifier),
13 UserPointsAccount(user_points_account::UserPointsAccount),
14}
15
16impl<'a> AccountDecoder<'a> for PointsDecoder {
17 type AccountType = PointsAccount;
18 fn decode_account(
19 &self,
20 account: &solana_account::Account,
21 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
22 if let Some(decoded_account) =
23 point_category::PointCategory::deserialize(account.data.as_slice())
24 {
25 return Some(carbon_core::account::DecodedAccount {
26 lamports: account.lamports,
27 data: PointsAccount::PointCategory(decoded_account),
28 owner: account.owner,
29 executable: account.executable,
30 rent_epoch: account.rent_epoch,
31 });
32 }
33
34 if let Some(decoded_account) =
35 points_modifier::PointsModifier::deserialize(account.data.as_slice())
36 {
37 return Some(carbon_core::account::DecodedAccount {
38 lamports: account.lamports,
39 data: PointsAccount::PointsModifier(decoded_account),
40 owner: account.owner,
41 executable: account.executable,
42 rent_epoch: account.rent_epoch,
43 });
44 }
45
46 if let Some(decoded_account) =
47 user_points_account::UserPointsAccount::deserialize(account.data.as_slice())
48 {
49 return Some(carbon_core::account::DecodedAccount {
50 lamports: account.lamports,
51 data: PointsAccount::UserPointsAccount(decoded_account),
52 owner: account.owner,
53 executable: account.executable,
54 rent_epoch: account.rent_epoch,
55 });
56 }
57
58 None
59 }
60}