carbon-sharky-decoder 2.0.0

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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "ForecloseLoanV3Compressed")]
pub struct ForecloseLoanV3CompressedGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub cnft_root: Vec<U8>,
    pub cnft_data_hash: Vec<U8>,
    pub cnft_creator_hash: Vec<U8>,
    pub cnft_nonce: U64,
    pub cnft_index: U32,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::ForecloseLoanV3CompressedRow>
    for ForecloseLoanV3CompressedGraphQL
{
    type Error = carbon_core::error::Error;
    fn try_from(
        row: crate::instructions::postgres::ForecloseLoanV3CompressedRow,
    ) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            cnft_root: row
                .cnft_root
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            cnft_data_hash: row
                .cnft_data_hash
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            cnft_creator_hash: row
                .cnft_creator_hash
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            cnft_nonce: carbon_core::graphql::primitives::U64(*row.cnft_nonce),
            cnft_index: carbon_core::graphql::primitives::U32((*row.cnft_index) as u32),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}