@@ -926,6 +926,13 @@ pub async fn channel_payout<C: Locked + 'static>(
926
926
} ) ?) )
927
927
}
928
928
929
+ /// POST `/v5/channel/dummy-deposit` request
930
+ ///
931
+ /// Full details about the route's API and intend can be found in the [`routes`](crate::routes#post-v5channeldummy-deposit-auth-required) module
932
+ ///
933
+ /// Request body (json): [`ChannelDummyDeposit`]
934
+ ///
935
+ /// Response: [`SuccessResponse`]
929
936
pub async fn channel_dummy_deposit_axum < C : Locked + ' static > (
930
937
Extension ( app) : Extension < Arc < Application < C > > > ,
931
938
Extension ( auth) : Extension < Auth > ,
@@ -1016,7 +1023,10 @@ pub async fn channel_dummy_deposit<C: Locked + 'static>(
1016
1023
/// starting with `/v5/channel/0xXXX.../validator-messages`
1017
1024
///
1018
1025
pub mod validator_message {
1026
+ use std:: sync:: Arc ;
1027
+
1019
1028
use crate :: {
1029
+ application:: Qs ,
1020
1030
db:: validator_message:: { get_validator_messages, insert_validator_message} ,
1021
1031
Auth ,
1022
1032
} ;
@@ -1025,15 +1035,17 @@ pub mod validator_message {
1025
1035
Application ,
1026
1036
} ;
1027
1037
use adapter:: client:: Locked ;
1038
+ use axum:: { extract:: Path , Extension , Json } ;
1028
1039
use futures:: future:: try_join_all;
1029
1040
use hyper:: { Body , Request , Response } ;
1030
1041
use primitives:: {
1031
1042
sentry:: {
1032
1043
SuccessResponse , ValidatorMessagesCreateRequest , ValidatorMessagesListQuery ,
1033
1044
ValidatorMessagesListResponse ,
1034
1045
} ,
1035
- ChainOf , Channel , DomainError , ValidatorId ,
1046
+ ChainOf , Channel , ChannelId , DomainError , ValidatorId ,
1036
1047
} ;
1048
+ use serde:: Deserialize ;
1037
1049
1038
1050
pub fn extract_params (
1039
1051
from_path : & str ,
@@ -1065,6 +1077,108 @@ pub mod validator_message {
1065
1077
Ok ( ( validator_id, message_types. unwrap_or_default ( ) ) )
1066
1078
}
1067
1079
1080
+ #[ derive( Debug , Deserialize ) ]
1081
+ pub struct MessagesListParams {
1082
+ pub id : ChannelId ,
1083
+ // Optional filtering by ValidatorId
1084
+ #[ serde( default ) ]
1085
+ pub address : Option < ValidatorId > ,
1086
+ /// List of validator message types separated by `+` (urlencoded):
1087
+ /// e.g. `ApproveState+NewState`
1088
+ #[ serde( default ) ]
1089
+ pub message_types : String ,
1090
+ }
1091
+
1092
+ /// GET `/v5/channel/0xXXX.../validator-messages`
1093
+ ///
1094
+ /// Full details about the route's API and intend can be found in the [`routes`](crate::routes#get-v5channelidvalidator-messages) module
1095
+ ///
1096
+ /// Request query parameters: [`ValidatorMessagesListQuery`]
1097
+ ///
1098
+ /// Response: [`ValidatorMessagesListResponse`]
1099
+ ///
1100
+ pub async fn list_validator_messages_axum < C : Locked + ' static > (
1101
+ Extension ( app) : Extension < Arc < Application < C > > > ,
1102
+ Extension ( channel_context) : Extension < ChainOf < Channel > > ,
1103
+ Path ( params) : Path < MessagesListParams > ,
1104
+ Qs ( query) : Qs < ValidatorMessagesListQuery > ,
1105
+ ) -> Result < Json < ValidatorMessagesListResponse > , ResponseError > {
1106
+ let message_types = {
1107
+ // We need to strip the `/` prefix from axum
1108
+ let stripped = params
1109
+ . message_types
1110
+ . strip_prefix ( '/' )
1111
+ . unwrap_or ( & params. message_types ) ;
1112
+
1113
+ if !stripped. is_empty ( ) {
1114
+ stripped
1115
+ . split ( '+' )
1116
+ . map ( |s| s. to_string ( ) )
1117
+ . collect :: < Vec < _ > > ( )
1118
+ } else {
1119
+ vec ! [ ]
1120
+ }
1121
+ } ;
1122
+
1123
+ let channel = channel_context. context ;
1124
+
1125
+ let config_limit = app. config . msgs_find_limit as u64 ;
1126
+ let limit = query
1127
+ . limit
1128
+ . filter ( |n| * n >= 1 )
1129
+ . unwrap_or ( config_limit)
1130
+ . min ( config_limit) ;
1131
+
1132
+ let validator_messages = get_validator_messages (
1133
+ & app. pool ,
1134
+ & channel. id ( ) ,
1135
+ & params. address ,
1136
+ & message_types,
1137
+ limit,
1138
+ )
1139
+ . await ?;
1140
+
1141
+ Ok ( Json ( ValidatorMessagesListResponse {
1142
+ messages : validator_messages,
1143
+ } ) )
1144
+ }
1145
+
1146
+ /// POST `/v5/channel/0xXXX.../validator-messages`
1147
+ ///
1148
+ /// Full details about the route's API and intend can be found in the [`routes`](crate::routes#post-v5channelidvalidator-messages-auth-required) module
1149
+ ///
1150
+ /// Request body (json): [`ValidatorMessagesCreateRequest`]
1151
+ ///
1152
+ /// Response: [`SuccessResponse`]
1153
+ ///
1154
+ /// # Examples
1155
+ ///
1156
+ /// Request:
1157
+ ///
1158
+ /// ```
1159
+ #[ doc = include_str ! ( "../../../primitives/examples/validator_messages_create_request.rs" ) ]
1160
+ /// ```
1161
+ pub async fn create_validator_messages_axum < C : Locked + ' static > (
1162
+ Extension ( app) : Extension < Arc < Application < C > > > ,
1163
+ Extension ( auth) : Extension < Auth > ,
1164
+ Extension ( channel_context) : Extension < ChainOf < Channel > > ,
1165
+ Json ( create_request) : Json < ValidatorMessagesCreateRequest > ,
1166
+ ) -> Result < Json < SuccessResponse > , ResponseError > {
1167
+ let channel = channel_context. context ;
1168
+
1169
+ match channel. find_validator ( auth. uid ) {
1170
+ None => Err ( ResponseError :: Unauthorized ) ,
1171
+ _ => {
1172
+ try_join_all ( create_request. messages . iter ( ) . map ( |message| {
1173
+ insert_validator_message ( & app. pool , & channel, & auth. uid , message)
1174
+ } ) )
1175
+ . await ?;
1176
+
1177
+ Ok ( Json ( SuccessResponse { success : true } ) )
1178
+ }
1179
+ }
1180
+ }
1181
+
1068
1182
/// GET `/v5/channel/0xXXX.../validator-messages`
1069
1183
///
1070
1184
/// Full details about the route's API and intend can be found in the [`routes`](crate::routes#get-v5channelidvalidator-messages) module
0 commit comments