pub struct DynCpi<'a, const MAX_ACCTS: usize, const MAX_DATA: usize> { /* private fields */ }Expand description
Variable-length CPI builder with compile-time stack capacity.
MAX_ACCTS is the upper bound on the number of AccountMeta
entries. MAX_DATA is the upper bound on the instruction data
byte count. Exceeding either returns an error; nothing panics.
Use when the CPI shape is not known at compile time. For
statically-shaped CPIs, prefer cpi::invoke_signed::<N> which
avoids the two bounds entirely.
Implementations§
Source§impl<'a, const MAX_ACCTS: usize, const MAX_DATA: usize> DynCpi<'a, MAX_ACCTS, MAX_DATA>
impl<'a, const MAX_ACCTS: usize, const MAX_DATA: usize> DynCpi<'a, MAX_ACCTS, MAX_DATA>
Sourcepub fn push_account(
&mut self,
account: &'a AccountView,
writable: bool,
signer: bool,
) -> ProgramResult
pub fn push_account( &mut self, account: &'a AccountView, writable: bool, signer: bool, ) -> ProgramResult
Append one account meta. The writable and signer flags
are carried through to the emitted CPI instruction.
Returns Err(ProgramError::InvalidArgument) when the builder
is already at MAX_ACCTS capacity. Users pick the capacity
at the type parameter; bumping it is a type-system edit, not
a runtime error.
Sourcepub fn push_data(&mut self, bytes: &[u8]) -> ProgramResult
pub fn push_data(&mut self, bytes: &[u8]) -> ProgramResult
Append the given bytes to the instruction data buffer.
Returns Err(ProgramError::InvalidArgument) when the buffer
does not have room for the full slice. The append is
all-or-nothing; a partial write does not happen.
Sourcepub fn push_byte(&mut self, byte: u8) -> ProgramResult
pub fn push_byte(&mut self, byte: u8) -> ProgramResult
Append one byte. Sugar for programs that build instruction data one discriminator + one argument at a time.
Sourcepub fn push_u64_le(&mut self, value: u64) -> ProgramResult
pub fn push_u64_le(&mut self, value: u64) -> ProgramResult
Append the little-endian encoding of a u64. Covers the
most common arg shape (lamports, timestamps, flags).
Sourcepub fn push_pubkey(&mut self, address: &Address) -> ProgramResult
pub fn push_pubkey(&mut self, address: &Address) -> ProgramResult
Append a 32-byte pubkey.
Sourcepub const fn account_count(&self) -> usize
pub const fn account_count(&self) -> usize
Current account count.
Sourcepub const fn program_id(&self) -> &Address
pub const fn program_id(&self) -> &Address
Program id this dynamic CPI targets.