1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::{Schema, SchemaValue};
use anchor_lang::prelude::*;
use spl_account_compression::{wrap_application_data_v1, Noop};

#[derive(AnchorDeserialize, AnchorSerialize)]
pub enum CompressedDataEventStream {
    Full { data: SchemaValue },
    PatchChunk { key: String, data: SchemaValue },
    Empty,
}

#[derive(AnchorDeserialize, AnchorSerialize)]
pub enum CompressedDataEvent {
    Leaf {
        slot: u64,
        tree_id: [u8; 32],
        leaf_idx: u32,
        seq: u64,
        stream_type: CompressedDataEventStream,
    },
    TreeSchemaValue {
        tree_id: [u8; 32],
        schema: Schema,
    },
}
impl CompressedDataEvent {
    pub fn wrap<'info>(&self, noop: &Program<'info, Noop>) -> Result<()> {
        wrap_application_data_v1(self.try_to_vec().unwrap(), noop)
    }
}