carbon-system-program-decoder 1.0.0

System Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
pub mod nonce_row;

pub use self::nonce_row::*;
use super::SystemProgramAccount;

pub struct SystemProgramAccountsMigration;

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

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

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

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

pub struct SystemProgramAccountWithMetadata(
    pub SystemProgramAccount,
    pub carbon_core::account::AccountMetadata,
);

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

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

        match account {
            SystemProgramAccount::Nonce(account) => {
                let row = nonce_row::NonceRow::from_parts(*account.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

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