carbon-swig-decoder 0.12.0

Swig Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::account_utils::next_account;
use carbon_core::borsh;
use carbon_core::deserialize::ArrangeAccounts;
use carbon_core::deserialize::CarbonDeserialize;
use carbon_core::CarbonDeserialize;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq)]
pub struct CreateV1 {}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateV1InstructionAccounts {
    pub swig: solana_pubkey::Pubkey,
    pub payer: solana_pubkey::Pubkey,
    pub swig_wallet_address: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl CreateV1 {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.is_empty() {
            return None;
        }
        let discriminator = &data[0..1];
        if discriminator != [0] {
            return None;
        }

        let data_slice = data;

        let data_slice = &data_slice[1..];

        Self::deserialize(data_slice)
    }
}

impl ArrangeAccounts for CreateV1 {
    type ArrangedAccounts = CreateV1InstructionAccounts;

    fn arrange_accounts(
        accounts: &[solana_instruction::AccountMeta],
    ) -> Option<Self::ArrangedAccounts> {
        let mut iter = accounts.iter();

        let swig = next_account(&mut iter)?;
        let payer = next_account(&mut iter)?;
        let swig_wallet_address = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CreateV1InstructionAccounts {
            swig,
            payer,
            swig_wallet_address,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}