Skip to content

Commit 5c1a435

Browse files
authored
fix(pyth-lazer-agent): Support jrpc string ids
2 parents dde5629 + b6cce6c commit 5c1a435

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/pyth-lazer-agent/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "pyth-lazer-agent"
3-
version = "0.5.2"
3+
version = "0.6.0"
44
edition = "2024"
55
description = "Pyth Lazer Agent"
66
license = "Apache-2.0"
77
repository = "https://github.com/pyth-network/pyth-crosschain"
88

99
[dependencies]
10-
pyth-lazer-publisher-sdk = "0.12.1"
11-
pyth-lazer-protocol = "0.15.1"
10+
pyth-lazer-publisher-sdk = "0.16.1"
11+
pyth-lazer-protocol = "0.18.1"
1212

1313
anyhow = "1.0.98"
1414
backoff = "0.4.0"

apps/pyth-lazer-agent/src/jrpc_handle.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use futures::{AsyncRead, AsyncWrite};
66
use futures_util::io::{BufReader, BufWriter};
77
use hyper_util::rt::TokioIo;
88
use 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
};
1212
use soketto::Sender;
1313
use 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

Comments
 (0)