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