| Crates.io | pda_pinocchio_mapping |
| lib.rs | pda_pinocchio_mapping |
| version | 0.1.0 |
| created_at | 2025-12-10 14:11:23.572173+00 |
| updated_at | 2025-12-10 14:11:23.572173+00 |
| description | On-chain mapping utility for Solana / Pinocchio programs. |
| homepage | |
| repository | https://github.com/beber89/pda_pinocchio_mapping/tree/main/pda_pinocchio_mapping |
| max_upload_size | |
| id | 1978110 |
| size | 17,971 |
A lightweight, no_std utility crate for creating a solidity-like mapping for pinocchio programs.
This library provides a simple abstraction called Mapping, which allows programs to create and overwrite PDA-derived accounts.
Add to your Cargo.toml:
[dependencies]
pda-pinocchio-mapping = "0.x"
This crate depends only on:
pinocchiopinocchio_systempinocchio_pubkeybytemuckand remains fully no_std.
BumpySupplies the bump used in PDA derivation. Your struct type should be implementing this trait (i.e. contains bump value).
pub trait Bumpy {
fn bump(&self) -> u8 {self.bump};
}
Mapping AbstractionA Mapping is created by convenience macro:
let mapping = mapping!(b"positions", payer);
It stores and retrieves values associated with:
Pubkey)T : Pod + Bumpy)PDA seeds are constructed using:
[name, key, [bump]]
This is abstracted behind Mapping.
The mapping! macro:
crate::ID existsMapping::new(&crate::ID, name, payer)createCreates a PDA for the first time and initializes it to value.
mapping.create(&user_key, value, account_info)?;
Fails if the account already exists.
setCreates or overwrites a PDA.
mapping.set(&user_key, value, account_info)?;
updateOverwrites only if the PDA exists.
mapping.update(&user_key, new_value, account_info)?;
Fails if the PDA is uninitialized.
#[repr(C)]
#[derive(Clone, Copy, Pod, Zeroable)]
pub struct Position {
pub amount: u64,
pub bump: u8,
}
impl Bumpy for Position {
fn bump(&self) -> u8 { self.bump }
}
let [position_account, accounts @..] = accounts;
let position = Position { amount: 100, bump };
let mapping = mapping!(b"positions", payer);
mapping.set(&user.pubkey(), position, position_account)?;
This library ensures:
PDA account must match the derived address
Account data size must equal core::mem::size_of<T>()
Only the rightful program owner may update stored values
PDA creation requires amount of rent-exempt lamports