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