solana_svm_callback/
lib.rs

1use {
2    solana_account::AccountSharedData, solana_precompile_error::PrecompileError,
3    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 account_matches_owners(&self, account: &Pubkey, owners: &[Pubkey]) -> Option<usize>;
37
38    fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<AccountSharedData>;
39
40    fn add_builtin_account(&self, _name: &str, _program_id: &Pubkey) {}
41
42    fn inspect_account(&self, _address: &Pubkey, _account_state: AccountState, _is_writable: bool) {
43    }
44
45    #[deprecated(
46        since = "2.3.0",
47        note = "Use `get_epoch_stake_for_vote_account` on the `InvokeContextCallback` trait instead"
48    )]
49    fn get_current_epoch_vote_account_stake(&self, vote_address: &Pubkey) -> u64 {
50        Self::get_epoch_stake_for_vote_account(self, vote_address)
51    }
52}
53
54/// The state the account is in initially, before transaction processing
55#[derive(Debug)]
56pub enum AccountState<'a> {
57    /// This account is dead, and will be created by this transaction
58    Dead,
59    /// This account is alive, and already existed prior to this transaction
60    Alive(&'a AccountSharedData),
61}