Extended interface for AccountOverrides (#25964)
* Extended interface for AccountOverrides * fix checker issue * make accounts private Co-authored-by: Ivan Loboda <lobodatell@yandex.ru>
This commit is contained in:
parent
25dc0992ae
commit
1ea6a2cb91
|
@ -1,25 +1,31 @@
|
||||||
use solana_sdk::{account::AccountSharedData, pubkey::Pubkey, sysvar};
|
use {
|
||||||
|
solana_sdk::{account::AccountSharedData, pubkey::Pubkey, sysvar},
|
||||||
|
std::collections::HashMap,
|
||||||
|
};
|
||||||
|
|
||||||
/// Encapsulates overridden accounts, typically used for transaction simulations
|
/// Encapsulates overridden accounts, typically used for transaction simulations
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AccountOverrides {
|
pub struct AccountOverrides {
|
||||||
pub slot_history: Option<AccountSharedData>,
|
accounts: HashMap<Pubkey, AccountSharedData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AccountOverrides {
|
impl AccountOverrides {
|
||||||
|
pub fn set_account(&mut self, pubkey: &Pubkey, account: Option<AccountSharedData>) {
|
||||||
|
match account {
|
||||||
|
Some(account) => self.accounts.insert(*pubkey, account),
|
||||||
|
None => self.accounts.remove(pubkey),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets in the slot history
|
/// Sets in the slot history
|
||||||
///
|
///
|
||||||
/// Note: no checks are performed on the correctness of the contained data
|
/// Note: no checks are performed on the correctness of the contained data
|
||||||
pub fn set_slot_history(&mut self, slot_history: Option<AccountSharedData>) {
|
pub fn set_slot_history(&mut self, slot_history: Option<AccountSharedData>) {
|
||||||
self.slot_history = slot_history;
|
self.set_account(&sysvar::slot_history::id(), slot_history);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the account if it's found in the list of overrides
|
/// Gets the account if it's found in the list of overrides
|
||||||
pub fn get(&self, pubkey: &Pubkey) -> Option<&AccountSharedData> {
|
pub fn get(&self, pubkey: &Pubkey) -> Option<&AccountSharedData> {
|
||||||
if pubkey == &sysvar::slot_history::id() {
|
self.accounts.get(pubkey)
|
||||||
self.slot_history.as_ref()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue