triggr-program 0.1.1

Created with Anchor
Documentation
use crate::state::SerializableInstruction;
use anchor_lang::prelude::*;

#[account]
pub struct TempInstructions {
    pub bundles: Vec<SerializableInstruction>,
}

#[derive(Clone, PartialEq, Eq, Debug, AnchorDeserialize, AnchorSerialize)]
pub struct BufferPart {
    index: u8,
    buffer: Vec<u8>,
}

#[account]
pub struct TempStore {
    pub buffer: Vec<BufferPart>,
    pub initializer: Pubkey,
    pub expiration_slot: u64,
}

impl TempStore {
    pub fn construct_complete_buffer(&self) -> Vec<u8> {
        // Sort the buffer parts by index
        let mut sorted_parts = self.buffer.clone();
        sorted_parts.sort_by(|a, b| a.index.cmp(&b.index));

        // Construct the final buffer
        let mut result = Vec::new();
        for part in sorted_parts {
            result.extend_from_slice(&part.buffer);
        }

        result
    }
}