carbon_system_program_decoder/accounts/
mod.rs

1use carbon_core::account::AccountDecoder;
2use carbon_core::deserialize::CarbonDeserialize;
3
4use super::SystemProgramDecoder;
5
6pub mod legacy;
7pub mod nonce;
8
9pub enum SystemAccount {
10    Nonce(nonce::Nonce),
11    Legacy(legacy::Legacy),
12}
13
14impl AccountDecoder<'_> for SystemProgramDecoder {
15    type AccountType = SystemAccount;
16    fn decode_account(
17        &self,
18        account: &solana_account::Account,
19    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
20        if !account.owner.eq(&solana_program::system_program::id()) {
21            return None;
22        }
23
24        if account.data.is_empty() {
25            return Some(carbon_core::account::DecodedAccount {
26                lamports: account.lamports,
27                data: SystemAccount::Legacy(legacy::Legacy),
28                owner: account.owner,
29                executable: account.executable,
30                rent_epoch: account.rent_epoch,
31            });
32        }
33
34        if let Some(decoded_account) = nonce::Nonce::deserialize(account.data.as_slice()) {
35            return Some(carbon_core::account::DecodedAccount {
36                lamports: account.lamports,
37                data: SystemAccount::Nonce(decoded_account),
38                owner: account.owner,
39                executable: account.executable,
40                rent_epoch: account.rent_epoch,
41            });
42        }
43
44        None
45    }
46}