Skip to main content

anvil_core/
types.rs

1use alloy_eips::eip7840::BlobParams;
2use alloy_primitives::Bytes;
3use alloy_rpc_types::TransactionRequest;
4use alloy_serde::WithOtherFields;
5use serde::{Deserialize, Serialize};
6
7/// Represents the options used in `anvil_reorg`
8#[derive(Debug, Clone, Deserialize)]
9pub struct ReorgOptions {
10    // The depth of the reorg
11    pub depth: u64,
12    // List of transaction requests and blocks pairs to be mined into the new chain
13    pub tx_block_pairs: Vec<(TransactionData, u64)>,
14}
15
16#[derive(Debug, Clone, Deserialize)]
17#[serde(untagged)]
18#[expect(clippy::large_enum_variant)]
19pub enum TransactionData {
20    JSON(WithOtherFields<TransactionRequest>),
21    Raw(Bytes),
22}
23
24/// Blob parameters a node prices blobs with, reported as `blobParams` in `anvil_nodeInfo`.
25///
26/// Unlike the EIP-7840 serialization of [`BlobParams`], this keeps every field, so a fork of the
27/// node can tell schedules apart that share their target, max, and update fraction.
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct NodeBlobParams {
31    pub target_blob_count: u64,
32    pub max_blob_count: u64,
33    #[serde(with = "alloy_serde::quantity")]
34    pub update_fraction: u128,
35    #[serde(with = "alloy_serde::quantity")]
36    pub min_blob_fee: u128,
37    pub max_blobs_per_tx: u64,
38    pub blob_base_cost: u64,
39}
40
41impl From<BlobParams> for NodeBlobParams {
42    fn from(params: BlobParams) -> Self {
43        let BlobParams {
44            target_blob_count,
45            max_blob_count,
46            update_fraction,
47            min_blob_fee,
48            max_blobs_per_tx,
49            blob_base_cost,
50        } = params;
51        Self {
52            target_blob_count,
53            max_blob_count,
54            update_fraction,
55            min_blob_fee,
56            max_blobs_per_tx,
57            blob_base_cost,
58        }
59    }
60}
61
62impl From<NodeBlobParams> for BlobParams {
63    fn from(params: NodeBlobParams) -> Self {
64        let NodeBlobParams {
65            target_blob_count,
66            max_blob_count,
67            update_fraction,
68            min_blob_fee,
69            max_blobs_per_tx,
70            blob_base_cost,
71        } = params;
72        Self {
73            target_blob_count,
74            max_blob_count,
75            update_fraction,
76            min_blob_fee,
77            max_blobs_per_tx,
78            blob_base_cost,
79        }
80    }
81}