pub mod add_authority_v1_row;
pub mod close_swig_v1_row;
pub mod close_token_account_v1_row;
pub mod create_session_v1_row;
pub mod create_sub_account_v1_row;
pub mod create_v1_row;
pub mod deprecated_sign_v1_row;
pub mod migrate_to_wallet_address_v1_row;
pub mod remove_authority_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::*, close_swig_v1_row::*, close_token_account_v1_row::*,
create_session_v1_row::*, create_sub_account_v1_row::*, create_v1_row::*,
deprecated_sign_v1_row::*, migrate_to_wallet_address_v1_row::*, remove_authority_v1_row::*,
sign_v2_row::*, sub_account_sign_v1_row::*, toggle_sub_account_v1_row::*,
transfer_assets_v1_row::*, update_authority_v1_row::*, 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(CloseSwigV1MigrationOperation),
Box::new(CloseTokenAccountV1MigrationOperation),
Box::new(CreateSessionV1MigrationOperation),
Box::new(CreateSubAccountV1MigrationOperation),
Box::new(CreateV1MigrationOperation),
Box::new(DeprecatedSignV1MigrationOperation),
Box::new(MigrateToWalletAddressV1MigrationOperation),
Box::new(RemoveAuthorityV1MigrationOperation),
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,
pub Vec<solana_instruction::AccountMeta>,
);
impl
From<(
SwigInstruction,
carbon_core::instruction::InstructionMetadata,
Vec<solana_instruction::AccountMeta>,
)> for SwigInstructionWithMetadata
{
fn from(
value: (
SwigInstruction,
carbon_core::instruction::InstructionMetadata,
Vec<solana_instruction::AccountMeta>,
),
) -> Self {
SwigInstructionWithMetadata(value.0, value.1, value.2)
}
}
#[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(decoded_instruction, metadata, raw_accounts) = self;
match decoded_instruction {
SwigInstruction::CreateV1 { data, .. } => {
let row = create_v1_row::CreateV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::AddAuthorityV1 { data, .. } => {
let row = add_authority_v1_row::AddAuthorityV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::RemoveAuthorityV1 { data, .. } => {
let row = remove_authority_v1_row::RemoveAuthorityV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::UpdateAuthorityV1 { data, .. } => {
let row = update_authority_v1_row::UpdateAuthorityV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::DeprecatedSignV1 { data, .. } => {
let row = deprecated_sign_v1_row::DeprecatedSignV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::CreateSessionV1 { data, .. } => {
let row = create_session_v1_row::CreateSessionV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::CreateSubAccountV1 { data, .. } => {
let row = create_sub_account_v1_row::CreateSubAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::WithdrawFromSubAccountV1 { data, .. } => {
let row = withdraw_from_sub_account_v1_row::WithdrawFromSubAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::SubAccountSignV1 { data, .. } => {
let row = sub_account_sign_v1_row::SubAccountSignV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::ToggleSubAccountV1 { data, .. } => {
let row = toggle_sub_account_v1_row::ToggleSubAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::SignV2 { data, .. } => {
let row = sign_v2_row::SignV2Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::MigrateToWalletAddressV1 { data, .. } => {
let row = migrate_to_wallet_address_v1_row::MigrateToWalletAddressV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::TransferAssetsV1 { data, .. } => {
let row = transfer_assets_v1_row::TransferAssetsV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::CloseTokenAccountV1 { data, .. } => {
let row = close_token_account_v1_row::CloseTokenAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.insert(pool).await?;
Ok(())
}
SwigInstruction::CloseSwigV1 { data, .. } => {
let row = close_swig_v1_row::CloseSwigV1Row::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 SwigInstructionWithMetadata {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let SwigInstructionWithMetadata(decoded_instruction, metadata, raw_accounts) = self;
match decoded_instruction {
SwigInstruction::CreateV1 { data, .. } => {
let row = create_v1_row::CreateV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::AddAuthorityV1 { data, .. } => {
let row = add_authority_v1_row::AddAuthorityV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::RemoveAuthorityV1 { data, .. } => {
let row = remove_authority_v1_row::RemoveAuthorityV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::UpdateAuthorityV1 { data, .. } => {
let row = update_authority_v1_row::UpdateAuthorityV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::DeprecatedSignV1 { data, .. } => {
let row = deprecated_sign_v1_row::DeprecatedSignV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::CreateSessionV1 { data, .. } => {
let row = create_session_v1_row::CreateSessionV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::CreateSubAccountV1 { data, .. } => {
let row = create_sub_account_v1_row::CreateSubAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::WithdrawFromSubAccountV1 { data, .. } => {
let row = withdraw_from_sub_account_v1_row::WithdrawFromSubAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::SubAccountSignV1 { data, .. } => {
let row = sub_account_sign_v1_row::SubAccountSignV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::ToggleSubAccountV1 { data, .. } => {
let row = toggle_sub_account_v1_row::ToggleSubAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::SignV2 { data, .. } => {
let row = sign_v2_row::SignV2Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::MigrateToWalletAddressV1 { data, .. } => {
let row = migrate_to_wallet_address_v1_row::MigrateToWalletAddressV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::TransferAssetsV1 { data, .. } => {
let row = transfer_assets_v1_row::TransferAssetsV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::CloseTokenAccountV1 { data, .. } => {
let row = close_token_account_v1_row::CloseTokenAccountV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
SwigInstruction::CloseSwigV1 { data, .. } => {
let row = close_swig_v1_row::CloseSwigV1Row::from_parts(
data.clone(),
metadata.clone(),
raw_accounts.clone(),
);
row.upsert(pool).await?;
Ok(())
}
}
}
}