pub struct ScopedContext<'ctx, 'a> { /* private fields */ }Expand description
Borrow-scoped view of a Context.
Generated typed contexts expose this wrapper from their safe raw() method
instead of returning &mut Context<'a> directly. That keeps account and
remaining-account references tied to the borrow of the generated context,
preventing backend account-view lifetimes from being widened through the raw
escape hatch.
Implementations§
Source§impl<'ctx, 'a> ScopedContext<'ctx, 'a>
impl<'ctx, 'a> ScopedContext<'ctx, 'a>
Sourcepub fn new(inner: &'ctx mut Context<'a>) -> Self
pub fn new(inner: &'ctx mut Context<'a>) -> Self
Create a borrow-scoped wrapper around a raw Hopper context.
Sourcepub fn program_id(&self) -> &'ctx Address
pub fn program_id(&self) -> &'ctx Address
Program ID, narrowed to the wrapper borrow lifetime.
Sourcepub fn instruction_data(&self) -> &'ctx [u8]
pub fn instruction_data(&self) -> &'ctx [u8]
Raw instruction data, narrowed to the wrapper borrow lifetime.
Sourcepub fn account(
&self,
index: usize,
) -> Result<&'ctx AccountView<'a>, ProgramError>
pub fn account( &self, index: usize, ) -> Result<&'ctx AccountView<'a>, ProgramError>
Get an account by index, narrowed to the wrapper borrow lifetime.
Sourcepub fn account_mut(
&self,
index: usize,
) -> Result<&'ctx AccountView<'a>, ProgramError>
pub fn account_mut( &self, index: usize, ) -> Result<&'ctx AccountView<'a>, ProgramError>
Mutation-intent account access, narrowed to the wrapper borrow lifetime.
Sourcepub fn num_accounts(&self) -> usize
pub fn num_accounts(&self) -> usize
Get the total number of accounts.
Sourcepub fn accounts(&self) -> &'ctx [AccountView<'a>]
pub fn accounts(&self) -> &'ctx [AccountView<'a>]
Get all accounts as a slice, narrowed to the wrapper borrow lifetime.
Sourcepub fn segment_ref<'b, T: Pod>(
&'b mut self,
index: usize,
abs_offset: u32,
) -> Result<SegRef<'b, T>, ProgramError>
pub fn segment_ref<'b, T: Pod>( &'b mut self, index: usize, abs_offset: u32, ) -> Result<SegRef<'b, T>, ProgramError>
Borrow one runtime-selected typed byte range for reading.
This is the safe bridge for generated typed contexts whose semantic column is known statically but whose cell offset is selected at runtime (for example, a slot in a column-oriented intent shard). The returned guard remains tied to this scoped context borrow and participates in the instruction segment-borrow ledger.
Sourcepub fn segment_mut<'b, T: Pod>(
&'b mut self,
index: usize,
abs_offset: u32,
) -> Result<SegRefMut<'b, T>, ProgramError>
pub fn segment_mut<'b, T: Pod>( &'b mut self, index: usize, abs_offset: u32, ) -> Result<SegRefMut<'b, T>, ProgramError>
Borrow one runtime-selected typed byte range for mutation.
The underlying Context::segment_mut performs the active
strict_writes containment check before registering the exclusive
segment lease, so exposing this method does not create a policy escape.
It lets typed handlers keep their generated manifest/IDL metadata while
selecting an exact cell inside a declared column at runtime.
Sourcepub fn split_segments_mut<'b, T: Pod, const N: usize>(
&'b mut self,
index: usize,
ranges: [(u32, u32); N],
) -> Result<SegmentsMut<'b, T, N>, ProgramError>
pub fn split_segments_mut<'b, T: Pod, const N: usize>( &'b mut self, index: usize, ranges: [(u32, u32); N], ) -> Result<SegmentsMut<'b, T, N>, ProgramError>
Borrow several disjoint runtime-selected typed ranges for mutation. Every range is checked against the active write policy before any lease is granted.
Sourcepub fn borrows(&self) -> &SegmentBorrowRegistry
pub fn borrows(&self) -> &SegmentBorrowRegistry
Access the instruction-scoped segment borrow registry.
Sourcepub fn borrows_mut(&mut self) -> &mut SegmentBorrowRegistry
pub fn borrows_mut(&mut self) -> &mut SegmentBorrowRegistry
Mutably access the instruction-scoped segment borrow registry.
Sourcepub fn audit_accounts(&self) -> AccountAudit<'ctx>
pub fn audit_accounts(&self) -> AccountAudit<'ctx>
Inspect the currently reachable account slice for duplicate aliases.
Sourcepub fn remaining_accounts(&self, from: usize) -> &'ctx [AccountView<'a>]
pub fn remaining_accounts(&self, from: usize) -> &'ctx [AccountView<'a>]
Get the remaining accounts starting at from, narrowed to the wrapper
borrow lifetime.
Sourcepub fn remaining_accounts_strict(&self, from: usize) -> RemainingAccounts<'ctx>
pub fn remaining_accounts_strict(&self, from: usize) -> RemainingAccounts<'ctx>
Get remaining accounts in strict duplicate-rejecting mode.
Sourcepub fn remaining_accounts_passthrough(
&self,
from: usize,
) -> RemainingAccounts<'ctx>
pub fn remaining_accounts_passthrough( &self, from: usize, ) -> RemainingAccounts<'ctx>
Get remaining accounts in duplicate-preserving passthrough mode.
Sourcepub fn remaining_accounts_typed(&self, from: usize) -> RemainingTyped<'ctx>
pub fn remaining_accounts_typed(&self, from: usize) -> RemainingTyped<'ctx>
Get remaining accounts in strict mode and bind a sequential typed parser.
Sourcepub fn remaining_accounts_lazy(&self, from: usize) -> RemainingLazy<'ctx>
pub fn remaining_accounts_lazy(&self, from: usize) -> RemainingLazy<'ctx>
Get remaining accounts in strict mode and bind a lazy indexed parser.
Sourcepub fn require_accounts(&self, n: usize) -> ProgramResult
pub fn require_accounts(&self, n: usize) -> ProgramResult
Require at least n accounts are present.
Sourcepub fn require_unique_accounts(&self) -> ProgramResult
pub fn require_unique_accounts(&self) -> ProgramResult
Require all account addresses to be unique.
Sourcepub fn require_unique_writable_accounts(&self) -> ProgramResult
pub fn require_unique_writable_accounts(&self) -> ProgramResult
Require that no duplicated account is writable in this instruction.
Sourcepub fn require_unique_signer_accounts(&self) -> ProgramResult
pub fn require_unique_signer_accounts(&self) -> ProgramResult
Require that no duplicated account is used as a signer role.
Sourcepub fn require_data_len(&self, n: usize) -> ProgramResult
pub fn require_data_len(&self, n: usize) -> ProgramResult
Require at least n bytes of instruction data.
Sourcepub fn read_data<T: ValuePod>(&self, offset: usize) -> Result<T, ProgramError>
pub fn read_data<T: ValuePod>(&self, offset: usize) -> Result<T, ProgramError>
Read instruction data as a typed value.
Sourcepub fn data_slice(
&self,
offset: usize,
len: usize,
) -> Result<&'ctx [u8], ProgramError>
pub fn data_slice( &self, offset: usize, len: usize, ) -> Result<&'ctx [u8], ProgramError>
Get a byte slice from instruction data.