carbon-swig-decoder 0.12.0

Swig Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
pub mod add_authority_v1_row;
pub mod create_session_v1_row;
pub mod create_sub_account_v1_row;
pub mod create_v1_row;
pub mod migrate_to_wallet_address_v1_row;
pub mod remove_authority_v1_row;
pub mod sign_v1_row;
pub mod sign_v2_row;
pub mod sub_account_sign_v1_row;
pub mod toggle_sub_account_v1_row;
pub mod transfer_assets_v1_row;
pub mod update_authority_v1_row;
pub mod withdraw_from_sub_account_v1_row;

pub use self::add_authority_v1_row::*;
pub use self::create_session_v1_row::*;
pub use self::create_sub_account_v1_row::*;
pub use self::create_v1_row::*;
pub use self::migrate_to_wallet_address_v1_row::*;
pub use self::remove_authority_v1_row::*;
pub use self::sign_v1_row::*;
pub use self::sign_v2_row::*;
pub use self::sub_account_sign_v1_row::*;
pub use self::toggle_sub_account_v1_row::*;
pub use self::transfer_assets_v1_row::*;
pub use self::update_authority_v1_row::*;
pub use self::withdraw_from_sub_account_v1_row::*;

use super::SwigInstruction;

pub struct SwigInstructionsMigration;

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

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

    fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
        vec![
            Box::new(AddAuthorityV1MigrationOperation),
            Box::new(CreateSessionV1MigrationOperation),
            Box::new(CreateSubAccountV1MigrationOperation),
            Box::new(CreateV1MigrationOperation),
            Box::new(MigrateToWalletAddressV1MigrationOperation),
            Box::new(RemoveAuthorityV1MigrationOperation),
            Box::new(SignV1MigrationOperation),
            Box::new(SignV2MigrationOperation),
            Box::new(SubAccountSignV1MigrationOperation),
            Box::new(ToggleSubAccountV1MigrationOperation),
            Box::new(TransferAssetsV1MigrationOperation),
            Box::new(UpdateAuthorityV1MigrationOperation),
            Box::new(WithdrawFromSubAccountV1MigrationOperation),
        ]
    }

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

pub struct SwigInstructionWithMetadata(
    pub SwigInstruction,
    pub carbon_core::instruction::InstructionMetadata,
);

impl
    From<(
        SwigInstruction,
        carbon_core::instruction::InstructionMetadata,
    )> for SwigInstructionWithMetadata
{
    fn from(
        value: (
            SwigInstruction,
            carbon_core::instruction::InstructionMetadata,
        ),
    ) -> Self {
        SwigInstructionWithMetadata(value.0, value.1)
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for SwigInstructionWithMetadata {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let SwigInstructionWithMetadata(instruction, metadata) = self;
        match instruction {
            SwigInstruction::CreateV1(instruction) => {
                let row =
                    create_v1_row::CreateV1Row::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::AddAuthorityV1(instruction) => {
                let row = add_authority_v1_row::AddAuthorityV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::RemoveAuthorityV1(instruction) => {
                let row = remove_authority_v1_row::RemoveAuthorityV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::UpdateAuthorityV1(instruction) => {
                let row = update_authority_v1_row::UpdateAuthorityV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::SignV1(instruction) => {
                let row = sign_v1_row::SignV1Row::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::SignV2(instruction) => {
                let row = sign_v2_row::SignV2Row::from_parts(instruction.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::CreateSessionV1(instruction) => {
                let row = create_session_v1_row::CreateSessionV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::CreateSubAccountV1(instruction) => {
                let row = create_sub_account_v1_row::CreateSubAccountV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::WithdrawFromSubAccountV1(instruction) => {
                let row = withdraw_from_sub_account_v1_row::WithdrawFromSubAccountV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::SubAccountSignV1(instruction) => {
                let row = sub_account_sign_v1_row::SubAccountSignV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::ToggleSubAccountV1(instruction) => {
                let row = toggle_sub_account_v1_row::ToggleSubAccountV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::MigrateToWalletAddressV1(instruction) => {
                let row = migrate_to_wallet_address_v1_row::MigrateToWalletAddressV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            SwigInstruction::TransferAssetsV1(instruction) => {
                let row = transfer_assets_v1_row::TransferAssetsV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for SwigInstructionWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let SwigInstructionWithMetadata(instruction, metadata) = self;
        match instruction {
            SwigInstruction::CreateV1(instruction) => {
                let row =
                    create_v1_row::CreateV1Row::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::AddAuthorityV1(instruction) => {
                let row = add_authority_v1_row::AddAuthorityV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::RemoveAuthorityV1(instruction) => {
                let row = remove_authority_v1_row::RemoveAuthorityV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::UpdateAuthorityV1(instruction) => {
                let row = update_authority_v1_row::UpdateAuthorityV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::SignV1(instruction) => {
                let row = sign_v1_row::SignV1Row::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::SignV2(instruction) => {
                let row = sign_v2_row::SignV2Row::from_parts(instruction.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::CreateSessionV1(instruction) => {
                let row = create_session_v1_row::CreateSessionV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::CreateSubAccountV1(instruction) => {
                let row = create_sub_account_v1_row::CreateSubAccountV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::WithdrawFromSubAccountV1(instruction) => {
                let row = withdraw_from_sub_account_v1_row::WithdrawFromSubAccountV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::SubAccountSignV1(instruction) => {
                let row = sub_account_sign_v1_row::SubAccountSignV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::ToggleSubAccountV1(instruction) => {
                let row = toggle_sub_account_v1_row::ToggleSubAccountV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::MigrateToWalletAddressV1(instruction) => {
                let row = migrate_to_wallet_address_v1_row::MigrateToWalletAddressV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            SwigInstruction::TransferAssetsV1(instruction) => {
                let row = transfer_assets_v1_row::TransferAssetsV1Row::from_parts(
                    instruction.clone(),
                    metadata.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}