(
transactions: Vec<SimulationRequest>,
config: Config,
)
| 255 | } |
| 256 | |
| 257 | pub 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 | |
| 313 | pub async fn simulate_stateful_new( |
| 314 | stateful_simulation_request: StatefulSimulationRequest, |
nothing calls this directly
no test coverage detected