carbon-sharky-decoder 2.0.0

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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "TakeLoanV3")]
pub struct TakeLoanV3GraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub expected_loan: String,
    pub nft_list_index: Option<U32>,
    pub skip_freezing_collateral: bool,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::TakeLoanV3Row> for TakeLoanV3GraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::TakeLoanV3Row) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            expected_loan: row.expected_loan,
            nft_list_index: row
                .nft_list_index
                .map(|v| carbon_core::graphql::primitives::U32((*v) as u32)),
            skip_freezing_collateral: row.skip_freezing_collateral,
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}