Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions basics/cross-program-invocation/steel/hand/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[workspace]
resolver = "2"
members = ["api", "program"]

[workspace.package]
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
homepage = ""
documentation = ""
repository = ""
readme = "./README.md"
keywords = ["solana"]

[workspace.dependencies]
hand-api = { path = "./api", version = "0.1.0" }
bytemuck = "1.14"
num_enum = "0.7"
solana-program = "1.18"
steel = "2.0"
thiserror = "1.0"
lever-api = { path = "../lever/api", version = "0.1.0" }
lever-program = { path = "../lever/program", version = "0.1.0", features = [
"cpi",
] }
28 changes: 28 additions & 0 deletions basics/cross-program-invocation/steel/hand/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Cpi

**Cpi** is a ...

## API
- [`Consts`](api/src/consts.rs) – Program constants.
- [`Error`](api/src/error.rs) – Custom program errors.
- [`Event`](api/src/event.rs) – Custom program events.
- [`Instruction`](api/src/instruction.rs) – Declared instructions.

## Instructions
- [`Add`](program/src/add.rs) – Add ...
- [`Initialize`](program/src/initialize.rs) – Initialize ...

## State
- [`Counter`](api/src/state/counter.rs) – Counter ...

## Get started

Compile your program:
```sh
steel build
```

Run unit and integration tests:
```sh
steel test
```
19 changes: 19 additions & 0 deletions basics/cross-program-invocation/steel/hand/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "hand-api"
description = "API for interacting with the Hand program"
version.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
documentation.workspace = true
repository.workspace = true
readme.workspace = true
keywords.workspace = true

[dependencies]
bytemuck.workspace = true
num_enum.workspace = true
solana-program.workspace = true
steel.workspace = true
thiserror.workspace = true
lever-api.workspace = true
16 changes: 16 additions & 0 deletions basics/cross-program-invocation/steel/hand/api/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use steel::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum HandInstruction {
PullLever = 0,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct PullLever {
// string max length is 64 bytes
pub name: [u8; 64],
}

instruction!(HandInstruction, PullLever);
12 changes: 12 additions & 0 deletions basics/cross-program-invocation/steel/hand/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub mod instruction;
pub mod sdk;

pub mod prelude {
pub use crate::instruction::*;
pub use crate::sdk::*;
}

use steel::*;

// TODO Set program id
declare_id!("2LSt6uKm3YpTogXwEUvSNWLskMdsA6uyNkBFhwkS7sx4");
16 changes: 16 additions & 0 deletions basics/cross-program-invocation/steel/hand/api/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::prelude::*;
use steel::*;

pub fn pull_level(power: Pubkey, name: &str) -> Instruction {
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(power, false),
AccountMeta::new_readonly(lever_api::ID, false),
],
data: PullLever {
name: name.as_bytes().try_into().unwrap(),
}
.to_bytes(),
}
}
29 changes: 29 additions & 0 deletions basics/cross-program-invocation/steel/hand/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "hand",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/*.test.ts",
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
"deploy": "solana program deploy ./program/target/so/account_data_program.so"
},
"keywords": [],
"author": "Leo Pham <hongthaipro@gmail.com>",
"license": "ISC",
"dependencies": {
"@solana/web3.js": "^1.95.4"
},
"devDependencies": {
"@types/mocha": "^10.0.9",
"@types/node": "^22.7.9",
"borsh": "^2.0.0",
"mocha": "^10.7.3",
"solana-bankrun": "^0.4.0",
"ts-mocha": "^10.0.0",
"typescript": "^5.6.3",
"chai": "^4.3.7",
"@types/chai": "^4.3.7"
}
}
Loading