solana_program/
instruction.rs

1pub use solana_instruction::{
2    error::InstructionError, AccountMeta, Instruction, ProcessedSiblingInstruction,
3    TRANSACTION_LEVEL_STACK_HEIGHT,
4};
5
6/// Returns a sibling instruction from the processed sibling instruction list.
7///
8/// The processed sibling instruction list is a reverse-ordered list of
9/// successfully processed sibling instructions. For example, given the call flow:
10///
11/// A
12/// B -> C -> D
13/// B -> E
14/// B -> F
15///
16/// Then B's processed sibling instruction list is: `[A]`
17/// Then F's processed sibling instruction list is: `[E, C]`
18pub fn get_processed_sibling_instruction(index: usize) -> Option<Instruction> {
19    #[cfg(target_os = "solana")]
20    {
21        solana_instruction::syscalls::get_processed_sibling_instruction(index)
22    }
23
24    #[cfg(not(target_os = "solana"))]
25    {
26        crate::program_stubs::sol_get_processed_sibling_instruction(index)
27    }
28}
29
30/// Get the current stack height, transaction-level instructions are height
31/// TRANSACTION_LEVEL_STACK_HEIGHT, fist invoked inner instruction is height
32/// TRANSACTION_LEVEL_STACK_HEIGHT + 1, etc...
33pub fn get_stack_height() -> usize {
34    #[cfg(target_os = "solana")]
35    {
36        solana_instruction::syscalls::get_stack_height()
37    }
38
39    #[cfg(not(target_os = "solana"))]
40    {
41        crate::program_stubs::sol_get_stack_height() as usize
42    }
43}
44
45// TODO: remove this.
46/// Addition that returns [`InstructionError::InsufficientFunds`] on overflow.
47///
48/// This is an internal utility function.
49#[doc(hidden)]
50pub fn checked_add(a: u64, b: u64) -> Result<u64, InstructionError> {
51    a.checked_add(b).ok_or(InstructionError::InsufficientFunds)
52}