carbon-openbook-v2-decoder 2.0.0

Openbook V2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::OracleConfigParamsGraphQL, carbon_core::graphql::primitives::I64,
    juniper::GraphQLObject, serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CreateMarket")]
pub struct CreateMarketGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub name: String,
    pub oracle_config: OracleConfigParamsGraphQL,
    pub quote_lot_size: I64,
    pub base_lot_size: I64,
    pub maker_fee: I64,
    pub taker_fee: I64,
    pub time_expiry: I64,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::CreateMarketRow> for CreateMarketGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::CreateMarketRow) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            name: row.name,
            oracle_config: row.oracle_config.0.into(),
            quote_lot_size: carbon_core::graphql::primitives::I64(row.quote_lot_size),
            base_lot_size: carbon_core::graphql::primitives::I64(row.base_lot_size),
            maker_fee: carbon_core::graphql::primitives::I64(row.maker_fee),
            taker_fee: carbon_core::graphql::primitives::I64(row.taker_fee),
            time_expiry: carbon_core::graphql::primitives::I64(row.time_expiry),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}