carbon-token-2022-decoder 2.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// This instruction is to be used to rescue SOLs sent to any TokenProgram
/// owned account by sending them to any other account, leaving behind only
/// lamports for rent exemption.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct WithdrawExcessLamports {}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WithdrawExcessLamportsInstructionAccounts {
    pub source_account: solana_pubkey::Pubkey,
    pub destination_account: solana_pubkey::Pubkey,
    pub authority: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}

impl ArrangeAccounts for WithdrawExcessLamports {
    type ArrangedAccounts = WithdrawExcessLamportsInstructionAccounts;

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

        let source_account = next_account(&mut iter)?;
        let destination_account = next_account(&mut iter)?;
        let authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(WithdrawExcessLamportsInstructionAccounts {
            source_account,
            destination_account,
            authority,
            remaining: remaining.to_vec(),
        })
    }
}