use {
carbon_core::graphql::primitives::{U64, U8},
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CreateConfig")]
pub struct CreateConfigGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub curve_type: U8,
pub index: i32,
pub migrate_fee: U64,
pub trade_fee_rate: U64,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::CreateConfigRow> for CreateConfigGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::instructions::postgres::CreateConfigRow) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
curve_type: carbon_core::graphql::primitives::U8((*row.curve_type) as u8),
index: *row.index,
migrate_fee: carbon_core::graphql::primitives::U64(*row.migrate_fee),
trade_fee_rate: carbon_core::graphql::primitives::U64(*row.trade_fee_rate),
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}