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: 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: TracerConfig,
45 ) -> RpcResult<Trace>;
46
47 #[method(name = "debug_traceCall")]
53 async fn trace_call(
54 &self,
55 transaction: GenericTransaction,
56 block: BlockNumberOrTagOrHash,
57 tracer_config: TracerConfig,
58 ) -> RpcResult<Trace>;
59}
60
61pub struct DebugRpcServerImpl {
62 client: client::Client,
63}
64
65impl DebugRpcServerImpl {
66 pub fn new(client: client::Client) -> Self {
67 Self { client }
68 }
69}
70
71async fn with_timeout<T>(
72 timeout: Option<core::time::Duration>,
73 fut: impl std::future::Future<Output = Result<T, ClientError>>,
74) -> RpcResult<T> {
75 if let Some(timeout) = timeout {
76 match tokio::time::timeout(timeout, fut).await {
77 Ok(r) => Ok(r?),
78 Err(_) => Err(ErrorObjectOwned::owned::<String>(
79 -32000,
80 "execution timeout".to_string(),
81 None,
82 )),
83 }
84 } else {
85 Ok(fut.await?)
86 }
87}
88
89#[async_trait]
90impl DebugRpcServer for DebugRpcServerImpl {
91 async fn trace_block_by_number(
92 &self,
93 block: BlockNumberOrTag,
94 tracer_config: TracerConfig,
95 ) -> RpcResult<Vec<TransactionTrace>> {
96 let TracerConfig { config, timeout } = tracer_config;
97 with_timeout(timeout, self.client.trace_block_by_number(block, config)).await
98 }
99
100 async fn trace_transaction(
101 &self,
102 transaction_hash: H256,
103 tracer_config: TracerConfig,
104 ) -> RpcResult<Trace> {
105 let TracerConfig { config, timeout } = tracer_config;
106 with_timeout(timeout, self.client.trace_transaction(transaction_hash, config)).await
107 }
108
109 async fn trace_call(
110 &self,
111 transaction: GenericTransaction,
112 block: BlockNumberOrTagOrHash,
113 tracer_config: TracerConfig,
114 ) -> RpcResult<Trace> {
115 let TracerConfig { config, timeout } = tracer_config;
116 with_timeout(timeout, self.client.trace_call(transaction, block, config)).await
117 }
118}