carbon-token-2022-decoder 1.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::Extension, solana_pubkey::Pubkey,
    spl_token_2022::extension::BaseStateWithExtensions,
};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Mint {
    /// Optional authority used to mint new tokens. The mint authority may only
    /// be provided during mint creation. If no mint authority is present
    /// then the mint has a fixed supply and no further tokens may be minted.
    pub mint_authority: Option<Pubkey>,
    /// Total supply of tokens.
    pub supply: u64,
    /// Number of base 10 digits to the right of the decimal place.
    pub decimals: u8,
    /// Is `true` if this structure has been initialized.
    pub is_initialized: bool,
    /// Optional authority to freeze token accounts.
    pub freeze_authority: Option<Pubkey>,
    /// The extensions activated on the mint account.
    pub extensions: Option<Vec<Extension>>,
}

impl From<spl_token_2022::extension::StateWithExtensions<'_, spl_token_2022::state::Mint>>
    for Mint
{
    fn from(
        value: spl_token_2022::extension::StateWithExtensions<'_, spl_token_2022::state::Mint>,
    ) -> Self {
        let extensions = value.get_extension_types().ok().map(|extensions| {
            extensions
                .iter()
                .filter_map(|extension_type| {
                    crate::types::Extension::from_mint_and_type(&value, extension_type)
                })
                .collect::<Vec<_>>()
        });

        Mint {
            mint_authority: value.base.mint_authority.into(),
            supply: value.base.supply,
            decimals: value.base.decimals,
            is_initialized: value.base.is_initialized,
            freeze_authority: value.base.freeze_authority.into(),
            extensions,
        }
    }
}