Skip to content

Commit d44bbdb

Browse files
committed
sentry - routes - channel - list validator messages
1 parent fc90898 commit d44bbdb

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

sentry/src/routes/channel.rs

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,13 @@ pub async fn channel_payout<C: Locked + 'static>(
688688
})?))
689689
}
690690

691+
/// POST `/v5/channel/dummy-deposit` request
692+
///
693+
/// Full details about the route's API and intend can be found in the [`routes`](crate::routes#post-v5channeldummy-deposit-auth-required) module
694+
///
695+
/// Request body (json): [`ChannelDummyDeposit`]
696+
///
697+
/// Response: [`SuccessResponse`]
691698
pub async fn channel_dummy_deposit_axum<C: Locked + 'static>(
692699
Extension(app): Extension<Arc<Application<C>>>,
693700
Extension(auth): Extension<Auth>,
@@ -778,7 +785,10 @@ pub async fn channel_dummy_deposit<C: Locked + 'static>(
778785
/// starting with `/v5/channel/0xXXX.../validator-messages`
779786
///
780787
pub mod validator_message {
788+
use std::sync::Arc;
789+
781790
use crate::{
791+
application::Qs,
782792
db::validator_message::{get_validator_messages, insert_validator_message},
783793
Auth,
784794
};
@@ -787,15 +797,17 @@ pub mod validator_message {
787797
Application,
788798
};
789799
use adapter::client::Locked;
800+
use axum::{extract::Path, Extension, Json};
790801
use futures::future::try_join_all;
791802
use hyper::{Body, Request, Response};
792803
use primitives::{
793804
sentry::{
794805
SuccessResponse, ValidatorMessagesCreateRequest, ValidatorMessagesListQuery,
795806
ValidatorMessagesListResponse,
796807
},
797-
ChainOf, Channel, DomainError, ValidatorId,
808+
ChainOf, Channel, ChannelId, DomainError, ValidatorId,
798809
};
810+
use serde::Deserialize;
799811

800812
pub fn extract_params(
801813
from_path: &str,
@@ -827,6 +839,72 @@ pub mod validator_message {
827839
Ok((validator_id, message_types.unwrap_or_default()))
828840
}
829841

842+
#[derive(Debug, Deserialize)]
843+
pub struct MessagesListParams {
844+
pub id: ChannelId,
845+
// Optional filtering by ValidatorId
846+
#[serde(default)]
847+
pub address: Option<ValidatorId>,
848+
/// List of validator message types separated by `+` (urlencoded):
849+
/// e.g. `ApproveState+NewState`
850+
#[serde(default)]
851+
pub message_types: String,
852+
}
853+
854+
/// GET `/v5/channel/0xXXX.../validator-messages`
855+
///
856+
/// Full details about the route's API and intend can be found in the [`routes`](crate::routes#get-v5channelidvalidator-messages) module
857+
///
858+
/// Request query parameters: [`ValidatorMessagesListQuery`]
859+
///
860+
/// Response: [`ValidatorMessagesListResponse`]
861+
///
862+
pub async fn list_validator_messages_axum<C: Locked + 'static>(
863+
Extension(app): Extension<Arc<Application<C>>>,
864+
Extension(channel_context): Extension<ChainOf<Channel>>,
865+
Path(params): Path<MessagesListParams>,
866+
Qs(query): Qs<ValidatorMessagesListQuery>,
867+
) -> Result<Json<ValidatorMessagesListResponse>, ResponseError> {
868+
let message_types = {
869+
// We need to strip the `/` prefix from axum
870+
let stripped = params
871+
.message_types
872+
.strip_prefix('/')
873+
.unwrap_or(&params.message_types);
874+
875+
if !stripped.is_empty() {
876+
stripped
877+
.split('+')
878+
.map(|s| s.to_string())
879+
.collect::<Vec<_>>()
880+
} else {
881+
vec![]
882+
}
883+
};
884+
885+
let channel = channel_context.context;
886+
887+
let config_limit = app.config.msgs_find_limit as u64;
888+
let limit = query
889+
.limit
890+
.filter(|n| *n >= 1)
891+
.unwrap_or(config_limit)
892+
.min(config_limit);
893+
894+
let validator_messages = get_validator_messages(
895+
&app.pool,
896+
&channel.id(),
897+
&params.address,
898+
&message_types,
899+
limit,
900+
)
901+
.await?;
902+
903+
Ok(Json(ValidatorMessagesListResponse {
904+
messages: validator_messages,
905+
}))
906+
}
907+
830908
/// GET `/v5/channel/0xXXX.../validator-messages`
831909
///
832910
/// 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: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ use tower::ServiceBuilder;
5656

5757
use super::{
5858
analytics::{analytics_axum, GET_ANALYTICS_ALLOWED_KEYS},
59-
channel::{channel_dummy_deposit_axum, channel_list_axum, channel_payout_axum},
59+
channel::{
60+
channel_dummy_deposit_axum, channel_list_axum, channel_payout_axum,
61+
validator_message::list_validator_messages_axum,
62+
},
6063
units_for_slot::post_units_for_slot,
6164
};
6265

@@ -146,6 +149,15 @@ pub fn channels_router_axum<C: Locked + 'static>() -> Router {
146149
post(channel_payout_axum::<C>)
147150
.route_layer(middleware::from_fn(authentication_required::<C, _>)),
148151
)
152+
.route(
153+
"/validator-messages",
154+
get(list_validator_messages_axum::<C>),
155+
)
156+
// We allow Message Type filtering only when filtering by a ValidatorId
157+
.route(
158+
"/validator-messages/:address/*message_types",
159+
get(list_validator_messages_axum::<C>),
160+
)
149161
.layer(
150162
// keeps the order from top to bottom!
151163
ServiceBuilder::new()

0 commit comments

Comments
 (0)