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