solana_svm_callback/
lib.rs

1#![cfg_attr(
2    not(feature = "agave-unstable-api"),
3    deprecated(
4        since = "3.1.0",
5        note = "This crate has been marked for formal inclusion in the Agave Unstable API. From \
6                v4.0.0 onward, the `agave-unstable-api` crate feature must be specified to \
7                acknowledge use of an interface that may break without warning."
8    )
9)]
10use {
11    solana_account::AccountSharedData, solana_clock::Slot,
12    solana_precompile_error::PrecompileError, solana_pubkey::Pubkey,
13};
14
15/// Callback used by InvokeContext in SVM
16pub trait InvokeContextCallback {
17    /// Returns the total current epoch stake for the network.
18    fn get_epoch_stake(&self) -> u64 {
19        0
20    }
21
22    /// Returns the current epoch stake for the given vote account.
23    fn get_epoch_stake_for_vote_account(&self, _vote_address: &Pubkey) -> u64 {
24        0
25    }
26
27    /// Returns true if the program_id corresponds to a precompiled program
28    fn is_precompile(&self, _program_id: &Pubkey) -> bool {
29        false
30    }
31
32    /// Calls the precompiled program corresponding to the given program ID.
33    fn process_precompile(
34        &self,
35        _program_id: &Pubkey,
36        _data: &[u8],
37        _instruction_datas: Vec<&[u8]>,
38    ) -> Result<(), PrecompileError> {
39        Err(PrecompileError::InvalidPublicKey)
40    }
41}
42
43/// Runtime callbacks for transaction processing.
44pub trait TransactionProcessingCallback: InvokeContextCallback {
45    fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<(AccountSharedData, Slot)>;
46
47    fn inspect_account(&self, _address: &Pubkey, _account_state: AccountState, _is_writable: bool) {
48    }
49}
50
51/// The state the account is in initially, before transaction processing
52#[derive(Debug)]
53pub enum AccountState<'a> {
54    /// This account is dead, and will be created by this transaction
55    Dead,
56    /// This account is alive, and already existed prior to this transaction
57    Alive(&'a AccountSharedData),
58}