Skip to content

Commit

Permalink
feat(node): add hash operation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
zcabter committed Nov 29, 2024
1 parent 646ba92 commit 486a54f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
37 changes: 37 additions & 0 deletions crates/jstz_node/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
22 changes: 20 additions & 2 deletions crates/jstz_node/src/services/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Operation>,
) -> ServiceResult<Json<OperationHash>> {
Ok(Json(operation.hash()))
}

impl Service for OperationsService {
fn router_with_openapi() -> OpenApiRouter<AppState> {
let routes = OpenApiRouter::new()
.routes(routes!(inject))
.routes(routes!(receipt));
.routes(routes!(receipt))
.routes(routes!(hash_operation));

OpenApiRouter::new().nest("/operations", routes)
}
Expand Down

0 comments on commit 486a54f

Please sign in to comment.