Skip to main content

espresso_api/generated/
espresso.api.v2.rest.rs

1// Auto-generated REST routes from proto `google.api.http` annotations.
2//
3// **Do not edit** - regenerated by `build.rs` when proto files change.
4//
5// Each handler transcodes HTTP/JSON <-> proto and calls the Tonic service trait,
6// sharing auth, validation, and business logic with gRPC handlers.
7
8use std::sync::Arc;
9
10use axum::extract::{Json, Query, State};
11use axum::http::HeaderMap;
12use axum::Router;
13
14// =============================================================================
15// StatusService REST routes
16// =============================================================================
17
18/// Build Axum REST routes for `StatusService`.
19///
20/// Generated from `google.api.http` annotations in `proto.proto`.
21pub fn status_service_rest_router<S>(service: Arc<S>) -> Router
22where
23    S: crate::proto::status_service_server::StatusService + Send + Sync + 'static,
24{
25    Router::new()
26        .route("/v2/status/block-height", axum::routing::get(rest_status_service_get_block_height::<S>))
27        .route("/v2/status/success-rate", axum::routing::get(rest_status_service_get_success_rate::<S>))
28        .route("/v2/status/time-since-last-decide", axum::routing::get(rest_status_service_get_time_since_last_decide::<S>))
29        .route("/v2/status/keys", axum::routing::get(rest_status_service_get_node_keys::<S>))
30        .with_state(service)
31}
32
33#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
34/// `GetBlockHeight` - JSON endpoint.
35///
36/// `GET /v2/status/block-height`
37async fn rest_status_service_get_block_height<S>(
38    State(service): State<Arc<S>>,
39    headers: HeaderMap,
40    Query(body): Query<crate::proto::GetBlockHeightRequest>,
41) -> Result<Json<crate::proto::BlockHeightResponse>, tonic_rest::RestError>
42where
43    S: crate::proto::status_service_server::StatusService + Send + Sync + 'static,
44{
45    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
46    let response = service.get_block_height(req).await.map_err(tonic_rest::RestError::from)?;
47    Ok(Json(response.into_inner()))
48}
49
50#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
51/// `GetSuccessRate` - JSON endpoint.
52///
53/// `GET /v2/status/success-rate`
54async fn rest_status_service_get_success_rate<S>(
55    State(service): State<Arc<S>>,
56    headers: HeaderMap,
57    Query(body): Query<crate::proto::GetSuccessRateRequest>,
58) -> Result<Json<crate::proto::SuccessRateResponse>, tonic_rest::RestError>
59where
60    S: crate::proto::status_service_server::StatusService + Send + Sync + 'static,
61{
62    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
63    let response = service.get_success_rate(req).await.map_err(tonic_rest::RestError::from)?;
64    Ok(Json(response.into_inner()))
65}
66
67#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
68/// `GetTimeSinceLastDecide` - JSON endpoint.
69///
70/// `GET /v2/status/time-since-last-decide`
71async fn rest_status_service_get_time_since_last_decide<S>(
72    State(service): State<Arc<S>>,
73    headers: HeaderMap,
74    Query(body): Query<crate::proto::GetTimeSinceLastDecideRequest>,
75) -> Result<Json<crate::proto::TimeSinceLastDecideResponse>, tonic_rest::RestError>
76where
77    S: crate::proto::status_service_server::StatusService + Send + Sync + 'static,
78{
79    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
80    let response = service.get_time_since_last_decide(req).await.map_err(tonic_rest::RestError::from)?;
81    Ok(Json(response.into_inner()))
82}
83
84#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
85/// `GetNodeKeys` - JSON endpoint.
86///
87/// `GET /v2/status/keys`
88async fn rest_status_service_get_node_keys<S>(
89    State(service): State<Arc<S>>,
90    headers: HeaderMap,
91    Query(body): Query<crate::proto::GetNodeKeysRequest>,
92) -> Result<Json<crate::proto::NodeKeysResponse>, tonic_rest::RestError>
93where
94    S: crate::proto::status_service_server::StatusService + Send + Sync + 'static,
95{
96    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
97    let response = service.get_node_keys(req).await.map_err(tonic_rest::RestError::from)?;
98    Ok(Json(response.into_inner()))
99}
100
101// =============================================================================
102// TokenService REST routes
103// =============================================================================
104
105/// Build Axum REST routes for `TokenService`.
106///
107/// Generated from `google.api.http` annotations in `proto.proto`.
108pub fn token_service_rest_router<S>(service: Arc<S>) -> Router
109where
110    S: crate::proto::token_service_server::TokenService + Send + Sync + 'static,
111{
112    Router::new()
113        .route("/v2/token/total-minted-supply", axum::routing::get(rest_token_service_get_total_minted_supply::<S>))
114        .route("/v2/token/circulating-supply", axum::routing::get(rest_token_service_get_circulating_supply::<S>))
115        .route("/v2/token/circulating-supply-ethereum", axum::routing::get(rest_token_service_get_circulating_supply_ethereum::<S>))
116        .route("/v2/token/total-issued-supply", axum::routing::get(rest_token_service_get_total_issued_supply::<S>))
117        .route("/v2/token/total-reward-distributed", axum::routing::get(rest_token_service_get_total_reward_distributed::<S>))
118        .with_state(service)
119}
120
121#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
122/// `GetTotalMintedSupply` - JSON endpoint.
123///
124/// `GET /v2/token/total-minted-supply`
125async fn rest_token_service_get_total_minted_supply<S>(
126    State(service): State<Arc<S>>,
127    headers: HeaderMap,
128    Query(body): Query<crate::proto::GetTotalMintedSupplyRequest>,
129) -> Result<Json<crate::proto::TotalMintedSupplyResponse>, tonic_rest::RestError>
130where
131    S: crate::proto::token_service_server::TokenService + Send + Sync + 'static,
132{
133    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
134    let response = service.get_total_minted_supply(req).await.map_err(tonic_rest::RestError::from)?;
135    Ok(Json(response.into_inner()))
136}
137
138#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
139/// `GetCirculatingSupply` - JSON endpoint.
140///
141/// `GET /v2/token/circulating-supply`
142async fn rest_token_service_get_circulating_supply<S>(
143    State(service): State<Arc<S>>,
144    headers: HeaderMap,
145    Query(body): Query<crate::proto::GetCirculatingSupplyRequest>,
146) -> Result<Json<crate::proto::CirculatingSupplyResponse>, tonic_rest::RestError>
147where
148    S: crate::proto::token_service_server::TokenService + Send + Sync + 'static,
149{
150    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
151    let response = service.get_circulating_supply(req).await.map_err(tonic_rest::RestError::from)?;
152    Ok(Json(response.into_inner()))
153}
154
155#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
156/// `GetCirculatingSupplyEthereum` - JSON endpoint.
157///
158/// `GET /v2/token/circulating-supply-ethereum`
159async fn rest_token_service_get_circulating_supply_ethereum<S>(
160    State(service): State<Arc<S>>,
161    headers: HeaderMap,
162    Query(body): Query<crate::proto::GetCirculatingSupplyEthereumRequest>,
163) -> Result<Json<crate::proto::CirculatingSupplyEthereumResponse>, tonic_rest::RestError>
164where
165    S: crate::proto::token_service_server::TokenService + Send + Sync + 'static,
166{
167    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
168    let response = service.get_circulating_supply_ethereum(req).await.map_err(tonic_rest::RestError::from)?;
169    Ok(Json(response.into_inner()))
170}
171
172#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
173/// `GetTotalIssuedSupply` - JSON endpoint.
174///
175/// `GET /v2/token/total-issued-supply`
176async fn rest_token_service_get_total_issued_supply<S>(
177    State(service): State<Arc<S>>,
178    headers: HeaderMap,
179    Query(body): Query<crate::proto::GetTotalIssuedSupplyRequest>,
180) -> Result<Json<crate::proto::TotalIssuedSupplyResponse>, tonic_rest::RestError>
181where
182    S: crate::proto::token_service_server::TokenService + Send + Sync + 'static,
183{
184    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
185    let response = service.get_total_issued_supply(req).await.map_err(tonic_rest::RestError::from)?;
186    Ok(Json(response.into_inner()))
187}
188
189#[expect(clippy::too_many_arguments, clippy::needless_pass_by_value)]
190/// `GetTotalRewardDistributed` - JSON endpoint.
191///
192/// `GET /v2/token/total-reward-distributed`
193async fn rest_token_service_get_total_reward_distributed<S>(
194    State(service): State<Arc<S>>,
195    headers: HeaderMap,
196    Query(body): Query<crate::proto::GetTotalRewardDistributedRequest>,
197) -> Result<Json<crate::proto::TotalRewardDistributedResponse>, tonic_rest::RestError>
198where
199    S: crate::proto::token_service_server::TokenService + Send + Sync + 'static,
200{
201    let req = tonic_rest::build_tonic_request::<_, ()>(body, &headers, None);
202    let response = service.get_total_reward_distributed(req).await.map_err(tonic_rest::RestError::from)?;
203    Ok(Json(response.into_inner()))
204}
205
206
207// =============================================================================
208// Public REST paths (bypass auth middleware)
209// =============================================================================
210
211/// REST paths that are marked as public (no authentication required).
212///
213/// Auto-generated from `google.api.http` annotations on public RPC methods.
214/// Used by middleware to identify unauthenticated endpoints.
215pub const PUBLIC_REST_PATHS: &[&str] = &[
216];
217
218// =============================================================================
219// Combined REST router
220// =============================================================================
221
222/// Build a combined Axum router with REST routes for all proto services.
223///
224/// Each service is generic - pass your concrete implementations as `Arc<T>`.
225pub fn all_rest_routes<S0, S1>(
226    status_service: Arc<S0>,
227    token_service: Arc<S1>,
228) -> Router
229where
230    S0: crate::proto::status_service_server::StatusService + Send + Sync + 'static,
231    S1: crate::proto::token_service_server::TokenService + Send + Sync + 'static,
232{
233    Router::new()
234        .merge(status_service_rest_router(status_service))
235        .merge(token_service_rest_router(token_service))
236}