carbon_mpl_core_decoder/accounts/
mod.rs1use {
2 super::MplCoreProgramDecoder,
3 crate::PROGRAM_ID,
4 carbon_core::{account::AccountDecoder, deserialize::CarbonDeserialize},
5};
6pub mod asset_v1;
7pub mod collection_v1;
8pub mod hashed_asset_v1;
9pub mod plugin_header_v1;
10pub mod plugin_registry_v1;
11
12pub enum MplCoreProgramAccount {
13 PluginHeaderV1(plugin_header_v1::PluginHeaderV1),
14 PluginRegistryV1(plugin_registry_v1::PluginRegistryV1),
15 AssetV1(asset_v1::AssetV1),
16 CollectionV1(collection_v1::CollectionV1),
17 HashedAssetV1(hashed_asset_v1::HashedAssetV1),
18}
19
20impl AccountDecoder<'_> for MplCoreProgramDecoder {
21 type AccountType = MplCoreProgramAccount;
22 fn decode_account(
23 &self,
24 account: &solana_account::Account,
25 ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
26 if !account.owner.eq(&PROGRAM_ID) {
27 return None;
28 }
29
30 if let Some(decoded_account) =
31 plugin_header_v1::PluginHeaderV1::deserialize(account.data.as_slice())
32 {
33 return Some(carbon_core::account::DecodedAccount {
34 lamports: account.lamports,
35 data: MplCoreProgramAccount::PluginHeaderV1(decoded_account),
36 owner: account.owner,
37 executable: account.executable,
38 rent_epoch: account.rent_epoch,
39 });
40 }
41
42 if let Some(decoded_account) =
43 plugin_registry_v1::PluginRegistryV1::deserialize(account.data.as_slice())
44 {
45 return Some(carbon_core::account::DecodedAccount {
46 lamports: account.lamports,
47 data: MplCoreProgramAccount::PluginRegistryV1(decoded_account),
48 owner: account.owner,
49 executable: account.executable,
50 rent_epoch: account.rent_epoch,
51 });
52 }
53
54 if let Some(decoded_account) = asset_v1::AssetV1::deserialize(account.data.as_slice()) {
55 return Some(carbon_core::account::DecodedAccount {
56 lamports: account.lamports,
57 data: MplCoreProgramAccount::AssetV1(decoded_account),
58 owner: account.owner,
59 executable: account.executable,
60 rent_epoch: account.rent_epoch,
61 });
62 }
63
64 if let Some(decoded_account) =
65 collection_v1::CollectionV1::deserialize(account.data.as_slice())
66 {
67 return Some(carbon_core::account::DecodedAccount {
68 lamports: account.lamports,
69 data: MplCoreProgramAccount::CollectionV1(decoded_account),
70 owner: account.owner,
71 executable: account.executable,
72 rent_epoch: account.rent_epoch,
73 });
74 }
75
76 if let Some(decoded_account) =
77 hashed_asset_v1::HashedAssetV1::deserialize(account.data.as_slice())
78 {
79 return Some(carbon_core::account::DecodedAccount {
80 lamports: account.lamports,
81 data: MplCoreProgramAccount::HashedAssetV1(decoded_account),
82 owner: account.owner,
83 executable: account.executable,
84 rent_epoch: account.rent_epoch,
85 });
86 }
87
88 None
89 }
90}