Skip to main content

LazyContext

Struct LazyContext 

Source
pub struct LazyContext<'info> { /* private fields */ }
Expand description

Pre-parsed header from the BPF input buffer: a cursor positioned at the first account, plus enough state to locate instruction data + program ID on demand.

Accounts are parsed lazily as you call next_account(). Instruction data and program ID are found by a memoized skip-walk the first time they are requested (see LazyContext::instruction_data).

Implementations§

Source§

impl<'info> LazyContext<'info>

Source

pub fn next_validated_signer( &mut self, ) -> Result<SignerView<'info>, ProgramError>

Parse the next account as a proven signer.

Source

pub fn next_validated_writable( &mut self, ) -> Result<WritableView<'info>, ProgramError>

Parse the next account as a proven writable.

Source

pub fn next_validated_mutable( &mut self, ) -> Result<MutableView<'info>, ProgramError>

Parse the next account as a proven mutable (signer + writable).

Source

pub fn next_validated_owned( &mut self, owner: &Address, ) -> Result<OwnedView<'info>, ProgramError>

Parse the next account as a proven program-owned account.

Source

pub fn next_validated_executable( &mut self, ) -> Result<ExecutableView<'info>, ProgramError>

Parse the next account as a proven executable program.

Source§

impl<'info> LazyContext<'info>

Source

pub fn instruction_data(&self) -> &[u8]

Instruction data for this invocation.

Available at any time, including before any account is consumed. The first call (or the first program_id() call) runs the memoized skip-walk to the instruction tail; later calls are cache reads.

Source

pub fn program_id(&self) -> &Address

The program ID of this invocation.

Available at any time (see instruction_data).

Source

pub fn total_accounts(&self) -> usize

Number of accounts declared in the transaction.

Source

pub fn parsed_count(&self) -> usize

Number of accounts parsed so far.

Source

pub fn remaining(&self) -> usize

Number of accounts remaining to be parsed.

Source

pub fn next_account(&mut self) -> Result<AccountView<'info>, ProgramError>

Parse and return the next account from the input buffer.

Each call advances the internal cursor by one account. Returns Err(NotEnoughAccountKeys) if all accounts have been consumed.

Source

pub fn next_signer(&mut self) -> Result<AccountView<'info>, ProgramError>

Parse the next account and validate it is a signer.

Source

pub fn next_writable(&mut self) -> Result<AccountView<'info>, ProgramError>

Parse the next account and validate it is writable.

Source

pub fn next_payer(&mut self) -> Result<AccountView<'info>, ProgramError>

Parse the next account and validate it is a writable signer (payer).

Source

pub fn next_owned_by( &mut self, program: &Address, ) -> Result<AccountView<'info>, ProgramError>

Parse the next account and validate it is owned by program.

Source

pub fn skip(&mut self, n: usize) -> Result<(), ProgramError>

Skip n accounts without returning them.

Advances the cursor through the raw buffer, resolving each skipped slot so get() and drain_remaining() stay consistent with parsed_count. Constructing an AccountView is a single pointer wrap, so this is materially the same cost as advancing past the record; the duplicate well-formedness trap fires here too.

Source

pub fn drain_remaining(&mut self) -> Result<&[AccountView<'info>], ProgramError>

Collect all remaining accounts into a slice of the internal buffer.

Parses all remaining accounts eagerly and returns them as a slice. After this call, remaining() returns 0.

Source

pub fn get(&self, index: usize) -> Option<&AccountView<'info>>

Get an already-parsed account by index.

Returns None if index >= parsed_count.

Auto Trait Implementations§

§

impl<'info> !Freeze for LazyContext<'info>

§

impl<'info> !RefUnwindSafe for LazyContext<'info>

§

impl<'info> !Send for LazyContext<'info>

§

impl<'info> !Sync for LazyContext<'info>

§

impl<'info> Unpin for LazyContext<'info>

§

impl<'info> UnsafeUnpin for LazyContext<'info>

§

impl<'info> UnwindSafe for LazyContext<'info>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.