triggr/state/
temp.rs

1use crate::state::SerializableInstruction;
2use anchor_lang::prelude::*;
3
4#[account]
5pub struct TempInstructions {
6    pub bundles: Vec<SerializableInstruction>,
7}
8
9#[derive(Clone, PartialEq, Eq, Debug, AnchorDeserialize, AnchorSerialize)]
10pub struct BufferPart {
11    index: u8,
12    buffer: Vec<u8>,
13}
14
15#[account]
16pub struct TempStore {
17    pub buffer: Vec<BufferPart>,
18    pub initializer: Pubkey,
19    pub expiration_slot: u64,
20}
21
22impl TempStore {
23    pub fn construct_complete_buffer(&self) -> Vec<u8> {
24        // Sort the buffer parts by index
25        let mut sorted_parts = self.buffer.clone();
26        sorted_parts.sort_by(|a, b| a.index.cmp(&b.index));
27
28        // Construct the final buffer
29        let mut result = Vec::new();
30        for part in sorted_parts {
31            result.extend_from_slice(&part.buffer);
32        }
33
34        result
35    }
36}