use {
crate::types::graphql::TargetsDatumGraphQL,
carbon_core::graphql::primitives::{Pubkey, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "ConstituentTargetBase")]
pub struct ConstituentTargetBaseGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub lp_pool: Pubkey,
pub bump: U8,
pub padding: Vec<U8>,
pub targets: Vec<TargetsDatumGraphQL>,
}
impl TryFrom<crate::accounts::postgres::ConstituentTargetBaseRow> for ConstituentTargetBaseGraphQL {
type Error = carbon_core::error::Error;
fn try_from(
row: crate::accounts::postgres::ConstituentTargetBaseRow,
) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
lp_pool: carbon_core::graphql::primitives::Pubkey(row.lp_pool.0),
bump: carbon_core::graphql::primitives::U8((*row.bump) as u8),
padding: row
.padding
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
targets: row.targets.0.into_iter().map(|item| item.into()).collect(),
})
}
}