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