carbon-moonshot-decoder 1.0.0

Moonshot Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
pub mod config_account_row;
pub mod curve_account_row;

pub use self::{config_account_row::*, curve_account_row::*};
use super::MoonshotAccount;

pub struct MoonshotAccountsMigration;

impl sqlx_migrator::Migration<sqlx::Postgres> for MoonshotAccountsMigration {
    fn app(&self) -> &str {
        "moonshot"
    }

    fn name(&self) -> &str {
        "moonshot_accounts"
    }

    fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
        vec![
            Box::new(ConfigAccountMigrationOperation),
            Box::new(CurveAccountMigrationOperation),
        ]
    }

    fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
        vec![]
    }
}

pub struct MoonshotAccountWithMetadata(
    pub MoonshotAccount,
    pub carbon_core::account::AccountMetadata,
);

impl From<(MoonshotAccount, carbon_core::account::AccountMetadata)>
    for MoonshotAccountWithMetadata
{
    fn from(value: (MoonshotAccount, carbon_core::account::AccountMetadata)) -> Self {
        MoonshotAccountWithMetadata(value.0, value.1)
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for MoonshotAccountWithMetadata {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let MoonshotAccountWithMetadata(account, metadata) = self;

        match account {
            MoonshotAccount::ConfigAccount(account) => {
                let row = config_account_row::ConfigAccountRow::from_parts(
                    *account.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            MoonshotAccount::CurveAccount(account) => {
                let row = curve_account_row::CurveAccountRow::from_parts(
                    *account.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for MoonshotAccountWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let MoonshotAccountWithMetadata(account, metadata) = self;
        match account {
            MoonshotAccount::ConfigAccount(account) => {
                let row = config_account_row::ConfigAccountRow::from_parts(
                    *account.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            MoonshotAccount::CurveAccount(account) => {
                let row = curve_account_row::CurveAccountRow::from_parts(
                    *account.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}