use {
carbon_core::graphql::primitives::{U128, U64},
juniper::GraphQLObject,
serde_json,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "TwoHopSwap")]
pub struct TwoHopSwapGraphQL {
pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
pub amount: U64,
pub other_amount_threshold: U64,
pub amount_specified_is_input: bool,
pub a_to_b_one: bool,
pub a_to_b_two: bool,
pub sqrt_price_limit_one: U128,
pub sqrt_price_limit_two: U128,
pub accounts: carbon_core::graphql::primitives::Json,
}
impl TryFrom<crate::instructions::postgres::TwoHopSwapRow> for TwoHopSwapGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::instructions::postgres::TwoHopSwapRow) -> Result<Self, Self::Error> {
Ok(Self {
instruction_metadata: row.instruction_metadata.into(),
amount: carbon_core::graphql::primitives::U64(*row.amount),
other_amount_threshold: carbon_core::graphql::primitives::U64(
*row.other_amount_threshold,
),
amount_specified_is_input: row.amount_specified_is_input,
a_to_b_one: row.a_to_b_one,
a_to_b_two: row.a_to_b_two,
sqrt_price_limit_one: carbon_core::graphql::primitives::U128(*row.sqrt_price_limit_one),
sqrt_price_limit_two: carbon_core::graphql::primitives::U128(*row.sqrt_price_limit_two),
accounts: carbon_core::graphql::primitives::Json(
serde_json::to_value(&row.accounts.0)
.map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
),
})
}
}