use { solana_sdk::{account::AccountSharedData, pubkey::Pubkey, sysvar}, std::collections::HashMap, }; /// Encapsulates overridden accounts, typically used for transaction simulations #[derive(Default)] pub struct AccountOverrides { accounts: HashMap, } impl AccountOverrides { pub fn set_account(&mut self, pubkey: &Pubkey, account: Option) { match account { Some(account) => self.accounts.insert(*pubkey, account), None => self.accounts.remove(pubkey), }; } /// Sets in the slot history /// /// Note: no checks are performed on the correctness of the contained data pub fn set_slot_history(&mut self, slot_history: Option) { self.set_account(&sysvar::slot_history::id(), slot_history); } /// Gets the account if it's found in the list of overrides pub fn get(&self, pubkey: &Pubkey) -> Option<&AccountSharedData> { self.accounts.get(pubkey) } }