hopper_native/raw_account.rs
1//! Raw account header for the Solana loader input buffer.
2//!
3//! `RuntimeAccount` is the substrate-level truth Hopper Native uses when it
4//! reads the loader's account array. Duplicate-account tracking lives in
5//! [`crate::raw_input`]; this type models only the canonical backing account
6//! record that duplicates point at.
7
8use crate::address::Address;
9
10/// Raw C-layout struct matching the Solana BPF account input format.
11///
12/// Each non-duplicate account in the entrypoint input buffer begins with this
13/// header, immediately followed by `data_len` bytes of account data.
14///
15/// The first byte occupies the loader's duplicate marker slot. Hopper Native
16/// reuses that byte as `borrow_state`, which is valid because canonical
17/// accounts enter the program with the `0xFF` marker and Hopper uses the same
18/// value to mean `NOT_BORROWED`.
19#[repr(C)]
20#[cfg_attr(feature = "copy", derive(Copy))]
21#[derive(Clone, Default)]
22pub struct RuntimeAccount {
23 /// Borrow tracking state (repurposed from the loader duplicate marker).
24 ///
25 /// Duplicate-account relationships are tracked in `raw_input`; once a
26 /// canonical account is identified, this byte becomes Hopper's borrow
27 /// state for that canonical record.
28 pub borrow_state: u8,
29 /// 1 if transaction signer, 0 otherwise.
30 pub is_signer: u8,
31 /// 1 if writable, 0 otherwise.
32 pub is_writable: u8,
33 /// 1 if executable, 0 otherwise.
34 pub executable: u8,
35 /// Original account data length, stored in the ABI's four padding bytes.
36 ///
37 /// The field name is retained for source compatibility with Hopper 0.3.0;
38 /// it is an immutable resize baseline, not a cumulative delta. Entrypoint
39 /// parsing initializes it before exposing an [`AccountView`](crate::AccountView).
40 pub resize_delta: u32,
41 /// Account public key (32 bytes).
42 pub address: Address,
43 /// Owning program (32 bytes).
44 pub owner: Address,
45 /// Lamport balance.
46 pub lamports: u64,
47 /// Length of account data following this struct.
48 pub data_len: u64,
49 // Account data bytes follow immediately in memory.
50}
51
52impl RuntimeAccount {
53 /// Size of the raw loader header before account data begins.
54 pub const SIZE: usize = core::mem::size_of::<Self>();
55}
56
57const _: () = assert!(core::mem::size_of::<RuntimeAccount>() == 88);