Skip to content

Commit

Permalink
fix: check commitment id (#1388)
Browse files Browse the repository at this point in the history
* add check

* nit

* review
  • Loading branch information
Alex6323 authored May 8, 2024
1 parent ce85c16 commit 4a0ff69
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/bin/inx-chronicle/api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,20 @@ async fn commitment(
Path(commitment_id): Path<SlotCommitmentId>,
headers: HeaderMap,
) -> ApiResult<IotaRawResponse<SlotCommitment>> {
commitment_by_index(database, Path(commitment_id.slot_index()), headers).await
let slot_commitment = database
.collection::<CommittedSlotCollection>()
.get_commitment(commitment_id.slot_index())
.await?
.ok_or(MissingError::NoResults)?;

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(
Expand Down

0 comments on commit 4a0ff69

Please sign in to comment.