carbon-tcomp-decoder 0.12.1

Rust decoder for Tensor cNFT Compressed program on Solana
Documentation
//! This code was AUTOGENERATED using the Codama library.
use crate::types::Field;
use crate::types::Target;
use carbon_core::CarbonDeserialize;
use carbon_core::account_utils::next_account;
use carbon_core::borsh;
use carbon_core::deserialize::ArrangeAccounts;
use carbon_core::deserialize::CarbonDeserialize;
use solana_pubkey::Pubkey;

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq, Eq, Hash)]
pub struct Bid {
    pub bid_id: Pubkey,
    pub target: Target,
    pub target_id: Pubkey,
    pub field: Option<Field>,
    pub field_id: Option<Pubkey>,
    pub amount: u64,
    pub quantity: u32,
    pub expire_in_sec: Option<u64>,
    pub currency: Option<Pubkey>,
    pub private_taker: Option<Pubkey>,
    pub maker_broker: Option<Pubkey>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BidInstructionAccounts {
    pub system_program: solana_pubkey::Pubkey,
    pub tcomp_program: solana_pubkey::Pubkey,
    pub bid_state: solana_pubkey::Pubkey,
    pub owner: solana_pubkey::Pubkey,
    pub margin_account: solana_pubkey::Pubkey,
    pub cosigner: solana_pubkey::Pubkey,
    pub rent_payer: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl Bid {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != &[199, 56, 85, 38, 146, 243, 37, 158] {
            return None;
        }

        let data_slice = data;

        let data_slice = &data_slice[8..];

        Self::deserialize(data_slice)
    }
}

impl ArrangeAccounts for Bid {
    type ArrangedAccounts = BidInstructionAccounts;

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

        let system_program = next_account(&mut iter)?;
        let tcomp_program = next_account(&mut iter)?;
        let bid_state = next_account(&mut iter)?;
        let owner = next_account(&mut iter)?;
        let margin_account = next_account(&mut iter)?;
        let cosigner = next_account(&mut iter)?;
        let rent_payer = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(BidInstructionAccounts {
            system_program,
            tcomp_program,
            bid_state,
            owner,
            margin_account,
            cosigner,
            rent_payer,
            remaining: remaining.to_vec(),
        })
    }
}