Skip to content

Instantly share code, notes, and snippets.

@buffalojoec
buffalojoec / bytemuck_bench.rs
Created May 9, 2025 08:36
Interpreting account data with bytemuck is cheap
use {
bytemuck::{Pod, Zeroable},
pinocchio::{
account_info::AccountInfo, program_entrypoint,
pubkey::Pubkey, ProgramResult, program_error::ProgramError,
},
};
#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
@buffalojoec
buffalojoec / transaction_roles.rs
Created May 2, 2025 03:44
Did you know Solana account roles (signer, writable) are transaction-wide?
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg, pubkey::Pubkey};
solana_program::entrypoint!(process);
fn process(_program_id: &Pubkey, accounts: &[AccountInfo], _input: &[u8]) -> ProgramResult {
let account = accounts.first().unwrap();
msg!("KEY: {}", account.key);
msg!("IS_SIGNER: {}", account.is_signer);
msg!("IS_WRITABLE: {}", account.is_writable);
Ok(())
@buffalojoec
buffalojoec / index_v2.rs
Last active May 16, 2024 09:17
Program cache index v2 design concept.
//! Program cache index v2 implementation.
//!
//! Consider a fork graph.
//!
//! ```
//!
//! 0 <- root
//! / \
//! 10 5
//! | |
@buffalojoec
buffalojoec / call_sites.txt
Last active March 19, 2024 13:45
Runtime `additional_builtins` call sites
runtime::bank::new_from_fields()
|
|-- runtime::serde_snapshot::reconstruct_bank_from_fields()
|
|-- runtime::serde_snapshot::bank_from_streams()
|
|-- runtime::snapshot_bank_utils::rebuild_bank_from_unarchived_snapshots()
| |
| |-- runtime::snapshot_bank_utils::bank_from_snapshot_archives()
| |
@buffalojoec
buffalojoec / lib.rs
Last active August 16, 2023 18:36
Sharing closure-fed library functions across async and sync
/// Scenario #1:
mod not_fut{
/// A lib function designed to take a closure that returns a `String`
fn lib_function<F>(get_account_data_fn: F) -> String
where
F: Fn(u8) -> String,
{
let account_data = get_account_data_fn(42);
println!("Account data: {}", account_data);
account_data