@@ -6,8 +6,8 @@ use futures::{AsyncRead, AsyncWrite};
66use futures_util:: io:: { BufReader , BufWriter } ;
77use hyper_util:: rt:: TokioIo ;
88use pyth_lazer_protocol:: jrpc:: {
9- FeedUpdateParams , GetMetadataParams , JrpcCall , JrpcError , JrpcErrorResponse , JrpcResponse ,
10- JrpcSuccessResponse , JsonRpcVersion , PythLazerAgentJrpcV1 , SymbolMetadata ,
9+ FeedUpdateParams , GetMetadataParams , JrpcCall , JrpcError , JrpcErrorResponse , JrpcId ,
10+ JrpcResponse , JrpcSuccessResponse , JsonRpcVersion , PythLazerAgentJrpcV1 , SymbolMetadata ,
1111} ;
1212use soketto:: Sender ;
1313use soketto:: handshake:: http:: Server ;
@@ -83,7 +83,7 @@ async fn try_handle_jrpc(
8383 JrpcErrorResponse {
8484 jsonrpc : JsonRpcVersion :: V2 ,
8585 error : JrpcError :: InternalError ( err. to_string ( ) ) . into ( ) ,
86- id : None ,
86+ id : JrpcId :: Null ,
8787 } ,
8888 ) ) ?
8989 . as_str ( ) ,
@@ -103,18 +103,23 @@ async fn handle_jrpc_inner<T: AsyncRead + AsyncWrite + Unpin>(
103103 match serde_json:: from_slice :: < PythLazerAgentJrpcV1 > ( receive_buf. as_slice ( ) ) {
104104 Ok ( jrpc_request) => match jrpc_request. params {
105105 JrpcCall :: PushUpdate ( request_params) => {
106- handle_push_update ( sender, lazer_publisher, request_params, jrpc_request. id ) . await
106+ handle_push_update (
107+ sender,
108+ lazer_publisher,
109+ request_params,
110+ jrpc_request. id . clone ( ) ,
111+ )
112+ . await
107113 }
108114 JrpcCall :: PushUpdates ( request_params) => {
109115 for feed in request_params {
110- handle_push_update ( sender, lazer_publisher, feed, jrpc_request. id ) . await ?;
116+ handle_push_update ( sender, lazer_publisher, feed, jrpc_request. id . clone ( ) )
117+ . await ?;
111118 }
112119 Ok ( ( ) )
113120 }
114- JrpcCall :: GetMetadata ( request_params) => {
115- if let Some ( request_id) = jrpc_request. id {
116- handle_get_metadata ( sender, config, request_params, request_id) . await
117- } else {
121+ JrpcCall :: GetMetadata ( request_params) => match jrpc_request. id {
122+ JrpcId :: Null => {
118123 send_json (
119124 sender,
120125 & JrpcErrorResponse {
@@ -123,12 +128,13 @@ async fn handle_jrpc_inner<T: AsyncRead + AsyncWrite + Unpin>(
123128 "The request to method 'get_metadata' requires an 'id'" . to_string ( ) ,
124129 )
125130 . into ( ) ,
126- id : None ,
131+ id : JrpcId :: Null ,
127132 } ,
128133 )
129134 . await
130135 }
131- }
136+ _ => handle_get_metadata ( sender, config, request_params, jrpc_request. id ) . await ,
137+ } ,
132138 } ,
133139 Err ( err) => {
134140 debug ! ( "Error parsing JRPC request: {}" , err) ;
@@ -137,7 +143,7 @@ async fn handle_jrpc_inner<T: AsyncRead + AsyncWrite + Unpin>(
137143 & JrpcErrorResponse {
138144 jsonrpc : JsonRpcVersion :: V2 ,
139145 error : JrpcError :: ParseError ( err. to_string ( ) ) . into ( ) ,
140- id : None ,
146+ id : JrpcId :: Null ,
141147 } ,
142148 )
143149 . await
@@ -199,14 +205,15 @@ async fn handle_push_update<T: AsyncRead + AsyncWrite + Unpin>(
199205 sender : & mut Sender < T > ,
200206 lazer_publisher : & LazerPublisher ,
201207 request_params : FeedUpdateParams ,
202- request_id : Option < i64 > ,
208+ request_id : JrpcId ,
203209) -> anyhow:: Result < ( ) > {
204210 match lazer_publisher
205211 . push_feed_update ( request_params. clone ( ) . into ( ) )
206212 . await
207213 {
208- Ok ( _) => {
209- if let Some ( request_id) = request_id {
214+ Ok ( _) => match request_id {
215+ JrpcId :: Null => Ok ( ( ) ) ,
216+ _ => {
210217 send_json (
211218 sender,
212219 & JrpcSuccessResponse :: < String > {
@@ -216,10 +223,8 @@ async fn handle_push_update<T: AsyncRead + AsyncWrite + Unpin>(
216223 } ,
217224 )
218225 . await
219- } else {
220- Ok ( ( ) )
221226 }
222- }
227+ } ,
223228 Err ( err) => {
224229 debug ! ( "error while sending updates: {:?}" , err) ;
225230 send_json (
@@ -239,7 +244,7 @@ async fn handle_get_metadata<T: AsyncRead + AsyncWrite + Unpin>(
239244 sender : & mut Sender < T > ,
240245 config : & Config ,
241246 request_params : GetMetadataParams ,
242- request_id : i64 ,
247+ request_id : JrpcId ,
243248) -> anyhow:: Result < ( ) > {
244249 match get_metadata ( config. clone ( ) ) . await {
245250 Ok ( symbols) => {
@@ -262,7 +267,7 @@ async fn handle_get_metadata<T: AsyncRead + AsyncWrite + Unpin>(
262267 & JrpcErrorResponse {
263268 jsonrpc : JsonRpcVersion :: V2 ,
264269 error : JrpcError :: InternalError ( err. to_string ( ) ) . into ( ) ,
265- id : Some ( request_id) ,
270+ id : request_id,
266271 } ,
267272 )
268273 . await
0 commit comments