use {
crate::types::graphql::{OrderTriggerTypeGraphQL, WrappedI80F48GraphQL},
carbon_core::graphql::primitives::{Pubkey, U32, U64, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Order")]
pub struct OrderGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub marginfi_account: Pubkey,
pub stop_loss: WrappedI80F48GraphQL,
pub take_profit: WrappedI80F48GraphQL,
pub placeholder: U64,
pub max_slippage: U32,
pub pad0: Vec<U8>,
pub tags: Vec<i32>,
pub pad1: Vec<U8>,
pub tags_padding: Vec<U8>,
pub trigger: OrderTriggerTypeGraphQL,
pub bump: U8,
pub pad2: Vec<U8>,
pub reserved1: Vec<Vec<U8>>,
}
impl TryFrom<crate::accounts::postgres::OrderRow> for OrderGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::OrderRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
marginfi_account: carbon_core::graphql::primitives::Pubkey(row.marginfi_account.0),
stop_loss: row.stop_loss.0.into(),
take_profit: row.take_profit.0.into(),
placeholder: carbon_core::graphql::primitives::U64(*row.placeholder),
max_slippage: carbon_core::graphql::primitives::U32((*row.max_slippage) as u32),
pad0: row
.pad0
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
tags: row.tags.into_iter().map(|item| *item).collect(),
pad1: row
.pad1
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
tags_padding: row
.tags_padding
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
trigger: row.trigger.0.into(),
bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
pad2: row
.pad2
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
reserved1: row
.reserved1
.0
.into_iter()
.map(|item| {
item.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect()
})
.collect(),
})
}
}