carbon-sharky-decoder 2.0.0

Sharky Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    carbon_core::graphql::primitives::{Pubkey, U32, U64},
    juniper::GraphQLObject,
    serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CreateTokenOrderbook")]
pub struct CreateTokenOrderbookGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub duration: U64,
    pub apr: U32,
    pub fee_permillicentage: i32,
    pub fee_authority: Pubkey,
    pub min_liquidity: Option<U64>,
    pub max_liquidity: Option<U64>,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::CreateTokenOrderbookRow>
    for CreateTokenOrderbookGraphQL
{
    type Error = carbon_core::error::Error;
    fn try_from(
        row: crate::instructions::postgres::CreateTokenOrderbookRow,
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            duration: carbon_core::graphql::primitives::U64(*row.duration),
            apr: carbon_core::graphql::primitives::U32((*row.apr) as u32),
            fee_permillicentage: *row.fee_permillicentage,
            fee_authority: carbon_core::graphql::primitives::Pubkey(row.fee_authority.0),
            min_liquidity: row
                .min_liquidity
                .map(|v| carbon_core::graphql::primitives::U64(*v)),
            max_liquidity: row
                .max_liquidity
                .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()))?,
            ),
        })
    }
}