Skip to content

Commit

Permalink
Add block ID to env
Browse files Browse the repository at this point in the history
  • Loading branch information
danhper committed Jul 31, 2024
1 parent c87711a commit 127484d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/interpreter/env.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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,
};
use url::Url;

use alloy::{
eips::BlockId,
network::{AnyNetwork, Ethereum, EthereumWallet, NetworkWallet, TxSigner},
primitives::Address,
providers::{Provider, ProviderBuilder},
Expand All @@ -24,9 +25,9 @@ pub struct Env {
variables: Vec<HashMap<String, Value>>,
types: HashMap<String, Type>,
provider: Arc<dyn Provider<Http<Client>, Ethereum>>,
function_bodies: HashMap<String, Statement>,
wallet: Option<EthereumWallet>,
ledger: Option<Arc<Mutex<Ledger>>>,
block_id: Option<BlockId>,
pub config: Config,
}

Expand All @@ -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());
}
Expand All @@ -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<BlockId> {
self.block_id
}

pub fn get_provider(&self) -> Arc<dyn Provider<Http<Client>, Ethereum>> {
self.provider.clone()
}
Expand Down
9 changes: 7 additions & 2 deletions src/interpreter/functions/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -224,14 +224,19 @@ where
}

async fn _execute_contract_call<T, P, N>(
env: &Env,
func: CallBuilder<T, P, alloy::json_abi::Function, N>,
) -> Result<Value>
where
T: Transport + Clone,
P: Provider<T, N>,
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)
Expand Down

0 comments on commit 127484d

Please sign in to comment.