reth_rpc_api/
trace.rs

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