Skip to main content

reth_rpc_api/
trace.rs

1use alloy_eips::BlockId;
2use alloy_primitives::{map::HashSet, Bytes, B256};
3use alloy_rpc_types_eth::{state::StateOverride, BlockOverrides, Index};
4use alloy_rpc_types_trace::{
5    filter::TraceFilter,
6    opcode::{BlockOpcodeGas, TransactionOpcodeGas},
7    parity::*,
8};
9use jsonrpsee::{core::RpcResult, proc_macros::rpc};
10
11/// Ethereum trace API
12#[cfg_attr(not(feature = "client"), rpc(server, namespace = "trace"))]
13#[cfg_attr(feature = "client", rpc(server, client, namespace = "trace"))]
14pub trait TraceApi<TxReq> {
15    /// Executes the given call and returns a number of possible traces for it.
16    #[method(name = "call")]
17    async fn trace_call(
18        &self,
19        call: TxReq,
20        trace_types: HashSet<TraceType>,
21        block_id: Option<BlockId>,
22        state_overrides: Option<StateOverride>,
23        block_overrides: Option<Box<BlockOverrides>>,
24    ) -> RpcResult<TraceResults>;
25
26    /// Performs multiple call traces on top of the same block, defaulting to latest when no block
27    /// is specified. Each call is executed with the preceding calls applied first, allowing
28    /// dependent transactions to be traced.
29    #[method(name = "callMany")]
30    async fn trace_call_many(
31        &self,
32        calls: Vec<(TxReq, HashSet<TraceType>)>,
33        block_id: Option<BlockId>,
34    ) -> RpcResult<Vec<TraceResults>>;
35
36    /// Traces a call to `eth_sendRawTransaction` without making the call, returning the traces.
37    ///
38    /// Expects a raw transaction data
39    #[method(name = "rawTransaction")]
40    async fn trace_raw_transaction(
41        &self,
42        data: Bytes,
43        trace_types: HashSet<TraceType>,
44        block_id: Option<BlockId>,
45    ) -> RpcResult<TraceResults>;
46
47    /// Replays all transactions in a block returning the requested traces for each transaction.
48    #[method(name = "replayBlockTransactions")]
49    async fn replay_block_transactions(
50        &self,
51        block_id: BlockId,
52        trace_types: HashSet<TraceType>,
53    ) -> RpcResult<Option<Vec<TraceResultsWithTransactionHash>>>;
54
55    /// Replays a transaction, returning the traces or `None` if the transaction does not exist.
56    #[method(name = "replayTransaction")]
57    async fn replay_transaction(
58        &self,
59        transaction: B256,
60        trace_types: HashSet<TraceType>,
61    ) -> RpcResult<Option<TraceResultsWithTransactionHash>>;
62
63    /// Returns traces created at given block.
64    #[method(name = "block")]
65    async fn trace_block(
66        &self,
67        block_id: BlockId,
68    ) -> RpcResult<Option<Vec<LocalizedTransactionTrace>>>;
69
70    /// Returns traces matching given filter.
71    ///
72    /// This is similar to `eth_getLogs` but for traces. Omitted range bounds default to latest.
73    #[method(name = "filter")]
74    async fn trace_filter(&self, filter: TraceFilter) -> RpcResult<Vec<LocalizedTransactionTrace>>;
75
76    /// Returns the transaction trace at the given `traceAddress` path.
77    ///
78    /// An empty path selects the root, `[0]` selects its first child, and `[0, 1]` selects that
79    /// child's second child. Returns `None` if the transaction or path does not exist.
80    /// Callers requiring a flat index can index the result of `trace_transaction` instead.
81    #[method(name = "get")]
82    async fn trace_get(
83        &self,
84        hash: B256,
85        indices: Vec<Index>,
86    ) -> RpcResult<Option<LocalizedTransactionTrace>>;
87
88    /// Returns all traces of given transaction.
89    #[method(name = "transaction")]
90    async fn trace_transaction(
91        &self,
92        hash: B256,
93    ) -> RpcResult<Option<Vec<LocalizedTransactionTrace>>>;
94
95    /// Returns all opcodes with their count and combined gas usage for the given transaction in no
96    /// particular order.
97    #[method(name = "transactionOpcodeGas")]
98    async fn trace_transaction_opcode_gas(
99        &self,
100        tx_hash: B256,
101    ) -> RpcResult<Option<TransactionOpcodeGas>>;
102
103    /// Returns the opcodes of all transactions in the given block.
104    ///
105    /// This is the same as `trace_transactionOpcodeGas` but for all transactions in a block.
106    #[method(name = "blockOpcodeGas")]
107    async fn trace_block_opcode_gas(&self, block_id: BlockId) -> RpcResult<Option<BlockOpcodeGas>>;
108}