revm_inspector/
inspect.rs

1use handler::evm::{ExecuteCommitEvm, ExecuteEvm};
2
3/// InspectEvm is a API that allows inspecting the EVM.
4///
5/// It extends the `ExecuteEvm` trait and enabled setting inspector
6///
7pub trait InspectEvm: ExecuteEvm {
8    type Inspector;
9
10    /// Set the inspector for the EVM.
11    ///
12    /// this function is used to change inspector during execution.
13    /// This function can't change Inspector type, changing inspector type can be done in
14    /// `Evm` with `with_inspector` function.
15    fn set_inspector(&mut self, inspector: Self::Inspector);
16
17    /// Inspect the EVM with the current inspector and previous transaction.
18    fn inspect_replay(&mut self) -> Self::Output;
19
20    /// Inspect the EVM with the given inspector and transaction.
21    fn inspect(&mut self, tx: Self::Tx, inspector: Self::Inspector) -> Self::Output {
22        self.set_tx(tx);
23        self.inspect_replay_with_inspector(inspector)
24    }
25
26    /// Inspect the EVM with the current inspector and previous transaction by replaying it.
27    fn inspect_replay_with_inspector(&mut self, inspector: Self::Inspector) -> Self::Output {
28        self.set_inspector(inspector);
29        self.inspect_replay()
30    }
31
32    /// Inspect the EVM with the given transaction.
33    fn inspect_with_tx(&mut self, tx: Self::Tx) -> Self::Output {
34        self.set_tx(tx);
35        self.inspect_replay()
36    }
37}
38
39/// InspectCommitEvm is a API that allows inspecting similar to `InspectEvm` but it has
40/// functions that commit the state diff to the database.
41///
42/// Functions return CommitOutput from [`ExecuteCommitEvm`] trait.
43pub trait InspectCommitEvm: InspectEvm + ExecuteCommitEvm {
44    /// Inspect the EVM with the current inspector and previous transaction, similar to [`InspectEvm::inspect_replay`]
45    /// and commit the state diff to the database.
46    fn inspect_replay_commit(&mut self) -> Self::CommitOutput;
47
48    /// Inspects commit with the given inspector and previous transaction, similar to [`InspectEvm::inspect_replay_with_inspector`]
49    /// and commit the state diff to the database.
50    fn inspect_replay_commit_with_inspector(
51        &mut self,
52        inspector: Self::Inspector,
53    ) -> Self::CommitOutput {
54        self.set_inspector(inspector);
55        self.inspect_replay_commit()
56    }
57
58    /// Inspect the EVM with the current inspector and previous transaction by replaying,similar to [`InspectEvm::inspect_replay_with_inspector`]
59    /// and commit the state diff to the database.
60    fn inspect_replay_with_inspector(&mut self, inspector: Self::Inspector) -> Self::CommitOutput {
61        self.set_inspector(inspector);
62        self.inspect_replay_commit()
63    }
64
65    /// Inspect the EVM with the given transaction and inspector similar to [`InspectEvm::inspect`]
66    /// and commit the state diff to the database.
67    fn inspect_commit(&mut self, tx: Self::Tx, inspector: Self::Inspector) -> Self::CommitOutput {
68        self.set_tx(tx);
69        self.inspect_replay_commit_with_inspector(inspector)
70    }
71}