use {carbon_core::graphql::primitives::U64, juniper::GraphQLObject, serde_json};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "TransferPools")]
pub struct TransferPoolsGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub deposit_from_market_index: i32,
pub deposit_to_market_index: i32,
pub borrow_from_market_index: i32,
pub borrow_to_market_index: i32,
pub deposit_amount: Option<U64>,
pub borrow_amount: Option<U64>,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::TransferPoolsRow> for TransferPoolsGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::instructions::postgres::TransferPoolsRow) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
deposit_from_market_index: *row.deposit_from_market_index,
deposit_to_market_index: *row.deposit_to_market_index,
borrow_from_market_index: *row.borrow_from_market_index,
borrow_to_market_index: *row.borrow_to_market_index,
deposit_amount: row
.deposit_amount
.map(|v| carbon_core::graphql::primitives::U64(*v)),
borrow_amount: row
.borrow_amount
.map(|v| carbon_core::graphql::primitives::U64(*v)),
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}