anvil_core/
types.rs

1use alloy_primitives::{Bytes, B256, U256};
2use alloy_rpc_types::TransactionRequest;
3use serde::{Deserialize, Serialize, Serializer};
4
5/// Represents the result of `eth_getWork`.
6///
7/// This may or may not include the block number.
8#[derive(Debug, Default, PartialEq, Eq)]
9pub struct Work {
10    pub pow_hash: B256,
11    pub seed_hash: B256,
12    pub target: B256,
13    pub number: Option<u64>,
14}
15
16impl Serialize for Work {
17    fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
18    where
19        S: Serializer,
20    {
21        if let Some(num) = self.number {
22            (&self.pow_hash, &self.seed_hash, &self.target, U256::from(num)).serialize(s)
23        } else {
24            (&self.pow_hash, &self.seed_hash, &self.target).serialize(s)
25        }
26    }
27}
28
29/// Represents the options used in `anvil_reorg`
30#[derive(Debug, Clone, Deserialize)]
31pub struct ReorgOptions {
32    // The depth of the reorg
33    pub depth: u64,
34    // List of transaction requests and blocks pairs to be mined into the new chain
35    pub tx_block_pairs: Vec<(TransactionData, u64)>,
36}
37
38#[derive(Debug, Clone, Deserialize)]
39#[serde(untagged)]
40#[expect(clippy::large_enum_variant)]
41pub enum TransactionData {
42    JSON(TransactionRequest),
43    Raw(Bytes),
44}