Skip to content

Commit 566eb0e

Browse files
author
adpthegreat
committed
refactored codebase, added poseidon_cross_program_invocation logic
1 parent cab51fa commit 566eb0e

File tree

15 files changed

+161
-80
lines changed

15 files changed

+161
-80
lines changed

basics/cross-program-invocation/poseidon/cross_program_invocation/Anchor.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ resolution = true
55
skip-lint = false
66

77
[programs.localnet]
8-
cross_program_invocation = "D4aA71us8bTcdXeZQpXyXidW2xPugVwUuoXx3b1bnvXa"
8+
hand = "Cd86dtBUzQKYTFtcB8zDxPRUPCtKPocyetWZSnq6PNxv"
9+
lever = "9aM9w7ozrZwXx9bQHbBx6QjWc6F46tdN9ayt86vt9uLL"
910

1011
[registry]
1112
url = "https://api.apr.dev"
@@ -15,4 +16,4 @@ cluster = "Localnet"
1516
wallet = "~/.config/solana/id.json"
1617

1718
[scripts]
18-
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
19+
test = "pnpm run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"

basics/cross-program-invocation/poseidon/cross_program_invocation/migrations/deploy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// single deploy script that's invoked from the CLI, injecting a provider
33
// configured from the workspace's Anchor.toml.
44

5-
const anchor = require("@coral-xyz/anchor");
5+
const anchor = require('@coral-xyz/anchor');
66

7-
module.exports = async function (provider) {
7+
module.exports = async (provider) => {
88
// Configure client to use the provider.
99
anchor.setProvider(provider);
1010

basics/cross-program-invocation/poseidon/cross_program_invocation/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"dependencies": {
99
"@coral-xyz/anchor": "^0.30.1",
10+
"@solana/web3.js": "^1.95.4",
1011
"anchor-bankrun": "^0.5.0",
1112
"solana-bankrun": "^0.4.0"
1213
},

basics/cross-program-invocation/poseidon/cross_program_invocation/pnpm-lock.yaml

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
2-
name = "cross_program_invocation"
2+
name = "hand"
33
version = "0.1.0"
44
description = "Created with Anchor"
55
edition = "2021"
66

77
[lib]
88
crate-type = ["cdylib", "lib"]
9-
name = "cross_program_invocation"
9+
name = "hand"
1010

1111
[features]
1212
default = []
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use anchor_lang::prelude::*;
2+
declare_id!("Cd86dtBUzQKYTFtcB8zDxPRUPCtKPocyetWZSnq6PNxv");
3+
#[program]
4+
pub mod hand {
5+
use super::*;
6+
pub fn initialize(ctx: Context<InitializeContext>) -> Result<()> {
7+
Ok(())
8+
}
9+
pub fn pull_lever(ctx: Context<PullLeverContext>) -> Result<()> {
10+
Ok(())
11+
}
12+
}
13+
#[derive(Accounts)]
14+
pub struct InitializeContext<'info> {
15+
#[account(mut)]
16+
pub power: Signer<'info>,
17+
#[account(mut)]
18+
pub user: Signer<'info>,
19+
}
20+
#[derive(Accounts)]
21+
pub struct PullLeverContext<'info> {
22+
#[account(init, payer = user, space = 8, seeds = [b"hand"], bump)]
23+
pub power: Account<'info, PowerStatus>,
24+
#[account(mut)]
25+
pub user: Signer<'info>,
26+
pub system_program: Program<'info, System>,
27+
}
28+
#[account]
29+
pub struct PowerStatus {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "lever"
3+
version = "0.1.0"
4+
description = "Created with Anchor"
5+
edition = "2021"
6+
7+
[lib]
8+
crate-type = ["cdylib", "lib"]
9+
name = "lever"
10+
11+
[features]
12+
default = []
13+
cpi = ["no-entrypoint"]
14+
no-entrypoint = []
15+
no-idl = []
16+
no-log-ix-name = []
17+
idl-build = ["anchor-lang/idl-build"]
18+
19+
[dependencies]
20+
anchor-lang = "0.30.1"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.bpfel-unknown-unknown.dependencies.std]
2+
features = []
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
use anchor_lang::prelude::*;
2-
declare_id!("D4aA71us8bTcdXeZQpXyXidW2xPugVwUuoXx3b1bnvXa");
2+
declare_id!("9aM9w7ozrZwXx9bQHbBx6QjWc6F46tdN9ayt86vt9uLL");
33
#[program]
4-
pub mod cross_program_invocation {
4+
pub mod lever {
55
use super::*;
66
pub fn initialize(ctx: Context<InitializeContext>) -> Result<()> {
77
Ok(())
88
}
9-
pub fn switch_power(ctx: Context<SwitchPowerContext>, name: String) -> Result<()> {
10-
Ok(())
11-
}
12-
pub fn pull_lever(ctx: Context<PullLeverContext>, name: String) -> Result<()> {
13-
Ok(())
14-
}
159
pub fn initialize_lever(ctx: Context<InitializeLeverContext>) -> Result<()> {
1610
Ok(())
1711
}
@@ -20,25 +14,18 @@ pub mod cross_program_invocation {
2014
}
2115
}
2216
#[derive(Accounts)]
23-
pub struct InitializeContext<'info> {}
24-
#[derive(Accounts)]
25-
pub struct SwitchPowerContext<'info> {}
26-
#[derive(Accounts)]
27-
pub struct PullLeverContext<'info> {
28-
#[account()]
29-
pub lever_program: Account<'info, Lever>,
17+
pub struct InitializeContext<'info> {
18+
#[account(mut)]
19+
pub power: Signer<'info>,
3020
#[account(mut)]
3121
pub user: Signer<'info>,
32-
#[account()]
33-
pub power: Account<'info, PowerStatus>,
34-
pub system_program: Program<'info, System>,
3522
}
3623
#[derive(Accounts)]
3724
pub struct InitializeLeverContext<'info> {
38-
#[account(init, payer = user, space = 8, seeds = [b"power"], bump)]
39-
pub power: Account<'info, PowerStatus>,
4025
#[account(mut)]
4126
pub user: Signer<'info>,
27+
#[account(init, payer = user, space = 8, seeds = [b"lever"], bump)]
28+
pub power: Account<'info, PowerStatus>,
4229
pub system_program: Program<'info, System>,
4330
}
4431
#[derive(Accounts)]
@@ -51,5 +38,3 @@ pub struct SetPowerStatusContext<'info> {
5138
}
5239
#[account]
5340
pub struct PowerStatus {}
54-
#[account]
55-
pub struct Lever {}

0 commit comments

Comments
 (0)