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. i.e. transaction n will be executed
27    /// on top of a pending block with all n-1 transactions applied (traced) first. Allows to trace
28    /// dependent transactions.
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.
56    #[method(name = "replayTransaction")]
57    async fn replay_transaction(
58        &self,
59        transaction: B256,
60        trace_types: HashSet<TraceType>,
61    ) -> RpcResult<TraceResults>;
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.
73    #[method(name = "filter")]
74    async fn trace_filter(&self, filter: TraceFilter) -> RpcResult<Vec<LocalizedTransactionTrace>>;
75
76    /// Returns transaction trace at given index.
77    ///
78    /// `indices` represent the index positions of the traces.
79    ///
80    /// Note: This expects a list of indices but only one is supported since this function returns a
81    /// single [`LocalizedTransactionTrace`].
82    #[method(name = "get")]
83    async fn trace_get(
84        &self,
85        hash: B256,
86        indices: Vec<Index>,
87    ) -> RpcResult<Option<LocalizedTransactionTrace>>;
88
89    /// Returns all traces of given transaction.
90    #[method(name = "transaction")]
91    async fn trace_transaction(
92        &self,
93        hash: B256,
94    ) -> RpcResult<Option<Vec<LocalizedTransactionTrace>>>;
95
96    /// Returns all opcodes with their count and combined gas usage for the given transaction in no
97    /// particular order.
98    #[method(name = "transactionOpcodeGas")]
99    async fn trace_transaction_opcode_gas(
100        &self,
101        tx_hash: B256,
102    ) -> RpcResult<Option<TransactionOpcodeGas>>;
103
104    /// Returns the opcodes of all transactions in the given block.
105    ///
106    /// This is the same as `trace_transactionOpcodeGas` but for all transactions in a block.
107    #[method(name = "blockOpcodeGas")]
108    async fn trace_block_opcode_gas(&self, block_id: BlockId) -> RpcResult<Option<BlockOpcodeGas>>;
109}