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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use anchor_lang::{Accounts, CpiContext};
use solana_program::account_info::AccountInfo;
use solana_program::declare_id;
use solana_program::entrypoint::ProgramResult;
use solana_program::instruction::{AccountMeta, Instruction};
use solana_program::program;
declare_id!("DynWy94wrWp5RimU49creYMQ5py3Up8BBNS4VA73VCpi");
pub fn ret<'a, 'b, 'c, 'info>(
ctx: CpiContext<'a, 'b, 'c, 'info, Ret<'info>>,
data: Vec<u8>,
) -> ProgramResult {
let instruction = Instruction {
program_id: *ctx.program.key,
accounts: vec![AccountMeta::new(*ctx.accounts.buffer.key, false)],
data,
};
let mut accounts = vec![ctx.accounts.buffer];
accounts.push(ctx.program.clone());
program::invoke(&instruction, &accounts)
}
#[derive(Accounts)]
pub struct Ret<'info> {
#[account(mut)]
pub buffer: AccountInfo<'info>,
}
#[derive(Accounts)]
pub struct Shmem<'info> {
#[account(mut, "shmem.owner == shmem_program.key")]
pub shmem: AccountInfo<'info>,
#[account("shmem_program.key == &ID")]
pub shmem_program: AccountInfo<'info>,
}