use {
crate::types::graphql::LoanStateGraphQL,
carbon_core::graphql::primitives::{Pubkey, U64, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Loan")]
pub struct LoanGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub version: U8,
pub principal_lamports: U64,
pub order_book: Pubkey,
pub value_token_mint: Pubkey,
pub escrow_bump_seed: U8,
pub loan_state: LoanStateGraphQL,
}
impl TryFrom<crate::accounts::postgres::LoanRow> for LoanGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::LoanRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
version: carbon_core::graphql::primitives::U8((*row.version) as u8),
principal_lamports: carbon_core::graphql::primitives::U64(*row.principal_lamports),
order_book: carbon_core::graphql::primitives::Pubkey(row.order_book.0),
value_token_mint: carbon_core::graphql::primitives::Pubkey(row.value_token_mint.0),
escrow_bump_seed: carbon_core::graphql::primitives::U8((*row.escrow_bump_seed) as u8),
loan_state: row.loan_state.0.into(),
})
}
}