From 1835cd95b41ad1def9141b44cdf818cd06ff87d4 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 8 May 2024 12:36:19 +0200 Subject: [PATCH 1/3] add check --- src/bin/inx-chronicle/api/core/routes.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bin/inx-chronicle/api/core/routes.rs b/src/bin/inx-chronicle/api/core/routes.rs index 4663bdc29..2cf4502ee 100644 --- a/src/bin/inx-chronicle/api/core/routes.rs +++ b/src/bin/inx-chronicle/api/core/routes.rs @@ -333,6 +333,13 @@ async fn commitment( Path(commitment_id): Path, headers: HeaderMap, ) -> ApiResult> { + database + .collection::() + .get_id_for_slot_index(commitment_id.slot_index()) + .await? + .and_then(|id| (id == commitment_id).then_some(id)) + .ok_or(MissingError::NoResults)?; + commitment_by_index(database, Path(commitment_id.slot_index()), headers).await } From 4ac05bfd2f89392f25f91082440f9528eef28ca2 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 8 May 2024 13:03:41 +0200 Subject: [PATCH 2/3] nit --- src/bin/inx-chronicle/api/core/routes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/inx-chronicle/api/core/routes.rs b/src/bin/inx-chronicle/api/core/routes.rs index 2cf4502ee..134f6abfa 100644 --- a/src/bin/inx-chronicle/api/core/routes.rs +++ b/src/bin/inx-chronicle/api/core/routes.rs @@ -337,7 +337,7 @@ async fn commitment( .collection::() .get_id_for_slot_index(commitment_id.slot_index()) .await? - .and_then(|id| (id == commitment_id).then_some(id)) + .and_then(|id| (id == commitment_id).then_some(())) .ok_or(MissingError::NoResults)?; commitment_by_index(database, Path(commitment_id.slot_index()), headers).await From 7a4f4d21562d66d51e715e414ac209a79fbc6506 Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Wed, 8 May 2024 15:04:49 +0200 Subject: [PATCH 3/3] review --- src/bin/inx-chronicle/api/core/routes.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/bin/inx-chronicle/api/core/routes.rs b/src/bin/inx-chronicle/api/core/routes.rs index 134f6abfa..7be2eb370 100644 --- a/src/bin/inx-chronicle/api/core/routes.rs +++ b/src/bin/inx-chronicle/api/core/routes.rs @@ -333,14 +333,20 @@ async fn commitment( Path(commitment_id): Path, headers: HeaderMap, ) -> ApiResult> { - database + let slot_commitment = database .collection::() - .get_id_for_slot_index(commitment_id.slot_index()) + .get_commitment(commitment_id.slot_index()) .await? - .and_then(|id| (id == commitment_id).then_some(())) .ok_or(MissingError::NoResults)?; - commitment_by_index(database, Path(commitment_id.slot_index()), headers).await + if slot_commitment.commitment_id != commitment_id { + return Err(ApiError::from(MissingError::NoResults)); + } + + if matches!(headers.get(axum::http::header::ACCEPT), Some(header) if header == BYTE_CONTENT_HEADER) { + return Ok(IotaRawResponse::Raw(slot_commitment.commitment.data())); + } + Ok(IotaRawResponse::Json(slot_commitment.commitment.into_inner())) } async fn commitment_by_index(