carbon-swig-decoder 0.12.0

Swig Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use crate::SwigDecoder;
use crate::PROGRAM_ID;
#[cfg(feature = "postgres")]
pub mod postgres;

#[cfg(feature = "graphql")]
pub mod graphql;

pub mod add_authority_v1;
pub mod create_session_v1;
pub mod create_sub_account_v1;
pub mod create_v1;
pub mod migrate_to_wallet_address_v1;
pub mod remove_authority_v1;
pub mod sign_v1;
pub mod sign_v2;
pub mod sub_account_sign_v1;
pub mod toggle_sub_account_v1;
pub mod transfer_assets_v1;
pub mod update_authority_v1;
pub mod withdraw_from_sub_account_v1;

pub use self::add_authority_v1::*;
pub use self::create_session_v1::*;
pub use self::create_sub_account_v1::*;
pub use self::create_v1::*;
pub use self::migrate_to_wallet_address_v1::*;
pub use self::remove_authority_v1::*;
pub use self::sign_v1::*;
pub use self::sign_v2::*;
pub use self::sub_account_sign_v1::*;
pub use self::toggle_sub_account_v1::*;
pub use self::transfer_assets_v1::*;
pub use self::update_authority_v1::*;
pub use self::withdraw_from_sub_account_v1::*;

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))]
pub enum SwigInstruction {
    AddAuthorityV1(AddAuthorityV1),
    CreateSessionV1(CreateSessionV1),
    CreateSubAccountV1(CreateSubAccountV1),
    CreateV1(CreateV1),
    MigrateToWalletAddressV1(MigrateToWalletAddressV1),
    RemoveAuthorityV1(RemoveAuthorityV1),
    SignV1(SignV1),
    SignV2(SignV2),
    SubAccountSignV1(SubAccountSignV1),
    ToggleSubAccountV1(ToggleSubAccountV1),
    TransferAssetsV1(TransferAssetsV1),
    UpdateAuthorityV1(UpdateAuthorityV1),
    WithdrawFromSubAccountV1(WithdrawFromSubAccountV1),
}

impl carbon_core::instruction::InstructionDecoder<'_> for SwigDecoder {
    type InstructionType = SwigInstruction;

    fn decode_instruction(
        &self,
        instruction: &solana_instruction::Instruction,
    ) -> Option<carbon_core::instruction::DecodedInstruction<Self::InstructionType>> {
        if !instruction.program_id.eq(&PROGRAM_ID) {
            return None;
        }

        let data = instruction.data.as_slice();

        {
            if let Some(decoded) = create_v1::CreateV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::CreateV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = add_authority_v1::AddAuthorityV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::AddAuthorityV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = remove_authority_v1::RemoveAuthorityV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::RemoveAuthorityV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = update_authority_v1::UpdateAuthorityV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::UpdateAuthorityV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = sign_v1::SignV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::SignV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = sign_v2::SignV2::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::SignV2(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = create_session_v1::CreateSessionV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::CreateSessionV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = create_sub_account_v1::CreateSubAccountV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::CreateSubAccountV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) =
                withdraw_from_sub_account_v1::WithdrawFromSubAccountV1::decode(data)
            {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::WithdrawFromSubAccountV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = sub_account_sign_v1::SubAccountSignV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::SubAccountSignV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = toggle_sub_account_v1::ToggleSubAccountV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::ToggleSubAccountV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) =
                migrate_to_wallet_address_v1::MigrateToWalletAddressV1::decode(data)
            {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::MigrateToWalletAddressV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }
        {
            if let Some(decoded) = transfer_assets_v1::TransferAssetsV1::decode(data) {
                return Some(carbon_core::instruction::DecodedInstruction {
                    program_id: instruction.program_id,
                    data: SwigInstruction::TransferAssetsV1(decoded),
                    accounts: instruction.accounts.clone(),
                });
            }
        }

        None
    }
}