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>
impl<'info> LazyContext<'info>
Sourcepub fn next_validated_signer(
&mut self,
) -> Result<SignerView<'info>, ProgramError>
pub fn next_validated_signer( &mut self, ) -> Result<SignerView<'info>, ProgramError>
Parse the next account as a proven signer.
Sourcepub fn next_validated_writable(
&mut self,
) -> Result<WritableView<'info>, ProgramError>
pub fn next_validated_writable( &mut self, ) -> Result<WritableView<'info>, ProgramError>
Parse the next account as a proven writable.
Sourcepub fn next_validated_mutable(
&mut self,
) -> Result<MutableView<'info>, ProgramError>
pub fn next_validated_mutable( &mut self, ) -> Result<MutableView<'info>, ProgramError>
Parse the next account as a proven mutable (signer + writable).
Sourcepub fn next_validated_owned(
&mut self,
owner: &Address,
) -> Result<OwnedView<'info>, ProgramError>
pub fn next_validated_owned( &mut self, owner: &Address, ) -> Result<OwnedView<'info>, ProgramError>
Parse the next account as a proven program-owned account.
Sourcepub fn next_validated_executable(
&mut self,
) -> Result<ExecutableView<'info>, ProgramError>
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>
impl<'info> LazyContext<'info>
Sourcepub fn instruction_data(&self) -> &[u8]
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.
Sourcepub fn program_id(&self) -> &Address
pub fn program_id(&self) -> &Address
The program ID of this invocation.
Available at any time (see instruction_data).
Sourcepub fn total_accounts(&self) -> usize
pub fn total_accounts(&self) -> usize
Number of accounts declared in the transaction.
Sourcepub fn parsed_count(&self) -> usize
pub fn parsed_count(&self) -> usize
Number of accounts parsed so far.
Sourcepub fn next_account(&mut self) -> Result<AccountView<'info>, ProgramError>
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.
Sourcepub fn next_signer(&mut self) -> Result<AccountView<'info>, ProgramError>
pub fn next_signer(&mut self) -> Result<AccountView<'info>, ProgramError>
Parse the next account and validate it is a signer.
Sourcepub fn next_writable(&mut self) -> Result<AccountView<'info>, ProgramError>
pub fn next_writable(&mut self) -> Result<AccountView<'info>, ProgramError>
Parse the next account and validate it is writable.
Sourcepub fn next_payer(&mut self) -> Result<AccountView<'info>, ProgramError>
pub fn next_payer(&mut self) -> Result<AccountView<'info>, ProgramError>
Parse the next account and validate it is a writable signer (payer).
Sourcepub fn next_owned_by(
&mut self,
program: &Address,
) -> Result<AccountView<'info>, ProgramError>
pub fn next_owned_by( &mut self, program: &Address, ) -> Result<AccountView<'info>, ProgramError>
Parse the next account and validate it is owned by program.
Sourcepub fn skip(&mut self, n: usize) -> Result<(), ProgramError>
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.
Sourcepub fn drain_remaining(&mut self) -> Result<&[AccountView<'info>], ProgramError>
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.
Sourcepub fn get(&self, index: usize) -> Option<&AccountView<'info>>
pub fn get(&self, index: usize) -> Option<&AccountView<'info>>
Get an already-parsed account by index.
Returns None if index >= parsed_count.