carbon-vertigo-decoder 1.0.0

Vertigo DEX Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
pub mod pool_row;

pub use self::pool_row::*;
use super::VertigoAccount;

pub struct VertigoAccountsMigration;

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

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

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

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

pub struct VertigoAccountWithMetadata(
    pub VertigoAccount,
    pub carbon_core::account::AccountMetadata,
);

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

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

        match account {
            VertigoAccount::Pool(account) => {
                let row = pool_row::PoolRow::from_parts(*account.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for VertigoAccountWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let VertigoAccountWithMetadata(account, metadata) = self;
        match account {
            VertigoAccount::Pool(account) => {
                let row = pool_row::PoolRow::from_parts(*account.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}