carbon_srsly_decoder/accounts/
mod.rs1use crate::PROGRAM_ID;
3use crate::SrslyDecoder;
4
5pub mod contract_state;
6pub mod fleet;
7pub mod rental_state;
8pub mod thread;
9
10#[derive(Debug, Clone, PartialEq)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
13pub enum SrslyAccount {
14 ContractState(Box<contract_state::ContractState>),
15 Fleet(Box<fleet::Fleet>),
16 RentalState(Box<rental_state::RentalState>),
17 Thread(Box<thread::Thread>),
18}
19
20impl<'a> carbon_core::account::AccountDecoder<'a> for SrslyDecoder {
21 type AccountType = SrslyAccount;
22
23 fn decode_account(
24 &self,
25 account: &'a solana_account::Account,
26 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
27 if account.owner != PROGRAM_ID {
28 return None;
29 }
30
31 let data = account.data.as_slice();
32
33 {
34 if let Some(decoded) = contract_state::ContractState::decode(data) {
35 return Some(carbon_core::account::DecodedAccount {
36 lamports: account.lamports,
37 data: SrslyAccount::ContractState(Box::new(decoded)),
38 owner: account.owner,
39 executable: account.executable,
40 rent_epoch: account.rent_epoch,
41 });
42 }
43 }
44 {
45 if let Some(decoded) = fleet::Fleet::decode(data) {
46 return Some(carbon_core::account::DecodedAccount {
47 lamports: account.lamports,
48 data: SrslyAccount::Fleet(Box::new(decoded)),
49 owner: account.owner,
50 executable: account.executable,
51 rent_epoch: account.rent_epoch,
52 });
53 }
54 }
55 {
56 if let Some(decoded) = rental_state::RentalState::decode(data) {
57 return Some(carbon_core::account::DecodedAccount {
58 lamports: account.lamports,
59 data: SrslyAccount::RentalState(Box::new(decoded)),
60 owner: account.owner,
61 executable: account.executable,
62 rent_epoch: account.rent_epoch,
63 });
64 }
65 }
66 {
67 if let Some(decoded) = thread::Thread::decode(data) {
68 return Some(carbon_core::account::DecodedAccount {
69 lamports: account.lamports,
70 data: SrslyAccount::Thread(Box::new(decoded)),
71 owner: account.owner,
72 executable: account.executable,
73 rent_epoch: account.rent_epoch,
74 });
75 }
76 }
77
78 None
79 }
80}