Skip to content

Commit 4a9a00b

Browse files
authored
Update Pinocchio examples to 0.9.1 (#22)
1 parent ed96fc7 commit 4a9a00b

File tree

6 files changed

+34
-23
lines changed

6 files changed

+34
-23
lines changed

Cargo.lock

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

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ a little-endian u64 in instruction data.
170170
| Zig | 38 |
171171
| C | 104 |
172172
| Assembly | 30 |
173-
| Rust (pinocchio) | 32 |
173+
| Rust (pinocchio) | 28 |
174174

175175
This one starts to get interesting since it requires parsing the instruction
176176
input. Since the assembly version knows exactly where to find everything, it can
177-
be hyper-optimized. The pinocchio version performs very closely to the assembly
177+
be hyper-optimized. The pinocchio version performs better than the assembly
178178
implementation!
179179

180180
### CPI
@@ -188,7 +188,7 @@ address and `invoke_signed` to CPI to the system program.
188188
| Rust | 3698 | 1198 |
189189
| Zig | 2809 | 309 |
190190
| C | 3122 | 622 |
191-
| Rust (pinocchio) | 2816 | 316 |
191+
| Rust (pinocchio) | 2802 | 302 |
192192

193193
Note: `create_program_address` consumes 1500 CUs, and `invoke` consumes 1000, so
194194
we can subtract 2500 CUs from each program to see the actual cost of the program

cpi/pinocchio/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version = "1.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
pinocchio = "0.6"
8-
pinocchio-system = "0.2"
7+
pinocchio = "0.9.1"
8+
pinocchio-system = "0.3.0"
99

1010
[lib]
1111
crate-type = ["cdylib", "lib"]

cpi/pinocchio/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#![deny(missing_docs)]
33

44
use pinocchio::{
5-
instruction::{Account, AccountMeta, Instruction},
5+
instruction::{Account, AccountMeta, Instruction, Signer},
66
lazy_entrypoint::InstructionContext,
77
program::invoke_signed_unchecked,
88
program_error::ProgramError,
99
pubkey::create_program_address,
10-
signer, ProgramResult,
10+
seeds, ProgramResult,
1111
};
1212

1313
// Since this is a single instruction program, we use the "lazy" variation
1414
// of the entrypoint.
15-
pinocchio::lazy_entrypoint!(process_instruction);
15+
pinocchio::lazy_program_entrypoint!(process_instruction);
1616

1717
/// Amount of bytes of account data to allocate
1818
pub const SIZE: usize = 42;
@@ -31,7 +31,8 @@ fn process_instruction(mut context: InstructionContext) -> ProgramResult {
3131

3232
// Again, don't need to check that all accounts have been consumed, we know
3333
// we have exactly 2 accounts.
34-
let (instruction_data, program_id) = unsafe { context.instruction_data_unchecked() };
34+
let instruction_data = unsafe { context.instruction_data_unchecked() };
35+
let program_id = unsafe { context.program_id_unchecked() };
3536

3637
let expected_allocated_key =
3738
create_program_address(&[b"You pass butter", &[instruction_data[0]]], program_id)?;
@@ -57,7 +58,10 @@ fn process_instruction(mut context: InstructionContext) -> ProgramResult {
5758
invoke_signed_unchecked(
5859
&instruction,
5960
&[Account::from(&allocated_info)],
60-
&[signer!(b"You pass butter", &[instruction_data[0]])],
61+
&[Signer::from(&seeds!(
62+
b"You pass butter",
63+
&[instruction_data[0]]
64+
))],
6165
)
6266
};
6367

transfer-lamports/pinocchio/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
no-entrypoint = []
88

99
[dependencies]
10-
pinocchio = "0.6"
10+
pinocchio = "0.9.1"
1111

1212
[lib]
1313
crate-type = ["cdylib", "lib"]

transfer-lamports/pinocchio/src/entrypoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use pinocchio::{
1010

1111
// Since this is a single instruction program, we use the "lazy" variation
1212
// of the entrypoint.
13-
pinocchio::lazy_entrypoint!(process_instruction);
13+
pinocchio::lazy_program_entrypoint!(process_instruction);
1414

1515
#[inline]
1616
fn process_instruction(mut context: InstructionContext) -> ProgramResult {
@@ -38,7 +38,7 @@ fn process_instruction(mut context: InstructionContext) -> ProgramResult {
3838
// accounts are different, so we can safely ignore the case when the account is
3939
// duplicated.
4040
if let MaybeAccount::Account(destination_info) = context.next_account_unchecked() {
41-
let (instruction_data, _) = context.instruction_data_unchecked();
41+
let instruction_data = context.instruction_data_unchecked();
4242
let transfer_amount = u64::from_le_bytes(instruction_data.try_into().unwrap());
4343
// withdraw five lamports
4444
*source_info.borrow_mut_lamports_unchecked() -= transfer_amount;

0 commit comments

Comments
 (0)