use {
crate::types::graphql::{OrderTypeGraphQL, SideGraphQL},
carbon_core::graphql::primitives::U64,
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "PlaceOrderV3")]
pub struct PlaceOrderV3GraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub price: U64,
pub size: U64,
pub side: SideGraphQL,
pub order_type: OrderTypeGraphQL,
pub client_order_id: Option<U64>,
pub tag: Option<String>,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::PlaceOrderV3Row> for PlaceOrderV3GraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::instructions::postgres::PlaceOrderV3Row) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
price: carbon_core::graphql::primitives::U64(*row.price),
size: carbon_core::graphql::primitives::U64(*row.size),
side: row.side.0.into(),
order_type: row.order_type.0.into(),
client_order_id: row
.client_order_id
.map(|v| carbon_core::graphql::primitives::U64(*v)),
tag: row.tag,
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}