carbon-token-program-decoder 2.0.0

Token Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {crate::types::AccountState, solana_pubkey::Pubkey};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Token {
    /// The mint associated with this account.
    pub mint: Pubkey,
    /// The owner of this account.
    pub owner: Pubkey,
    /// The amount of tokens this account holds.
    pub amount: u64,
    /// If `delegate` is `Some` then `delegated_amount` represents
    /// the amount authorized by the delegate.
    pub delegate: Option<Pubkey>,
    /// The account's state.
    pub state: AccountState,
    /// If is_native.is_some, this is a native token, and the value logs the
    /// rent-exempt reserve. An Account is required to be rent-exempt, so
    /// the value is used by the Processor to ensure that wrapped SOL
    /// accounts do not drop below this threshold.
    pub is_native: Option<u64>,
    /// The amount delegated.
    pub delegated_amount: u64,
    /// Optional authority to close the account.
    pub close_authority: Option<Pubkey>,
}

impl From<spl_token_interface::state::Account> for Token {
    fn from(value: spl_token_interface::state::Account) -> Self {
        Token {
            mint: value.mint,
            owner: value.owner,
            amount: value.amount,
            delegate: value.delegate.into(),
            state: match value.state {
                spl_token_interface::state::AccountState::Uninitialized => {
                    crate::types::AccountState::Uninitialized
                }
                spl_token_interface::state::AccountState::Initialized => {
                    crate::types::AccountState::Initialized
                }
                spl_token_interface::state::AccountState::Frozen => {
                    crate::types::AccountState::Frozen
                }
            },
            is_native: value.is_native.into(),
            delegated_amount: value.delegated_amount,
            close_authority: value.close_authority.into(),
        }
    }
}