Skip to main content

LazyContext

Struct LazyContext 

Source
pub struct LazyContext { /* private fields */ }
Expand description

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

Accounts are parsed lazily as you call next_account().

Implementations§

Source§

impl LazyContext

Source

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

Parse the next account as a proven signer.

Source

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

Parse the next account as a proven writable.

Source

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

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

Source

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

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

Source

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

Parse the next account as a proven executable program.

Source§

impl LazyContext

Source

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

Instruction data for this invocation.

Source

pub fn program_id(&self) -> &Address

The program ID of this invocation.

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, 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, ProgramError>

Parse the next account and validate it is a signer.

Source

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

Parse the next account and validate it is writable.

Source

pub fn next_payer(&mut self) -> Result<AccountView, 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, 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 without constructing full AccountView values, only doing enough work to find account boundaries.

Source

pub fn drain_remaining(&mut self) -> Result<&[AccountView], 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>

Get an already-parsed account by index.

Returns None if index >= parsed_count.

Trait Implementations§

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.