Skip to main content

solana_svm_callback/
lib.rs

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