foundry_evm_core/backend/
bal.rs1use super::{Backend, DatabaseError, DatabaseResult};
4use crate::evm::FoundryEvmNetwork;
5use alloy_primitives::{Address, U256};
6use revm::{
7 database_interface::bal::BalState,
8 state::{
9 AccountInfo,
10 bal::{Bal, BlockAccessIndex},
11 },
12};
13use std::sync::Arc;
14
15impl<FEN: FoundryEvmNetwork> Backend<FEN> {
16 pub fn set_bal(&mut self, bal: Arc<Bal>, index: BlockAccessIndex) {
24 self.bal = Some(BalState {
25 bal: Some(bal),
26 bal_index: index,
27 allow_db_fallback: true,
28 ..Default::default()
29 });
30 }
31
32 pub(super) fn apply_bal_account(
33 &self,
34 address: Address,
35 account: &mut Option<AccountInfo>,
36 ) -> DatabaseResult<()> {
37 if let Some(bal) = &self.bal {
38 bal.basic(address, account)
39 .map_err(|err| DatabaseError::GetAccount(address, Arc::new(err.into())))?;
40 }
41 Ok(())
42 }
43
44 pub(super) fn bal_storage(
45 &self,
46 address: Address,
47 index: U256,
48 ) -> DatabaseResult<Option<U256>> {
49 let Some(bal) = &self.bal else { return Ok(None) };
50 bal.storage(&address, index)
51 .map_err(|err| DatabaseError::GetStorage(address, index, Arc::new(err.into())))
52 }
53}
54
55#[cfg(test)]
56mod tests;