carbon-sharky-decoder 2.0.0

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

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

impl TryFrom<crate::instructions::postgres::TakeLoanV3CompressedRow>
    for TakeLoanV3CompressedGraphQL
{
    type Error = carbon_core::error::Error;
    fn try_from(
        row: crate::instructions::postgres::TakeLoanV3CompressedRow,
    ) -> 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)),
            cnft_args: row.cnft_args.0.into(),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}