diff --git a/catalyst-gateway/bin/src/service/api/fragments/mod.rs b/catalyst-gateway/bin/src/service/api/fragments/mod.rs deleted file mode 100644 index c1e2d8ee3dd..00000000000 --- a/catalyst-gateway/bin/src/service/api/fragments/mod.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Fragment endpoints - -mod index; -mod statuses; - -use poem_openapi::{param::Query, payload::Json, OpenApi}; - -use self::statuses::FragmentIds; -use crate::service::common::{objects::fragments_batch::FragmentsBatch, tags::ApiTags}; - -/// All Responses -pub(crate) struct FragmentsApi; - -#[OpenApi(prefix_path = "/v1/fragments", tag = "ApiTags::Fragments")] -impl FragmentsApi { - /// Process fragments - /// - /// Posts a fragments batch to be processed. - #[oai(path = "/", method = "post", operation_id = "fragments")] - async fn index( - &self, - /// Batch of fragments to be processed. - Json(fragments_batch): Json, - ) -> index::AllResponses { - index::endpoint(fragments_batch).await - } - - /// Get Fragment Statuses - /// - /// Get statuses of the fragments with the given ids. - #[oai(path = "/statuses", method = "get", operation_id = "fragmentsStatuses")] - async fn statuses( - &self, - /// Comma-separated list of fragment ids for which the statuses will - /// be retrieved. - Query(fragment_ids): Query, - ) -> statuses::AllResponses { - statuses::endpoint(fragment_ids).await - } -} diff --git a/catalyst-gateway/bin/src/service/api/mod.rs b/catalyst-gateway/bin/src/service/api/mod.rs index ebdd7b058f3..6a2828cbb9d 100644 --- a/catalyst-gateway/bin/src/service/api/mod.rs +++ b/catalyst-gateway/bin/src/service/api/mod.rs @@ -9,10 +9,8 @@ use test_endpoints::TestApi; use v0::V0Api; use v1::V1Api; -use self::fragments::FragmentsApi; use crate::settings::API_URL_PREFIX; -mod fragments; mod health; mod registration; mod test_endpoints; @@ -65,26 +63,9 @@ const TERMS_OF_SERVICE: &str = /// Create the `OpenAPI` definition pub(crate) fn mk_api( hosts: Vec, -) -> OpenApiService< - ( - TestApi, - HealthApi, - RegistrationApi, - V0Api, - V1Api, - FragmentsApi, - ), - (), -> { +) -> OpenApiService<(TestApi, HealthApi, RegistrationApi, V0Api, V1Api), ()> { let mut service = OpenApiService::new( - ( - TestApi, - HealthApi, - RegistrationApi, - V0Api, - V1Api, - FragmentsApi, - ), + (TestApi, HealthApi, RegistrationApi, V0Api, V1Api), API_TITLE, API_VERSION, ) diff --git a/catalyst-gateway/bin/src/service/api/fragments/index.rs b/catalyst-gateway/bin/src/service/api/v1/fragments_post.rs similarity index 100% rename from catalyst-gateway/bin/src/service/api/fragments/index.rs rename to catalyst-gateway/bin/src/service/api/v1/fragments_post.rs diff --git a/catalyst-gateway/bin/src/service/api/fragments/statuses.rs b/catalyst-gateway/bin/src/service/api/v1/fragments_statuses.rs similarity index 100% rename from catalyst-gateway/bin/src/service/api/fragments/statuses.rs rename to catalyst-gateway/bin/src/service/api/v1/fragments_statuses.rs diff --git a/catalyst-gateway/bin/src/service/api/v1/mod.rs b/catalyst-gateway/bin/src/service/api/v1/mod.rs index aaf7e875c5b..654c46b10f5 100644 --- a/catalyst-gateway/bin/src/service/api/v1/mod.rs +++ b/catalyst-gateway/bin/src/service/api/v1/mod.rs @@ -3,14 +3,19 @@ use std::sync::Arc; use poem::web::{Data, Path}; -use poem_openapi::OpenApi; +use poem_openapi::{param::Query, payload::Json, OpenApi}; use crate::{ - service::common::{objects::account_votes::AccountId, tags::ApiTags}, + service::common::{ + objects::{account_votes::AccountId, fragments_batch::FragmentsBatch}, + tags::ApiTags, + }, state::State, }; mod account_votes_get; +mod fragments_post; +mod fragments_statuses; /// V1 API Endpoints pub(crate) struct V1Api; @@ -29,4 +34,39 @@ impl V1Api { ) -> account_votes_get::AllResponses { account_votes_get::endpoint(state, account_id).await } + + /// Process fragments + /// + /// Posts a fragments batch to be processed. + #[oai( + path = "/fragments", + method = "post", + operation_id = "fragments", + tag = "ApiTags::Fragments" + )] + async fn fragments_post( + &self, + /// Batch of fragments to be processed. + Json(fragments_batch): Json, + ) -> fragments_post::AllResponses { + fragments_post::endpoint(fragments_batch).await + } + + /// Get Fragment Statuses + /// + /// Get statuses of the fragments with the given ids. + #[oai( + path = "/fragments/statuses", + method = "get", + operation_id = "fragmentsStatuses", + tag = "ApiTags::Fragments" + )] + async fn fragments_statuses( + &self, + /// Comma-separated list of fragment ids for which the statuses will + /// be retrieved. + Query(fragment_ids): Query, + ) -> fragments_statuses::AllResponses { + fragments_statuses::endpoint(fragment_ids).await + } } diff --git a/catalyst-gateway/bin/src/service/common/objects/fragment_status.rs b/catalyst-gateway/bin/src/service/common/objects/fragment_status.rs index c7a875e3baf..8318b7b54bb 100644 --- a/catalyst-gateway/bin/src/service/common/objects/fragment_status.rs +++ b/catalyst-gateway/bin/src/service/common/objects/fragment_status.rs @@ -28,14 +28,14 @@ impl Example for StatusRejected { /// Fragment is included in a block. pub(crate) struct StatusInABlock { pub date: BlockDate, - pub hash: Hash, + pub block: Hash, } impl Example for StatusInABlock { fn example() -> Self { Self { date: BlockDate::example(), - hash: Hash::example(), + block: Hash::example(), } } } diff --git a/catalyst-gateway/bin/src/service/common/objects/hash.rs b/catalyst-gateway/bin/src/service/common/objects/hash.rs index f8891aee49d..ac8093bd9d9 100644 --- a/catalyst-gateway/bin/src/service/common/objects/hash.rs +++ b/catalyst-gateway/bin/src/service/common/objects/hash.rs @@ -5,6 +5,7 @@ use poem_openapi::{types::Example, Object}; /// Blake2b256 hash wrapper. pub(crate) struct Hash { /// Blake2b256 hash encoded in hex. +#[oai(validator(max_length = 64, min_length = 64, pattern = "[0-9a-f]{64}"))] pub hash: String, }