Skip to main content

sui_rpc_api/grpc/v2/ledger_service/
mod.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::RpcService;
5
6use sui_rpc::proto::sui::rpc::v2::BatchGetObjectsRequest;
7use sui_rpc::proto::sui::rpc::v2::BatchGetObjectsResponse;
8use sui_rpc::proto::sui::rpc::v2::BatchGetTransactionsRequest;
9use sui_rpc::proto::sui::rpc::v2::BatchGetTransactionsResponse;
10use sui_rpc::proto::sui::rpc::v2::GetCheckpointRequest;
11use sui_rpc::proto::sui::rpc::v2::GetCheckpointResponse;
12use sui_rpc::proto::sui::rpc::v2::GetEpochRequest;
13use sui_rpc::proto::sui::rpc::v2::GetEpochResponse;
14use sui_rpc::proto::sui::rpc::v2::GetObjectRequest;
15use sui_rpc::proto::sui::rpc::v2::GetObjectResponse;
16use sui_rpc::proto::sui::rpc::v2::GetProtocolConfigRequest;
17use sui_rpc::proto::sui::rpc::v2::GetProtocolConfigResponse;
18use sui_rpc::proto::sui::rpc::v2::GetServiceInfoRequest;
19use sui_rpc::proto::sui::rpc::v2::GetServiceInfoResponse;
20use sui_rpc::proto::sui::rpc::v2::GetTransactionRequest;
21use sui_rpc::proto::sui::rpc::v2::GetTransactionResponse;
22use sui_rpc::proto::sui::rpc::v2::ListCheckpointsRequest;
23use sui_rpc::proto::sui::rpc::v2::ListCheckpointsResponse;
24use sui_rpc::proto::sui::rpc::v2::ListEventsRequest;
25use sui_rpc::proto::sui::rpc::v2::ListEventsResponse;
26use sui_rpc::proto::sui::rpc::v2::ListObjectVersionsRequest;
27use sui_rpc::proto::sui::rpc::v2::ListObjectVersionsResponse;
28use sui_rpc::proto::sui::rpc::v2::ListTransactionsRequest;
29use sui_rpc::proto::sui::rpc::v2::ListTransactionsResponse;
30use sui_rpc::proto::sui::rpc::v2::ledger_service_server::LedgerService;
31use tonic::codegen::BoxStream;
32
33mod bitmap_scan;
34mod chunked_scan;
35mod event_scan;
36pub(crate) mod get_checkpoint;
37mod get_epoch;
38mod get_object;
39mod get_protocol_config;
40mod get_service_info;
41pub(crate) mod get_transaction;
42mod ledger_read;
43mod list_checkpoints;
44mod list_events;
45mod list_object_versions;
46mod list_transactions;
47mod object_set;
48mod query_end;
49mod stream;
50pub use get_epoch::{protocol_config_from_parts, protocol_config_to_proto, set_epoch_end_fields};
51pub use get_object::ObjectSelector;
52pub use get_object::validate_get_object_requests;
53
54use stream::serve_list_stream;
55
56#[tonic::async_trait]
57impl LedgerService for RpcService {
58    async fn get_service_info(
59        &self,
60        _request: tonic::Request<GetServiceInfoRequest>,
61    ) -> Result<tonic::Response<GetServiceInfoResponse>, tonic::Status> {
62        get_service_info::get_service_info(self)
63            .map(tonic::Response::new)
64            .map_err(Into::into)
65    }
66
67    async fn get_object(
68        &self,
69        request: tonic::Request<GetObjectRequest>,
70    ) -> Result<tonic::Response<GetObjectResponse>, tonic::Status> {
71        get_object::get_object(self, request.into_inner())
72            .map(tonic::Response::new)
73            .map_err(Into::into)
74    }
75
76    async fn batch_get_objects(
77        &self,
78        request: tonic::Request<BatchGetObjectsRequest>,
79    ) -> Result<tonic::Response<BatchGetObjectsResponse>, tonic::Status> {
80        let service = self.clone();
81        tokio::task::spawn_blocking(move || {
82            get_object::batch_get_objects(&service, request.into_inner())
83        })
84        .await
85        .map_err(|e| tonic::Status::internal(format!("batch_get_objects task failed: {e}")))?
86        .map(tonic::Response::new)
87        .map_err(Into::into)
88    }
89
90    async fn list_object_versions(
91        &self,
92        request: tonic::Request<ListObjectVersionsRequest>,
93    ) -> Result<tonic::Response<BoxStream<ListObjectVersionsResponse>>, tonic::Status> {
94        serve_list_stream(
95            "list_object_versions",
96            self.config.ledger_history().list_object_versions().timeout,
97            list_object_versions::list_object_versions(self.clone(), request.into_inner()),
98        )
99        .await
100    }
101
102    async fn get_transaction(
103        &self,
104        request: tonic::Request<GetTransactionRequest>,
105    ) -> Result<tonic::Response<GetTransactionResponse>, tonic::Status> {
106        get_transaction::get_transaction(self, request.into_inner())
107            .map(tonic::Response::new)
108            .map_err(Into::into)
109    }
110
111    async fn batch_get_transactions(
112        &self,
113        request: tonic::Request<BatchGetTransactionsRequest>,
114    ) -> Result<tonic::Response<BatchGetTransactionsResponse>, tonic::Status> {
115        let service = self.clone();
116        tokio::task::spawn_blocking(move || {
117            get_transaction::batch_get_transactions(&service, request.into_inner())
118        })
119        .await
120        .map_err(|e| tonic::Status::internal(format!("batch_get_transactions task failed: {e}")))?
121        .map(tonic::Response::new)
122        .map_err(Into::into)
123    }
124
125    async fn get_checkpoint(
126        &self,
127        request: tonic::Request<GetCheckpointRequest>,
128    ) -> Result<tonic::Response<GetCheckpointResponse>, tonic::Status> {
129        get_checkpoint::get_checkpoint(self, request.into_inner())
130            .map(tonic::Response::new)
131            .map_err(Into::into)
132    }
133
134    async fn get_epoch(
135        &self,
136        request: tonic::Request<GetEpochRequest>,
137    ) -> Result<tonic::Response<GetEpochResponse>, tonic::Status> {
138        get_epoch::get_epoch(self, request.into_inner())
139            .map(tonic::Response::new)
140            .map_err(Into::into)
141    }
142
143    async fn get_protocol_config(
144        &self,
145        request: tonic::Request<GetProtocolConfigRequest>,
146    ) -> Result<tonic::Response<GetProtocolConfigResponse>, tonic::Status> {
147        get_protocol_config::get_protocol_config(self, request.into_inner())
148            .map(tonic::Response::new)
149            .map_err(Into::into)
150    }
151
152    async fn list_checkpoints(
153        &self,
154        request: tonic::Request<ListCheckpointsRequest>,
155    ) -> Result<tonic::Response<BoxStream<ListCheckpointsResponse>>, tonic::Status> {
156        serve_list_stream(
157            "list_checkpoints",
158            self.config.ledger_history().list_checkpoints().timeout,
159            list_checkpoints::list_checkpoints(self.clone(), request.into_inner()),
160        )
161        .await
162    }
163
164    async fn list_transactions(
165        &self,
166        request: tonic::Request<ListTransactionsRequest>,
167    ) -> Result<tonic::Response<BoxStream<ListTransactionsResponse>>, tonic::Status> {
168        serve_list_stream(
169            "list_transactions",
170            self.config.ledger_history().list_transactions().timeout,
171            list_transactions::list_transactions(self.clone(), request.into_inner()),
172        )
173        .await
174    }
175
176    async fn list_events(
177        &self,
178        request: tonic::Request<ListEventsRequest>,
179    ) -> Result<tonic::Response<BoxStream<ListEventsResponse>>, tonic::Status> {
180        serve_list_stream(
181            "list_events",
182            self.config.ledger_history().list_events().timeout,
183            list_events::list_events(self.clone(), request.into_inner()),
184        )
185        .await
186    }
187}