carbon-mpl-core-decoder 1.0.0

MPL Core Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use crate::{MplCoreDecoder, PROGRAM_ID};

#[cfg(feature = "postgres")]
pub mod postgres;

#[cfg(feature = "graphql")]
pub mod graphql;

pub mod asset_v1;
pub mod collection_v1;
pub mod group_v1;
pub mod hashed_asset_v1;
pub mod plugin_header_v1;
pub mod plugin_registry_v1;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum MplCoreAccount {
    AssetV1(Box<asset_v1::AssetV1>),
    CollectionV1(Box<collection_v1::CollectionV1>),
    GroupV1(Box<group_v1::GroupV1>),
    HashedAssetV1(Box<hashed_asset_v1::HashedAssetV1>),
    PluginHeaderV1(Box<plugin_header_v1::PluginHeaderV1>),
    PluginRegistryV1(Box<plugin_registry_v1::PluginRegistryV1>),
}

impl<'a> carbon_core::account::AccountDecoder<'a> for MplCoreDecoder {
    type AccountType = MplCoreAccount;

    fn decode_account(
        &self,
        account: &'a solana_account::Account,
    ) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
        if account.owner != PROGRAM_ID {
            return None;
        }

        let data = account.data.as_slice();

        {
            if let Some(decoded) = plugin_header_v1::PluginHeaderV1::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MplCoreAccount::PluginHeaderV1(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = plugin_registry_v1::PluginRegistryV1::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MplCoreAccount::PluginRegistryV1(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = asset_v1::AssetV1::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MplCoreAccount::AssetV1(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = collection_v1::CollectionV1::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MplCoreAccount::CollectionV1(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = group_v1::GroupV1::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MplCoreAccount::GroupV1(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }
        {
            if let Some(decoded) = hashed_asset_v1::HashedAssetV1::decode(data) {
                return Some(carbon_core::account::DecodedAccount {
                    lamports: account.lamports,
                    data: MplCoreAccount::HashedAssetV1(Box::new(decoded)),
                    owner: account.owner,
                    executable: account.executable,
                    rent_epoch: account.rent_epoch,
                });
            }
        }

        None
    }
}