use {
crate::types::graphql::{APYGraphQL, BookLoanTermsGraphQL, OrderBookTypeGraphQL},
carbon_core::graphql::primitives::Pubkey,
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CreateOrderBook")]
pub struct CreateOrderBookGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub order_book_type: OrderBookTypeGraphQL,
pub apy: APYGraphQL,
pub loan_terms: BookLoanTermsGraphQL,
pub fee_permillicentage: i32,
pub fee_authority: Pubkey,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::CreateOrderBookRow> for CreateOrderBookGraphQL {
type Error = carbon_core::error::Error;
fn try_from(
row: crate::instructions::postgres::CreateOrderBookRow,
) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
order_book_type: row.order_book_type.0.into(),
apy: row.apy.0.into(),
loan_terms: row.loan_terms.0.into(),
fee_permillicentage: *row.fee_permillicentage,
fee_authority: carbon_core::graphql::primitives::Pubkey(row.fee_authority.0),
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}