diff --git a/src/interpreter/env.rs b/src/interpreter/env.rs index 6146edb..79b63e7 100644 --- a/src/interpreter/env.rs +++ b/src/interpreter/env.rs @@ -1,5 +1,5 @@ use futures_util::lock::Mutex; -use solang_parser::pt::{Expression, Identifier, Statement}; +use solang_parser::pt::{Expression, Identifier}; use std::{ collections::{HashMap, HashSet}, sync::Arc, @@ -7,6 +7,7 @@ use std::{ use url::Url; use alloy::{ + eips::BlockId, network::{AnyNetwork, Ethereum, EthereumWallet, NetworkWallet, TxSigner}, primitives::Address, providers::{Provider, ProviderBuilder}, @@ -24,9 +25,9 @@ pub struct Env { variables: Vec>, types: HashMap, provider: Arc, Ethereum>>, - function_bodies: HashMap, wallet: Option, ledger: Option>>, + block_id: Option, pub config: Config, } @@ -40,21 +41,13 @@ impl Env { variables: vec![HashMap::new()], types: HashMap::new(), provider: Arc::new(provider), - function_bodies: HashMap::new(), wallet: None, ledger: None, + block_id: None, config, } } - pub fn set_function_body(&mut self, name: &str, body: Statement) { - self.function_bodies.insert(name.to_string(), body); - } - - pub fn get_function_body(&self, name: &str) -> Option<&Statement> { - self.function_bodies.get(name) - } - pub fn push_scope(&mut self) { self.variables.push(HashMap::new()); } @@ -71,6 +64,14 @@ impl Env { self.config.debug } + pub fn set_block(&mut self, block: BlockId) { + self.block_id = Some(block); + } + + pub fn block(&self) -> Option { + self.block_id + } + pub fn get_provider(&self) -> Arc, Ethereum>> { self.provider.clone() } diff --git a/src/interpreter/functions/contract.rs b/src/interpreter/functions/contract.rs index 97325e6..a3706b1 100644 --- a/src/interpreter/functions/contract.rs +++ b/src/interpreter/functions/contract.rs @@ -184,7 +184,7 @@ impl FunctionDef for ContractFunction { } else if self.mode == ContractCallMode::Call || (self.mode == ContractCallMode::Default && is_view) { - _execute_contract_call(func).await + _execute_contract_call(env, func).await } else { _execute_contract_send(&addr, func, &call_options, env).await } @@ -224,6 +224,7 @@ where } async fn _execute_contract_call( + env: &Env, func: CallBuilder, ) -> Result where @@ -231,7 +232,11 @@ where P: Provider, N: Network, { - let result = func.call().await?; + let mut call = func.call(); + if let Some(b) = env.block() { + call = call.block(b); + } + let result = call.await?; let return_values = result .into_iter() .map(Value::try_from)