pinocchio-util
Overview
pinocchio-util is crate designed to make your life just a little bit easier when building pinocchio programs.
While only being around for a relatively short time, Pinocchio has quickly become a go-to library for building efficient Solana programs. It strikes an effective balance between low-level control and developer ergonomics, which is one of the reasons I love it.
That being said, I've noticed a variety of recurring patterns between my own programs, and programs built by others. This crate encompasses some of the tools I've used over time to make implementing those patterns a bit easier.
Installation
Install this crate with the following command:
or add this to your Cargo.toml:
= "0.0.1"
Usage
Load an immutable reference to an account's data as an arbitrary type
let account_data = ?;
Load a mutable reference to an account's data as an arbitrary type:
let mut account_data = ?;
Extract an account's discriminator:
/// Defaults to first 8 bytes like classic Anchor does
let discriminator = load_discriminator.unwrap;
/// You can also define an arbitrary length, which some programs
/// >= Anchor 0.30.0 do to save bytes
let discriminator = load_discriminator.unwrap;
This crate also exposes various traits like DataLen, AccountUpdates, Validate, and Context. These are useful in their own right, but are best used with the derive feature outlined below.
Derive Macros
Enable the derive feature to leverage various procedural macros:
= { = "0.0.1", = ["derive"] }
Now that you've enabled them, you can add them to the various structs in your program:
// ...
let ctx = build
.map_err?;