Skip to main content

invoke_and_read

Function invoke_and_read 

Source
pub fn invoke_and_read<'a, T: Projectable, const ACCOUNTS: usize>(
    instruction: &InstructionView<'_, '_, '_, '_>,
    account_views: &[&AccountView; ACCOUNTS],
    signers_seeds: &[Signer<'_, '_>],
) -> Result<ReturnData, ProgramError>
Expand description

Invoke a CPI and immediately read back typed return data.

Combines invoke_signed + get_return_data + as_type::<T>() into a single operation. This is the cleanest way to call a program that returns structured data.

§Example

let oracle_price: &PriceData = invoke_and_read::<PriceData, 2>(
    &instruction,
    &[&oracle_program, &price_feed],
    &[],
)?;