solana_svm_callback/
lib.rs

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