multiversx_chain_vm/tx_mock/
tx_cache_source.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::{
    types::VMAddress,
    world_mock::{AccountData, BlockchainState},
};

use super::TxCache;

pub trait TxCacheSource: Send + Sync {
    fn load_account(&self, address: &VMAddress) -> Option<AccountData>;

    fn blockchain_ref(&self) -> &BlockchainState;
}

impl TxCacheSource for TxCache {
    fn load_account(&self, address: &VMAddress) -> Option<AccountData> {
        Some(self.with_account(address, AccountData::clone))
    }

    fn blockchain_ref(&self) -> &BlockchainState {
        self.blockchain_ref()
    }
}

impl TxCacheSource for BlockchainState {
    fn load_account(&self, address: &VMAddress) -> Option<AccountData> {
        self.accounts.get(address).cloned()
    }

    fn blockchain_ref(&self) -> &BlockchainState {
        self
    }
}