carbon-associated-token-account-decoder 1.0.0

Associated Token Account program decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
pub mod create_idempotent_row;
pub mod create_row;
pub mod recover_nested_row;

pub use self::{create_idempotent_row::*, create_row::*, recover_nested_row::*};
use super::AssociatedTokenAccountInstruction;

pub struct AssociatedTokenAccountInstructionsMigration;

impl sqlx_migrator::Migration<sqlx::Postgres> for AssociatedTokenAccountInstructionsMigration {
    fn app(&self) -> &str {
        "associated-token-account"
    }

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

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

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

pub struct AssociatedTokenAccountInstructionWithMetadata(
    pub AssociatedTokenAccountInstruction,
    pub carbon_core::instruction::InstructionMetadata,
    pub Vec<solana_instruction::AccountMeta>,
);

impl
    From<(
        AssociatedTokenAccountInstruction,
        carbon_core::instruction::InstructionMetadata,
        Vec<solana_instruction::AccountMeta>,
    )> for AssociatedTokenAccountInstructionWithMetadata
{
    fn from(
        value: (
            AssociatedTokenAccountInstruction,
            carbon_core::instruction::InstructionMetadata,
            Vec<solana_instruction::AccountMeta>,
        ),
    ) -> Self {
        AssociatedTokenAccountInstructionWithMetadata(value.0, value.1, value.2)
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for AssociatedTokenAccountInstructionWithMetadata {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let AssociatedTokenAccountInstructionWithMetadata(
            decoded_instruction,
            metadata,
            raw_accounts,
        ) = self;
        match decoded_instruction {
            AssociatedTokenAccountInstruction::Create { data, .. } => {
                let row = create_row::CreateRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            AssociatedTokenAccountInstruction::CreateIdempotent { data, .. } => {
                let row = create_idempotent_row::CreateIdempotentRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            AssociatedTokenAccountInstruction::RecoverNested { data, .. } => {
                let row = recover_nested_row::RecoverNestedRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for AssociatedTokenAccountInstructionWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let AssociatedTokenAccountInstructionWithMetadata(
            decoded_instruction,
            metadata,
            raw_accounts,
        ) = self;
        match decoded_instruction {
            AssociatedTokenAccountInstruction::Create { data, .. } => {
                let row = create_row::CreateRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            AssociatedTokenAccountInstruction::CreateIdempotent { data, .. } => {
                let row = create_idempotent_row::CreateIdempotentRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            AssociatedTokenAccountInstruction::RecoverNested { data, .. } => {
                let row = recover_nested_row::RecoverNestedRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}