carbon_player_profile_decoder/accounts/
mod.rs1use crate::PROGRAM_ID;
3use crate::PlayerProfileDecoder;
4
5pub mod player_name;
6pub mod profile;
7pub mod profile_role_membership;
8pub mod role;
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 PlayerProfileAccount {
14 PlayerName(Box<player_name::PlayerName>),
15 Profile(Box<profile::Profile>),
16 ProfileRoleMembership(Box<profile_role_membership::ProfileRoleMembership>),
17 Role(Box<role::Role>),
18}
19
20impl<'a> carbon_core::account::AccountDecoder<'a> for PlayerProfileDecoder {
21 type AccountType = PlayerProfileAccount;
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) = player_name::PlayerName::decode(data) {
35 return Some(carbon_core::account::DecodedAccount {
36 lamports: account.lamports,
37 data: PlayerProfileAccount::PlayerName(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) = profile::Profile::decode(data) {
46 return Some(carbon_core::account::DecodedAccount {
47 lamports: account.lamports,
48 data: PlayerProfileAccount::Profile(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) = profile_role_membership::ProfileRoleMembership::decode(data) {
57 return Some(carbon_core::account::DecodedAccount {
58 lamports: account.lamports,
59 data: PlayerProfileAccount::ProfileRoleMembership(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) = role::Role::decode(data) {
68 return Some(carbon_core::account::DecodedAccount {
69 lamports: account.lamports,
70 data: PlayerProfileAccount::Role(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}