Skip to content

Commit

Permalink
fix: serde for eth_simulateV1
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 10, 2024
1 parent 2443101 commit 340ce8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
47 changes: 13 additions & 34 deletions crates/rpc-types-eth/src/simulate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! 'eth_simulateV1' Request / Response types: <https://github.com/ethereum/execution-apis/pull/484>

use alloy_primitives::{Address, Bytes, Log, B256};
use alloy_primitives::{Bytes};
use serde::{Deserialize, Serialize};

use crate::{state::StateOverride, BlockOverrides, TransactionRequest};
use crate::{state::StateOverride, Block, Log, BlockOverrides, TransactionRequest};

/// The maximum number of blocks that can be simulated in a single request,
pub const MAX_SIMULATE_BLOCKS: u64 = 256;
Expand All @@ -15,47 +15,26 @@ pub const MAX_SIMULATE_BLOCKS: u64 = 256;
#[serde(rename_all = "camelCase")]
pub struct SimBlock {
/// Modifications to the default block characteristics.
pub block_overrides: BlockOverrides,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub block_overrides: Option<BlockOverrides>,
/// State modifications to apply before executing the transactions.
pub state_overrides: StateOverride,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub state_overrides: Option<StateOverride>,
/// A vector of transactions to be simulated.
pub calls: Vec<TransactionRequest>,
}

/// Represents the result of simulating a block.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SimulatedBlock {
/// The number of the block.
#[serde(with = "alloy_serde::quantity")]
pub number: u64,
/// The hash of the block.
pub hash: B256,
/// The timestamp of the block.
#[serde(with = "alloy_serde::quantity")]
pub timestamp: u64,
/// The gas limit of the block.
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u64,
/// The amount of gas used in the block.
#[serde(with = "alloy_serde::quantity")]
pub gas_used: u64,
/// The recipient of the block's fees.
pub fee_recipient: Address,
/// The base fee per gas unit for the block.
#[serde(with = "alloy_serde::quantity")]
pub base_fee_per_gas: u64,
/// The previous RANDAO value of the block.
pub prev_randao: B256,
pub struct SimulatedBlock<B = Block> {
/// The simulated block.
#[serde(flatten)]
pub inner: B,
/// A vector of results for each call in the block.
pub calls: Vec<SimCallResult>,
}
/// The response type for the eth_simulateV1 method.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SimulateV1Response {
/// Simulated blocks vector.
pub simulated_blocks: Vec<SimulatedBlock>,
}

/// Captures the outcome of a transaction simulation.
/// It includes the return value, logs produced, gas used, and the status of the transaction.
#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -71,7 +50,7 @@ pub struct SimCallResult {
pub gas_used: u64,
/// The final status of the transaction, typically indicating success or failure.
#[serde(with = "alloy_serde::quantity")]
pub status: u64,
pub status: bool,
/// Error in case the call failed
#[serde(default, skip_serializing_if = "Option::is_none")]
pub error: Option<SimulateError>,
Expand Down
5 changes: 5 additions & 0 deletions crates/rpc-types-eth/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub struct AccountOverride {
/// the call.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub state_diff: Option<HashMap<B256, B256>>,
/// Moves addresses precompile into the specified address. This move is done before the 'code'
/// override is set. When the specified address is not a precompile, the behaviour is undefined
/// and different clients might behave differently.
#[serde(default, skip_serializing_if = "Option::is_none", rename = "movePrecompileToAddress")]
pub move_precompile_to: Option<Address>,
}

/// Helper type that bundles various overrides for EVM Execution.
Expand Down

0 comments on commit 340ce8f

Please sign in to comment.