Skip to content

Commit

Permalink
fix binary stream
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-wang-cb committed Feb 24, 2025
1 parent 3854e5f commit 4b60c98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ tracing = { version = "0.1.41" }
serde = "1"
serde_json = "1.0"
url = "2.5"
metrics = "0.24.1"
metrics-derive = "0.1"

[features]
default = ["optimism"]
Expand Down
17 changes: 13 additions & 4 deletions src/flashblocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ impl FlashblocksClient {
// Handle incoming messages
while let Some(msg) = read.next().await {
match msg {
Ok(Message::Text(text)) => {
Ok(Message::Binary(bytes)) => {
// Decode binary message to string first
let text = match String::from_utf8(bytes.to_vec()) {
Ok(text) => text,
Err(e) => {
error!("Failed to decode binary message: {}", e);
continue;
}
};

// Then parse JSON
let payload: FlashblocksPayloadV1 =
match serde_json::from_str(&text) {
Ok(m) => m,
Expand All @@ -79,9 +89,8 @@ impl FlashblocksClient {
}
};

let _ = sender
.send(ActorMessage::BestPayload { payload: payload })
.await;
let _ =
sender.send(ActorMessage::BestPayload { payload }).await;
}
Ok(Message::Close(_)) => break,
Err(e) => {
Expand Down

0 comments on commit 4b60c98

Please sign in to comment.