carbon-wavebreak-decoder 2.0.0

Wavebreak Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::GraduationMethodGraphQL,
    carbon_core::graphql::primitives::{I64, U128, U64},
    juniper::GraphQLObject,
    serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "CreatePresale")]
pub struct CreatePresaleGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub name: String,
    pub symbol: String,
    pub uri: String,
    pub token_price: Option<U128>,
    pub graduation_target: Option<U64>,
    pub graduation_methods: Option<Vec<GraduationMethodGraphQL>>,
    pub launch_time: Option<I64>,
    pub graduation_time: Option<I64>,
    pub min_reserve_bps: Option<i32>,
    pub base_allocation_bps: Option<i32>,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::CreatePresaleRow> for CreatePresaleGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::CreatePresaleRow) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            name: row.name,
            symbol: row.symbol,
            uri: row.uri,
            token_price: row
                .token_price
                .map(|v| carbon_core::graphql::primitives::U128(*v)),
            graduation_target: row
                .graduation_target
                .map(|v| carbon_core::graphql::primitives::U64(*v)),
            graduation_methods: row.graduation_methods.map(|v| {
                v.0.clone()
                    .clone()
                    .into_iter()
                    .map(|item| item.into())
                    .collect()
            }),
            launch_time: row.launch_time.map(carbon_core::graphql::primitives::I64),
            graduation_time: row
                .graduation_time
                .map(carbon_core::graphql::primitives::I64),
            min_reserve_bps: row.min_reserve_bps.map(|v| *v),
            base_allocation_bps: row.base_allocation_bps.map(|v| *v),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}