Skip to content

Commit 290da30

Browse files
committed
add favorites pinocchio example
1 parent 020ebe7 commit 290da30

File tree

22 files changed

+1719
-36
lines changed

22 files changed

+1719
-36
lines changed

Cargo.lock

Lines changed: 16 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
@@ -33,6 +33,7 @@ members = [
3333
"basics/rent/pinocchio/program",
3434
"basics/rent/anchor/programs/*",
3535
"basics/favorites/native/program",
36+
"basics/favorites/pinocchio/program",
3637
"basics/repository-layout/native/program",
3738
"basics/repository-layout/anchor/programs/*",
3839
"basics/transfer-sol/native/program",

basics/account-data/pinocchio/program/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#![no_std]
2-
#![allow(deprecated)]
32

43
use pinocchio::{
54
account_info::AccountInfo,
65
entrypoint, nostd_panic_handler,
76
program_error::ProgramError,
87
pubkey::Pubkey,
9-
sysvars::rent::{
10-
Rent, DEFAULT_BURN_PERCENT, DEFAULT_EXEMPTION_THRESHOLD, DEFAULT_LAMPORTS_PER_BYTE_YEAR,
11-
},
8+
sysvars::{rent::Rent, Sysvar},
129
ProgramResult,
1310
};
1411
use pinocchio_system::instructions::CreateAccount;
@@ -63,11 +60,7 @@ fn process_create(
6360
return Err(ProgramError::InvalidInstructionData);
6461
}
6562

66-
let rent = Rent {
67-
lamports_per_byte_year: DEFAULT_LAMPORTS_PER_BYTE_YEAR,
68-
exemption_threshold: DEFAULT_EXEMPTION_THRESHOLD,
69-
burn_percent: DEFAULT_BURN_PERCENT,
70-
};
63+
let rent = Rent::get()?;
7164

7265
let account_span = AddressInfo::LEN;
7366
let lamports_required = rent.minimum_balance(account_span);

basics/checking-accounts/pinocchio/program/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![allow(deprecated)]
32

43
use pinocchio::{
54
account_info::AccountInfo, entrypoint, nostd_panic_handler, program_error::ProgramError,

basics/close-account/pinocchio/program/src/lib.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![allow(deprecated)]
32

43
use pinocchio::{
54
account_info::AccountInfo,
@@ -8,9 +7,7 @@ use pinocchio::{
87
nostd_panic_handler,
98
program_error::ProgramError,
109
pubkey::Pubkey,
11-
sysvars::rent::{
12-
Rent, DEFAULT_BURN_PERCENT, DEFAULT_EXEMPTION_THRESHOLD, DEFAULT_LAMPORTS_PER_BYTE_YEAR,
13-
},
10+
sysvars::{rent::Rent, Sysvar},
1411
ProgramResult,
1512
};
1613
use pinocchio_system::instructions::CreateAccount;
@@ -51,11 +48,7 @@ fn process_user(
5148
return Err(ProgramError::NotEnoughAccountKeys);
5249
};
5350

54-
let rent = Rent {
55-
lamports_per_byte_year: DEFAULT_LAMPORTS_PER_BYTE_YEAR,
56-
exemption_threshold: DEFAULT_EXEMPTION_THRESHOLD,
57-
burn_percent: DEFAULT_BURN_PERCENT,
58-
};
51+
let rent = Rent::get()?;
5952

6053
let account_span = User::LEN;
6154
let lamports_required = rent.minimum_balance(account_span);
@@ -93,11 +86,7 @@ fn process_close(accounts: &[AccountInfo]) -> ProgramResult {
9386
return Err(ProgramError::NotEnoughAccountKeys);
9487
};
9588

96-
let rent = Rent {
97-
lamports_per_byte_year: DEFAULT_LAMPORTS_PER_BYTE_YEAR,
98-
exemption_threshold: DEFAULT_EXEMPTION_THRESHOLD,
99-
burn_percent: DEFAULT_BURN_PERCENT,
100-
};
89+
let rent = Rent::get()?;
10190

10291
let account_span = 0usize;
10392
let lamports_required = rent.minimum_balance(account_span);

basics/counter/pinocchio/program/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![allow(deprecated)]
32

43
use pinocchio::{
54
account_info::AccountInfo, nostd_panic_handler, program_error::ProgramError, pubkey::Pubkey,

basics/create-account/pinocchio/program/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![no_std]
2-
#![allow(deprecated)]
32

43
use pinocchio::{
54
account_info::AccountInfo, entrypoint, nostd_panic_handler, program_error::ProgramError,

basics/favorites/pinocchio/cicd.sh

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 --bpf-out-dir=./program/target/so
8+
solana program deploy ./program/target/so/program.so
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.47.3",
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+
"@types/node": "^22.8.1",
18+
"chai": "^4.3.4",
19+
"mocha": "^9.0.3",
20+
"solana-bankrun": "^0.3.0",
21+
"ts-mocha": "^10.0.0",
22+
"typescript": "^4.3.5"
23+
}
24+
}

0 commit comments

Comments
 (0)