MCPcopy Create free account
hub / github.com/EnsoBuild/temper / simulate_bundle

Function simulate_bundle

src/simulation.rs:257–311  ·  view source on GitHub ↗
(
    transactions: Vec<SimulationRequest>,
    config: Config,
)

Source from the content-addressed store, hash-verified

255}
256
257pub async fn simulate_bundle(
258 transactions: Vec<SimulationRequest>,
259 config: Config,
260) -> Result<Json, Rejection> {
261 let first_chain_id = transactions[0].chain_id;
262 let first_block_number = transactions[0].block_number;
263 let first_block_timestamp = transactions[0].block_timestamp;
264
265 let fork_url = config
266 .fork_url
267 .unwrap_or(chain_id_to_fork_url(first_chain_id)?);
268 let mut evm = Evm::new(
269 None,
270 fork_url,
271 first_block_number,
272 transactions[0].gas_limit,
273 true,
274 config.etherscan_key,
275 );
276
277 if evm.get_chain_id() != Uint::from(first_chain_id) {
278 return Err(warp::reject::custom(IncorrectChainIdError()));
279 }
280
281 if let Some(timestamp) = first_block_timestamp {
282 evm.set_block_timestamp(timestamp)
283 .await
284 .expect("failed to set block timestamp");
285 }
286
287 let mut response = Vec::with_capacity(transactions.len());
288 for transaction in transactions {
289 if transaction.chain_id != first_chain_id {
290 return Err(warp::reject::custom(MultipleChainIdsError()));
291 }
292 if transaction.block_number != first_block_number {
293 let tx_block = transaction
294 .block_number
295 .expect("Transaction has no block number");
296 if transaction.block_number < first_block_number || tx_block < evm.get_block().as_u64()
297 {
298 return Err(warp::reject::custom(InvalidBlockNumbersError()));
299 }
300 evm.set_block(tx_block)
301 .await
302 .expect("Failed to set block number");
303 evm.set_block_timestamp(evm.get_block_timestamp().as_u64() + 12)
304 .await
305 .expect("Failed to set block timestamp");
306 }
307 response.push(run(&mut evm, transaction, true).await?);
308 }
309
310 Ok(warp::reply::json(&response))
311}
312
313pub async fn simulate_stateful_new(
314 stateful_simulation_request: StatefulSimulationRequest,

Callers

nothing calls this directly

Calls 10

chain_id_to_fork_urlFunction · 0.85
runFunction · 0.85
get_chain_idMethod · 0.80
set_block_timestampMethod · 0.80
get_blockMethod · 0.80
set_blockMethod · 0.80
get_block_timestampMethod · 0.80

Tested by

no test coverage detected