pallet_revive_eth_rpc/apis/
debug_apis.rs1use crate::*;
18use jsonrpsee::{core::RpcResult, proc_macros::rpc};
19
20#[rpc(server, client)]
22pub trait DebugRpc {
23 #[method(name = "debug_traceBlockByNumber")]
29 async fn trace_block_by_number(
30 &self,
31 block: BlockNumberOrTag,
32 tracer_config: Option<TracerConfig>,
33 ) -> RpcResult<Vec<TransactionTrace>>;
34
35 #[method(name = "debug_traceTransaction")]
41 async fn trace_transaction(
42 &self,
43 transaction_hash: H256,
44 tracer_config: Option<TracerConfig>,
45 ) -> RpcResult<Trace>;
46
47 #[method(name = "debug_traceCall")]
56 async fn trace_call(
57 &self,
58 transaction: GenericTransaction,
59 block: BlockNumberOrTagOrHash,
60 trace_call_config: Option<TraceCallConfig>,
61 ) -> RpcResult<Trace>;
62
63 #[method(name = "debug_getAutomine")]
64 async fn get_automine(&self) -> RpcResult<bool>;
65}
66
67pub struct DebugRpcServerImpl {
68 client: client::Client,
69}
70
71impl DebugRpcServerImpl {
72 pub fn new(client: client::Client) -> Self {
73 Self { client }
74 }
75}
76
77async fn with_timeout<T>(
78 timeout: Option<core::time::Duration>,
79 fut: impl std::future::Future<Output = Result<T, ClientError>>,
80) -> RpcResult<T> {
81 if let Some(timeout) = timeout {
82 match tokio::time::timeout(timeout, fut).await {
83 Ok(r) => Ok(r?),
84 Err(_) => Err(ErrorObjectOwned::owned::<String>(
85 -32000,
86 "execution timeout".to_string(),
87 None,
88 )),
89 }
90 } else {
91 Ok(fut.await?)
92 }
93}
94
95#[async_trait]
96impl DebugRpcServer for DebugRpcServerImpl {
97 async fn trace_block_by_number(
98 &self,
99 block: BlockNumberOrTag,
100 tracer_config: Option<TracerConfig>,
101 ) -> RpcResult<Vec<TransactionTrace>> {
102 let TracerConfig { config, timeout } = tracer_config.unwrap_or_default();
103 with_timeout(timeout, self.client.trace_block_by_number(block, config)).await
104 }
105
106 async fn trace_transaction(
107 &self,
108 transaction_hash: H256,
109 tracer_config: Option<TracerConfig>,
110 ) -> RpcResult<Trace> {
111 let TracerConfig { config, timeout } = tracer_config.unwrap_or_default();
112 with_timeout(timeout, self.client.trace_transaction(transaction_hash, config)).await
113 }
114
115 async fn trace_call(
116 &self,
117 transaction: GenericTransaction,
118 block: BlockNumberOrTagOrHash,
119 trace_call_config: Option<TraceCallConfig>,
120 ) -> RpcResult<Trace> {
121 let TraceCallConfig { tracer_config, state_overrides } =
122 trace_call_config.unwrap_or_default();
123 let TracerConfig { config, timeout } = tracer_config;
124 with_timeout(timeout, self.client.trace_call(transaction, block, config, state_overrides))
125 .await
126 }
127
128 async fn get_automine(&self) -> RpcResult<bool> {
129 sc_service::Result::Ok(self.client.get_automine().await)
130 }
131}