carbon-sharky-decoder 2.0.0

Sharky Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{APYGraphQL, BookLoanTermsGraphQL, OrderBookTypeGraphQL},
    carbon_core::graphql::primitives::Pubkey,
    juniper::GraphQLObject,
    serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "UpdateOrderBook")]
pub struct UpdateOrderBookGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub order_book_type: Option<OrderBookTypeGraphQL>,
    pub apy: Option<APYGraphQL>,
    pub loan_terms: Option<BookLoanTermsGraphQL>,
    pub fee_permillicentage: Option<i32>,
    pub fee_authority: Option<Pubkey>,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::UpdateOrderBookRow> for UpdateOrderBookGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(
        row: crate::instructions::postgres::UpdateOrderBookRow,
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            order_book_type: row.order_book_type.map(|v| v.0.into()),
            apy: row.apy.map(|v| v.0.into()),
            loan_terms: row.loan_terms.map(|v| v.0.into()),
            fee_permillicentage: row.fee_permillicentage.map(|v| *v),
            fee_authority: row
                .fee_authority
                .map(|v| carbon_core::graphql::primitives::Pubkey(v.0)),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}