diff --git a/crates/jstz_node/openapi.json b/crates/jstz_node/openapi.json index e522e7c25..1af175241 100644 --- a/crates/jstz_node/openapi.json +++ b/crates/jstz_node/openapi.json @@ -378,6 +378,43 @@ } } }, + "/operations/hash": { + "post": { + "tags": [ + "Operations" + ], + "summary": "Returns the hash of an Operation", + "operationId": "hash_operation", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Operation" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Blake2b" + } + } + } + }, + "400": { + "description": "" + }, + "500": { + "description": "" + } + } + } + }, "/operations/{operation_hash}/receipt": { "get": { "tags": [ diff --git a/crates/jstz_node/src/services/operations.rs b/crates/jstz_node/src/services/operations.rs index 16c999254..0187aaa73 100644 --- a/crates/jstz_node/src/services/operations.rs +++ b/crates/jstz_node/src/services/operations.rs @@ -5,7 +5,7 @@ use axum::{ extract::{Path, State}, Json, }; -use jstz_proto::operation::SignedOperation; +use jstz_proto::operation::{Operation, OperationHash, SignedOperation}; use jstz_proto::receipt::Receipt; use tezos_data_encoding::enc::BinWriter; use tezos_smart_rollup::inbox::ExternalMessageFrame; @@ -78,11 +78,29 @@ async fn receipt( Ok(Json(receipt)) } +/// Returns the hash of an Operation +#[utoipa::path( + post, + path = "/hash", + tag = OPERATIONS_TAG, + responses( + (status = 200, body = OperationHash), + (status = 400), + (status = 500) + ) + )] +async fn hash_operation( + Json(operation): Json, +) -> ServiceResult> { + Ok(Json(operation.hash())) +} + impl Service for OperationsService { fn router_with_openapi() -> OpenApiRouter { let routes = OpenApiRouter::new() .routes(routes!(inject)) - .routes(routes!(receipt)); + .routes(routes!(receipt)) + .routes(routes!(hash_operation)); OpenApiRouter::new().nest("/operations", routes) }