anvil_zksync_api_server/impls/
debug.rs

1use anvil_zksync_api_decl::DebugNamespaceServer;
2use anvil_zksync_core::node::InMemoryNode;
3use jsonrpsee::core::{async_trait, RpcResult};
4use zksync_types::api::{BlockNumber, CallTracerBlockResult, CallTracerResult, TracerConfig};
5use zksync_types::transaction_request::CallRequest;
6use zksync_types::{api, api::BlockId, web3::Bytes, H256};
7
8use crate::error::RpcErrorAdapter;
9
10pub struct DebugNamespace {
11    node: InMemoryNode,
12}
13
14impl DebugNamespace {
15    pub fn new(node: InMemoryNode) -> Self {
16        Self { node }
17    }
18}
19
20#[async_trait]
21impl DebugNamespaceServer for DebugNamespace {
22    async fn trace_block_by_number(
23        &self,
24        block: BlockNumber,
25        options: Option<TracerConfig>,
26    ) -> RpcResult<CallTracerBlockResult> {
27        self.node
28            .trace_block_impl(api::BlockId::Number(block), options)
29            .await
30            .map_err(RpcErrorAdapter::into)
31    }
32
33    async fn trace_block_by_hash(
34        &self,
35        hash: H256,
36        options: Option<TracerConfig>,
37    ) -> RpcResult<CallTracerBlockResult> {
38        self.node
39            .trace_block_impl(api::BlockId::Hash(hash), options)
40            .await
41            .map_err(RpcErrorAdapter::into)
42    }
43
44    async fn trace_call(
45        &self,
46        request: CallRequest,
47        block: Option<api::BlockId>,
48        options: Option<TracerConfig>,
49    ) -> RpcResult<CallTracerResult> {
50        self.node
51            .trace_call_impl(request, block, options)
52            .await
53            .map_err(RpcErrorAdapter::into)
54    }
55
56    async fn trace_transaction(
57        &self,
58        tx_hash: H256,
59        options: Option<TracerConfig>,
60    ) -> RpcResult<Option<CallTracerResult>> {
61        self.node
62            .trace_transaction_impl(tx_hash, options)
63            .await
64            .map_err(RpcErrorAdapter::into)
65    }
66
67    async fn get_raw_transaction(&self, tx_hash: H256) -> RpcResult<Option<Bytes>> {
68        self.node
69            .get_raw_transaction_impl(tx_hash)
70            .await
71            .map_err(RpcErrorAdapter::into)
72    }
73
74    async fn get_raw_transactions(&self, block_number: BlockId) -> RpcResult<Vec<Bytes>> {
75        self.node
76            .get_raw_transactions_impl(block_number)
77            .await
78            .map_err(RpcErrorAdapter::into)
79    }
80}