carbon-token-program-decoder 1.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 Token {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() != 165 {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[0..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}