Skip to main content

init_account

Macro init_account 

Source
macro_rules! init_account {
    ($payer:expr, $account:expr, $program_id:expr, $Layout:ty) => { ... };
}
Expand description

Initialize a Jiminy account: CPI CreateAccount, zero-init, write header.

Owns the full creation path so developers cannot forget zero_init or layout_id. Returns Ok(()) after creating a fully-initialized account with a valid 16-byte Jiminy header and zero-filled body.

Follow with Layout::load_checked_mut() to get a mutable overlay for setting field values.

Note: Requires pinocchio_system in scope. This macro is re-exported by the root jiminy crate which provides it automatically.

init_account!(payer, account, program_id, Vault)?;

// Now set fields via overlay:
let mut data = account.try_borrow_mut()?;
let vault = Vault::overlay_mut(&mut data)?;
vault.balance = 0;
vault.authority = *authority;

Expands to:

  1. rent_exempt_min(Layout::LEN) for lamports
  2. CPI CreateAccount with correct space and owner
  3. zero_init the full data slice
  4. write_header with disc + version + layout_id