Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.17.0" }
pyth-lazer-protocol = { path = "../../../../sdk/rust/protocol", version = "0.18.0" }

anchor-lang = "0.31.1"
bytemuck = { version = "1.20.0", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions lazer/publisher_sdk/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "pyth-lazer-publisher-sdk"
version = "0.15.0"
version = "0.16.0"
edition = "2021"
description = "Pyth Lazer Publisher SDK types."
license = "Apache-2.0"
repository = "https://github.com/pyth-network/pyth-crosschain"

[dependencies]
pyth-lazer-protocol = { version = "0.17.0", path = "../../sdk/rust/protocol" }
pyth-lazer-protocol = { version = "0.18.0", path = "../../sdk/rust/protocol" }
anyhow = "1.0.98"
protobuf = "3.7.2"
serde_json = "1.0.140"
Expand Down
4 changes: 2 additions & 2 deletions lazer/sdk/rust/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "pyth-lazer-client"
version = "8.3.0"
version = "8.4.0"
edition = "2021"
description = "A Rust client for Pyth Lazer"
license = "Apache-2.0"

[dependencies]
pyth-lazer-protocol = { path = "../protocol", version = "0.17.0" }
pyth-lazer-protocol = { path = "../protocol", version = "0.18.0" }
tokio = { version = "1", features = ["full"] }
tokio-tungstenite = { version = "0.20", features = ["native-tls"] }
futures-util = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion lazer/sdk/rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-lazer-protocol"
version = "0.17.0"
version = "0.18.0"
edition = "2021"
description = "Pyth Lazer SDK - protocol types."
license = "Apache-2.0"
Expand Down
113 changes: 107 additions & 6 deletions lazer/sdk/rust/protocol/src/jrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ pub enum JrpcResponse<T> {
pub struct JrpcSuccessResponse<T> {
pub jsonrpc: JsonRpcVersion,
pub result: T,
pub id: i64,
pub id: JrpcId,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
pub struct JrpcErrorResponse {
pub jsonrpc: JsonRpcVersion,
pub error: JrpcErrorObject,
pub id: Option<i64>,
pub id: JrpcId,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -523,7 +523,37 @@ mod tests {
message: "Internal error".to_string(),
data: None,
},
id: Some(2),
id: JrpcId::Int(2),
}
);
}

#[test]
fn test_response_format_error_string_id() {
let response = serde_json::from_str::<JrpcErrorResponse>(
r#"
{
"jsonrpc": "2.0",
"id": "62b627dc-5599-43dd-b2c2-9c4d30f4fdb4",
"error": {
"message": "Internal error",
"code": -32603
}
}
"#,
)
.unwrap();

assert_eq!(
response,
JrpcErrorResponse {
jsonrpc: JsonRpcVersion::V2,
error: JrpcErrorObject {
code: -32603,
message: "Internal error".to_string(),
data: None,
},
id: JrpcId::String("62b627dc-5599-43dd-b2c2-9c4d30f4fdb4".to_string())
}
);
}
Expand All @@ -546,7 +576,30 @@ mod tests {
JrpcSuccessResponse::<String> {
jsonrpc: JsonRpcVersion::V2,
result: "success".to_string(),
id: 2,
id: JrpcId::Int(2),
}
);
}

#[test]
pub fn test_response_format_success_string_id() {
let response = serde_json::from_str::<JrpcSuccessResponse<String>>(
r#"
{
"jsonrpc": "2.0",
"id": "62b627dc-5599-43dd-b2c2-9c4d30f4fdb4",
"result": "success"
}
"#,
)
.unwrap();

assert_eq!(
response,
JrpcSuccessResponse::<String> {
jsonrpc: JsonRpcVersion::V2,
result: "success".to_string(),
id: JrpcId::String("62b627dc-5599-43dd-b2c2-9c4d30f4fdb4".to_string()),
}
);
}
Expand All @@ -568,7 +621,7 @@ mod tests {
JrpcResponse::Success(JrpcSuccessResponse::<String> {
jsonrpc: JsonRpcVersion::V2,
result: "success".to_string(),
id: 2,
id: JrpcId::Int(2),
})
);

Expand All @@ -594,7 +647,55 @@ mod tests {
message: "Internal error".to_string(),
data: None,
},
id: Some(3),
id: JrpcId::Int(3),
})
);
}

#[test]
pub fn test_parse_response_string_id() {
let success_response = serde_json::from_str::<JrpcResponse<String>>(
r#"
{
"jsonrpc": "2.0",
"id": "id-2",
"result": "success"
}"#,
)
.unwrap();

assert_eq!(
success_response,
JrpcResponse::Success(JrpcSuccessResponse::<String> {
jsonrpc: JsonRpcVersion::V2,
result: "success".to_string(),
id: JrpcId::String("id-2".to_string()),
})
);

let error_response = serde_json::from_str::<JrpcResponse<String>>(
r#"
{
"jsonrpc": "2.0",
"id": "id-3",
"error": {
"code": -32603,
"message": "Internal error"
}
}"#,
)
.unwrap();

assert_eq!(
error_response,
JrpcResponse::Error(JrpcErrorResponse {
jsonrpc: JsonRpcVersion::V2,
error: JrpcErrorObject {
code: -32603,
message: "Internal error".to_string(),
data: None,
},
id: JrpcId::String("id-3".to_string()),
})
);
}
Expand Down