use {
crate::types::graphql::{LiquidationCacheGraphQL, LiquidationEntryGraphQL},
carbon_core::graphql::primitives::{Pubkey, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "LiquidationRecord")]
pub struct LiquidationRecordGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub key: Pubkey,
pub marginfi_account: Pubkey,
pub record_payer: Pubkey,
pub liquidation_receiver: Pubkey,
pub entries: Vec<LiquidationEntryGraphQL>,
pub cache: LiquidationCacheGraphQL,
pub reserved0: Vec<U8>,
pub reserved2: Vec<U8>,
pub reserved3: Vec<U8>,
}
impl TryFrom<crate::accounts::postgres::LiquidationRecordRow> for LiquidationRecordGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::LiquidationRecordRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
key: carbon_core::graphql::primitives::Pubkey(row.key.0),
marginfi_account: carbon_core::graphql::primitives::Pubkey(row.marginfi_account.0),
record_payer: carbon_core::graphql::primitives::Pubkey(row.record_payer.0),
liquidation_receiver: carbon_core::graphql::primitives::Pubkey(
row.liquidation_receiver.0,
),
entries: row.entries.0.into_iter().map(|item| item.into()).collect(),
cache: row.cache.0.into(),
reserved0: row
.reserved0
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
reserved2: row
.reserved2
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
reserved3: row
.reserved3
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
})
}
}