Skip to content

Commit 203b246

Browse files
authored
add pinocchio repository-layout example (#582)
* add pinocchio repository-layout example Ports the carnival program from anchor/native to a Pinocchio variant mirroring the same module layout (lib/processor/instructions/state/error). - #![no_std] crate using pinocchio + pinocchio-log - Instruction data wire format matches the native borsh layout, so the bankrun test reuses the same encoding - Static const tables replace heap-allocated Vec<FoodStand|Game|Ride> * add pnpm-lock.yaml for pinocchio repository-layout example Generated via pnpm install; required for CI's pnpm install --frozen-lockfile. * style: fix rustfmt in pinocchio repository-layout example
1 parent 93dc0a0 commit 203b246

20 files changed

Lines changed: 1903 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ members = [
4343
"basics/favorites/native/program",
4444
"basics/favorites/pinocchio/program",
4545
"basics/repository-layout/native/program",
46+
"basics/repository-layout/pinocchio/program",
4647
"basics/repository-layout/anchor/programs/*",
4748
"basics/transfer-sol/native/program",
4849
"basics/transfer-sol/pinocchio/program",

basics/repository-layout/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ This is the typical layout for a Solana program as it grows in size and begins t
44

55
> Note: You can structure your Rust `src` folder however you wish - provided you follow Cargo's repository structure standards. You don't have to follow this pattern, but it's here so you can recognize other programs, too.
66
7-
You can see that the structure for a `native` repository is very similar to that of the `anchor` repository. The only difference is the inclusion of a `processor.rs` in the `native` setup - one of the many things Anchor abstracts away for you!
7+
You can see that the structure for a `native` repository is very similar to that of the `anchor` repository. The only difference is the inclusion of a `processor.rs` in the `native` setup - one of the many things Anchor abstracts away for you!
8+
9+
The `pinocchio` variant follows the same layout as `native` (with a `processor.rs`), but uses the lightweight [Pinocchio](https://github.com/anza-xyz/pinocchio) SDK in a `#![no_std]` crate and emits logs via `pinocchio-log` instead of `msg!`. The instruction data wire format matches the `native` version, so the same Borsh-encoded layout in the TypeScript tests works for both.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# This script is for quick building & deploying of the program.
4+
# It also serves as a reference for the commands used for building & deploying Solana programs.
5+
# Run this bad boy with "bash cicd.sh" or "./cicd.sh"
6+
7+
cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so
8+
solana program deploy ./program/target/so/program.so
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "pnpm ts-mocha -p ./tsconfig.json -t 1000000 ./tests/test.ts",
5+
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
6+
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
7+
"deploy": "solana program deploy ./program/target/so/program.so"
8+
},
9+
"dependencies": {
10+
"@solana/web3.js": "^1.98.4",
11+
"borsh": "^2.0.0"
12+
},
13+
"devDependencies": {
14+
"@types/bn.js": "^5.1.0",
15+
"@types/chai": "^4.3.1",
16+
"@types/mocha": "^9.1.1",
17+
"chai": "^4.3.4",
18+
"mocha": "^9.0.3",
19+
"solana-bankrun": "^0.3.0",
20+
"ts-mocha": "^10.0.0",
21+
"typescript": "^4.3.5"
22+
}
23+
}

0 commit comments

Comments
 (0)