Skip to content

Commit fc9aa73

Browse files
committed
sentry - routes - create validator messages
1 parent 83325d2 commit fc9aa73

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

sentry/src/routes/channel.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,42 @@ pub mod validator_message {
905905
}))
906906
}
907907

908+
/// POST `/v5/channel/0xXXX.../validator-messages`
909+
///
910+
/// Full details about the route's API and intend can be found in the [`routes`](crate::routes#post-v5channelidvalidator-messages-auth-required) module
911+
///
912+
/// Request body (json): [`ValidatorMessagesCreateRequest`]
913+
///
914+
/// Response: [`SuccessResponse`]
915+
///
916+
/// # Examples
917+
///
918+
/// Request:
919+
///
920+
/// ```
921+
#[doc = include_str!("../../../primitives/examples/validator_messages_create_request.rs")]
922+
/// ```
923+
pub async fn create_validator_messages_axum<C: Locked + 'static>(
924+
Extension(app): Extension<Arc<Application<C>>>,
925+
Extension(auth): Extension<Auth>,
926+
Extension(channel_context): Extension<ChainOf<Channel>>,
927+
Json(create_request): Json<ValidatorMessagesCreateRequest>,
928+
) -> Result<Json<SuccessResponse>, ResponseError> {
929+
let channel = channel_context.context;
930+
931+
match channel.find_validator(auth.uid) {
932+
None => Err(ResponseError::Unauthorized),
933+
_ => {
934+
try_join_all(create_request.messages.iter().map(|message| {
935+
insert_validator_message(&app.pool, &channel, &auth.uid, message)
936+
}))
937+
.await?;
938+
939+
Ok(Json(SuccessResponse { success: true }))
940+
}
941+
}
942+
}
943+
908944
/// GET `/v5/channel/0xXXX.../validator-messages`
909945
///
910946
/// Full details about the route's API and intend can be found in the [`routes`](crate::routes#get-v5channelidvalidator-messages) module

sentry/src/routes/routers.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use super::{
5858
analytics::{analytics_axum, GET_ANALYTICS_ALLOWED_KEYS},
5959
channel::{
6060
channel_dummy_deposit_axum, channel_list_axum, channel_payout_axum,
61-
validator_message::list_validator_messages_axum,
61+
validator_message::{create_validator_messages_axum, list_validator_messages_axum},
6262
},
6363
units_for_slot::post_units_for_slot,
6464
};
@@ -149,6 +149,11 @@ pub fn channels_router_axum<C: Locked + 'static>() -> Router {
149149
post(channel_payout_axum::<C>)
150150
.route_layer(middleware::from_fn(authentication_required::<C, _>)),
151151
)
152+
.route(
153+
"/validator-messages",
154+
post(create_validator_messages_axum::<C>)
155+
.route_layer(middleware::from_fn(authentication_required::<C, _>)),
156+
)
152157
.route(
153158
"/validator-messages",
154159
get(list_validator_messages_axum::<C>),

0 commit comments

Comments
 (0)