carbon_tcomp_decoder/accounts/
mod.rs1use crate::PROGRAM_ID;
3use crate::TcompDecoder;
4
5pub mod bid_state;
6pub mod list_state;
7
8#[derive(Debug, Clone, PartialEq)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
11pub enum TcompAccount {
12 BidState(Box<bid_state::BidState>),
13 ListState(Box<list_state::ListState>),
14}
15
16impl<'a> carbon_core::account::AccountDecoder<'a> for TcompDecoder {
17 type AccountType = TcompAccount;
18
19 fn decode_account(
20 &self,
21 account: &'a solana_account::Account,
22 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
23 if account.owner != PROGRAM_ID {
24 return None;
25 }
26
27 let data = account.data.as_slice();
28
29 {
30 if let Some(decoded) = list_state::ListState::decode(data) {
31 return Some(carbon_core::account::DecodedAccount {
32 lamports: account.lamports,
33 data: TcompAccount::ListState(Box::new(decoded)),
34 owner: account.owner,
35 executable: account.executable,
36 rent_epoch: account.rent_epoch,
37 });
38 }
39 }
40 {
41 if let Some(decoded) = bid_state::BidState::decode(data) {
42 return Some(carbon_core::account::DecodedAccount {
43 lamports: account.lamports,
44 data: TcompAccount::BidState(Box::new(decoded)),
45 owner: account.owner,
46 executable: account.executable,
47 rent_epoch: account.rent_epoch,
48 });
49 }
50 }
51
52 None
53 }
54}