multiversx_chain_vm/host/context/
tx_cache_source.rs

1use crate::{
2    blockchain::state::{AccountData, BlockchainState},
3    types::VMAddress,
4};
5
6use super::TxCache;
7
8pub trait TxCacheSource: Send + Sync {
9    fn load_account(&self, address: &VMAddress) -> Option<AccountData>;
10
11    fn blockchain_ref(&self) -> &BlockchainState;
12}
13
14impl TxCacheSource for TxCache {
15    fn load_account(&self, address: &VMAddress) -> Option<AccountData> {
16        Some(self.with_account(address, AccountData::clone))
17    }
18
19    fn blockchain_ref(&self) -> &BlockchainState {
20        self.blockchain_ref()
21    }
22}
23
24impl TxCacheSource for BlockchainState {
25    fn load_account(&self, address: &VMAddress) -> Option<AccountData> {
26        self.accounts.get(address).cloned()
27    }
28
29    fn blockchain_ref(&self) -> &BlockchainState {
30        self
31    }
32}