spl_account_compression/noop/
mod.rs

1//! # Data Wrapper
2//! We use CPI calls to circumvent the 10kb log limit on Solana transactions.
3//! Instead of logging events to the runtime, we execute a CPI to the `wrapper` program
4//! where the log data is serialized into the instruction data.
5//!
6//! This works because CPI instruction data is never truncated. Logging information is
7//! vital to the functioning of compression. When compression logs are truncated, indexers can fallback to
8//! deserializing the CPI instruction data.
9
10use crate::events::{AccountCompressionEvent, ApplicationDataEvent, ApplicationDataEventV1};
11use anchor_lang::{prelude::*, solana_program::program::invoke};
12
13#[derive(Clone)]
14pub struct Noop;
15
16impl anchor_lang::Id for Noop {
17    fn id() -> Pubkey {
18        anchor_lang::prelude::Pubkey::from(spl_noop::id().to_bytes())
19    }
20}
21
22pub fn wrap_event<'info>(
23    event: &AccountCompressionEvent,
24    noop_program: &Program<'info, Noop>,
25) -> Result<()> {
26    invoke(
27        &spl_noop::instruction(event.try_to_vec()?),
28        &[noop_program.to_account_info()],
29    )?;
30    Ok(())
31}
32
33/// Wraps a custom event in the most recent version of application event data
34pub fn wrap_application_data_v1<'info>(
35    custom_data: Vec<u8>,
36    noop_program: &Program<'info, Noop>,
37) -> Result<()> {
38    let versioned_data = ApplicationDataEventV1 {
39        application_data: custom_data,
40    };
41    wrap_event(
42        &AccountCompressionEvent::ApplicationData(ApplicationDataEvent::V1(versioned_data)),
43        noop_program,
44    )
45}