carbon-bubblegum-decoder 2.0.0

Bubblegum Program 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 = "CreateTree")]
pub struct CreateTreeGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub max_depth: U32,
    pub max_buffer_size: U32,
    pub public: Option<bool>,
    pub accounts: carbon_core::graphql::primitives::Json,
}

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