Skip to content

Commit ecf7486

Browse files
authored
add basics/cross-program-invocation/steel (#248)
1 parent a667981 commit ecf7486

File tree

29 files changed

+591
-0
lines changed

29 files changed

+591
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Cross Program Invocation steel example
2+
3+
### Programs
4+
5+
- [Hand](./hand/README.md)
6+
- [Lever](./lever/README.md)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
test-ledger
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[workspace]
2+
resolver = "2"
3+
members = ["api", "program"]
4+
5+
[workspace.package]
6+
version = "0.1.0"
7+
edition = "2021"
8+
license = "Apache-2.0"
9+
homepage = ""
10+
documentation = ""
11+
repository = ""
12+
readme = "./README.md"
13+
keywords = ["solana"]
14+
15+
[workspace.dependencies]
16+
hand-api = { path = "./api", version = "0.1.0" }
17+
lever-api = { path = "../lever/api", version = "0.1.0" }
18+
lever-program = { path = "../lever/program", version = "0.1.0", features = [
19+
"cpi",
20+
] }
21+
bytemuck = "1.14"
22+
num_enum = "0.7"
23+
solana-program = "1.18"
24+
steel = "2.0"
25+
thiserror = "1.0"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Hand
2+
3+
**Hand** is a ...
4+
5+
## API
6+
- [`Instruction`](api/src/instruction.rs) – Declared instructions.
7+
8+
## Instructions
9+
- [`PullLever`](program/src/pull_lever.rs) – Pull Lever ...
10+
11+
## Get started
12+
13+
Compile your program:
14+
```sh
15+
steel build
16+
```
17+
18+
Run unit and integration tests:
19+
```sh
20+
steel test
21+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "hand-api"
3+
description = "API for interacting with the Hand program"
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
documentation.workspace = true
9+
repository.workspace = true
10+
readme.workspace = true
11+
keywords.workspace = true
12+
13+
[dependencies]
14+
bytemuck.workspace = true
15+
num_enum.workspace = true
16+
solana-program.workspace = true
17+
steel.workspace = true
18+
thiserror.workspace = true
19+
lever-api.workspace = true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use steel::*;
2+
3+
#[repr(u8)]
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5+
pub enum HandInstruction {
6+
PullLever = 0,
7+
}
8+
9+
#[repr(C)]
10+
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
11+
pub struct PullLever {
12+
pub name: [u8; 32],
13+
}
14+
15+
instruction!(HandInstruction, PullLever);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub mod instruction;
2+
pub mod sdk;
3+
4+
pub mod prelude {
5+
pub use crate::instruction::*;
6+
pub use crate::sdk::*;
7+
}
8+
9+
use steel::*;
10+
11+
// TODO Set program id
12+
declare_id!("Bi5N7SUQhpGknVcqPTzdFFVueQoxoUu8YTLz75J6fT8A");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use lever_api::prelude::*;
2+
use steel::*;
3+
4+
use crate::prelude::*;
5+
6+
pub fn pull_lever(power_account: Pubkey, name: &str) -> Instruction {
7+
// pub fn pull_lever(power_account: Pubkey, lever_program: Pubkey, name: &str) -> Instruction {
8+
Instruction {
9+
program_id: crate::ID,
10+
accounts: vec![
11+
AccountMeta::new(power_account, false),
12+
// AccountMeta::new(lever_program, false),
13+
AccountMeta::new_readonly(lever_api::ID, false),
14+
],
15+
data: PullLever {
16+
name: str_to_bytes(name),
17+
}
18+
.to_bytes(),
19+
}
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "hand-program"
3+
description = ""
4+
version.workspace = true
5+
edition.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
documentation.workspace = true
9+
repository.workspace = true
10+
readme.workspace = true
11+
keywords.workspace = true
12+
13+
[lib]
14+
crate-type = ["cdylib", "lib"]
15+
16+
[dependencies]
17+
hand-api.workspace = true
18+
lever-api.workspace = true
19+
lever-program.workspace = true
20+
solana-program.workspace = true
21+
steel.workspace = true
22+
23+
[dev-dependencies]
24+
base64 = "0.21"
25+
rand = "0.8.5"
26+
solana-program-test = "1.18"
27+
solana-sdk = "1.18"
28+
tokio = { version = "1.35", features = ["full"] }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
mod pull_lever;
2+
3+
use pull_lever::*;
4+
5+
use hand_api::prelude::*;
6+
use steel::*;
7+
8+
pub fn process_instruction(
9+
program_id: &Pubkey,
10+
accounts: &[AccountInfo],
11+
data: &[u8],
12+
) -> ProgramResult {
13+
let (ix, data) = parse_instruction(&hand_api::ID, program_id, data)?;
14+
15+
match ix {
16+
HandInstruction::PullLever => process_pull_lever(accounts, data)?,
17+
}
18+
19+
Ok(())
20+
}
21+
22+
entrypoint!(process_instruction);

0 commit comments

Comments
 (0)