Expand description
Cross-program account lenses – read foreign fields by offset.
When Program A wants to read a field from Program B’s account, every existing framework requires importing Program B’s full type definition at compile time. This creates tight coupling between programs.
Hopper lenses solve this: read specific fields from foreign account data by byte offset and type, no compile-time dependency required. This enables composability patterns that were previously impossible without shared crate dependencies.
§Safety
Lenses bypass type-level layout guarantees. The caller must know the correct offset and type for the target field. Incorrect offsets will read garbage data (but never cause UB, since all reads go through bounds-checked accessors).
§Usage
ⓘ
use hopper_native::lens;
// Read a 32-byte address at offset 10 from a foreign program's account
// (skip 10-byte Hopper header: disc + version + layout_id).
let authority = lens::read_address(oracle_account, 10)?;
// Read a u64 price at offset 42.
let price = lens::read_le_u64(oracle_account, 42)?;
// Read a typed struct at an offset.
let data: &MyPodType = lens::read_field::<MyPodType>(account, 10)?;Functions§
- field_
eq - Compare a field in account data against an expected value without copying.
- read_
address - Read a 32-byte address from account data.
- read_
bool - Read a boolean from account data (0 = false, nonzero = true).
- read_
bytes - Read a byte slice from account data.
- read_
field - Read a
Projectablefield from account data at the given byte offset. - read_
field_ pod - Read a
Podfield from account data at the given byte offset. - read_
le_ u16 - Read a little-endian u16 from account data.
- read_
le_ u32 - Read a little-endian u32 from account data.
- read_
le_ u64 - Read a little-endian u64 from account data.
- read_u8
- Read a single byte from account data.