carbon-openbook-v2-decoder 2.0.0

Openbook V2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{NonZeroPubkeyOptionGraphQL, OpenOrderGraphQL, PositionGraphQL},
    carbon_core::graphql::primitives::{Pubkey, U32, U8},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "OpenOrdersAccount")]
pub struct OpenOrdersAccountGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub owner: Pubkey,
    pub market: Pubkey,
    pub name: Vec<U8>,
    pub delegate: NonZeroPubkeyOptionGraphQL,
    pub account_num: U32,
    pub bump: U8,
    pub version: U8,
    pub padding: Vec<U8>,
    pub position: PositionGraphQL,
    pub open_orders: Vec<OpenOrderGraphQL>,
}

impl TryFrom<crate::accounts::postgres::OpenOrdersAccountRow> for OpenOrdersAccountGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::OpenOrdersAccountRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            owner: carbon_core::graphql::primitives::Pubkey(row.owner.0),
            market: carbon_core::graphql::primitives::Pubkey(row.market.0),
            name: row
                .name
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            delegate: row.delegate.0.into(),
            account_num: carbon_core::graphql::primitives::U32((*row.account_num) as u32),
            bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
            version: carbon_core::graphql::primitives::U8((*row.version) as u8),
            padding: row
                .padding
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            position: row.position.0.into(),
            open_orders: row
                .open_orders
                .0
                .into_iter()
                .map(|item| item.into())
                .collect(),
        })
    }
}