chunk_loader/instructions/
pass_to_cpi.rs

1use crate::state::*;
2use anchor_lang::{prelude::*, solana_program::instruction::Instruction};
3use solana_invoke::invoke;
4
5#[derive(Accounts)]
6pub struct PassToCpi<'info> {
7    #[account(mut)]
8    owner: Signer<'info>,
9    #[account(mut, has_one = owner, close = owner)]
10    chunk_holder: Account<'info, ChunkHolder>,
11    /// CHECK: This is the program that gets invoked.
12    program: AccountInfo<'info>,
13}
14
15pub fn pass_to_cpi(ctx: Context<PassToCpi>) -> Result<()> {
16    let data = ctx.accounts.chunk_holder.join_chunks();
17    let accounts = ctx
18        .remaining_accounts
19        .iter()
20        .map(|x| AccountMeta {
21            pubkey: x.key(),
22            is_signer: x.is_signer,
23            is_writable: x.is_writable,
24        })
25        .collect();
26    let instruction = Instruction {
27        program_id: ctx.accounts.program.key(),
28        accounts,
29        data,
30    };
31    invoke(&instruction, ctx.remaining_accounts)?;
32    Ok(())
33}