Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante committed Apr 11, 2021
1 parent 60b1c87 commit 14783f0
Show file tree
Hide file tree
Showing 12 changed files with 989 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/misc/programs/misc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ default = []

[dependencies]
anchor-lang = { path = "../../../../lang" }
misc2 = { path = "../misc2", features = ["cpi"] }
21 changes: 21 additions & 0 deletions examples/misc/programs/misc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! It's not too instructive/coherent by itself, so please see other examples.
use anchor_lang::prelude::*;
use misc2::misc2::MyState;
use misc2::Auth;

#[program]
pub mod misc {
Expand Down Expand Up @@ -29,6 +31,15 @@ pub mod misc {
pub fn test_executable(ctx: Context<TestExecutable>) -> ProgramResult {
Ok(())
}

pub fn test_state_cpi(ctx: Context<TestStateCpi>, data: u64) -> ProgramResult {
let cpi_program = ctx.accounts.misc2_program.clone();
let cpi_accounts = Auth {
authority: ctx.accounts.authority.clone(),
};
let ctx = ctx.accounts.cpi_state.context(cpi_program, cpi_accounts);
misc2::cpi::state::set_data(ctx, data)
}
}

#[derive(Accounts)]
Expand All @@ -47,6 +58,16 @@ pub struct TestExecutable<'info> {
program: AccountInfo<'info>,
}

#[derive(Accounts)]
pub struct TestStateCpi<'info> {
#[account(signer)]
authority: AccountInfo<'info>,
// #[account(state = misc2_program)]
cpi_state: CpiState<'info, MyState>,
#[account(executable)]
misc2_program: AccountInfo<'info>,
}

#[account]
pub struct Data {
udata: u128,
Expand Down
18 changes: 18 additions & 0 deletions examples/misc/programs/misc2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "misc2"
version = "0.1.0"
description = "Created with Anchor"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "misc2"

[features]
no-entrypoint = []
no-idl = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = { path = "../../../../lang" }
2 changes: 2 additions & 0 deletions examples/misc/programs/misc2/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
Loading

0 comments on commit 14783f0

Please sign in to comment.