carbon-token-program-decoder 1.0.0

Token Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::AccountStateGraphQL,
    carbon_core::graphql::primitives::{Pubkey, U64},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Token")]
pub struct TokenGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub mint: Pubkey,
    pub owner: Pubkey,
    pub amount: U64,
    pub delegate: Option<Pubkey>,
    pub state: AccountStateGraphQL,
    pub is_native: Option<U64>,
    pub delegated_amount: U64,
    pub close_authority: Option<Pubkey>,
}

impl TryFrom<crate::accounts::postgres::TokenRow> for TokenGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::TokenRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            mint: carbon_core::graphql::primitives::Pubkey(row.mint.0),
            owner: carbon_core::graphql::primitives::Pubkey(row.owner.0),
            amount: carbon_core::graphql::primitives::U64(*row.amount),
            delegate: row
                .delegate
                .map(|v| carbon_core::graphql::primitives::Pubkey(v.0)),
            state: row.state.0.into(),
            is_native: row
                .is_native
                .map(|v| carbon_core::graphql::primitives::U64(*v)),
            delegated_amount: carbon_core::graphql::primitives::U64(*row.delegated_amount),
            close_authority: row
                .close_authority
                .map(|v| carbon_core::graphql::primitives::Pubkey(v.0)),
        })
    }
}