-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add height stream example and enhance hypersync-client with streaming capabilities #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…eaming capabilities * Introduced a new example for streaming height updates in `examples/height_stream`. * Updated `hypersync-client` to support streaming from the `/height/stream` SSE endpoint. * Modified dependencies in `Cargo.toml` to include necessary libraries for the new functionality.
WalkthroughAdds a new example crate Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor App as Example Binary
participant Client as hypersync_client::Client
participant Req as reqwest
participant Server as Hypersync HTTP(S)
participant Chan as mpsc::channel
App->>Client: stream_height()
activate Client
Client->>Req: GET /height/sse<br/>Accept: text/event-stream<br/>(Bearer if configured)
Req->>Server: HTTP request
Server-->>Req: 200 OK + SSE stream
Client->>Chan: spawn task to read SSE and send heights
deactivate Client
loop For each SSE event
Req-->>Client: next SSE event
Client->>Client: parse data (number or JSON {height})
alt valid height
Client-->>Chan: Ok(u64)
else non-height / parse error
Client-->>Client: ignore or map error
end
end
loop Consumer
App-->>Chan: recv()
alt Ok(height)
App->>App: print height
else Err(e)
App->>App: log error and break
end
end
sequenceDiagram
autonumber
actor User
participant Main as examples/height_stream::main
participant Client as Arc<Client>
participant Chan as mpsc::Receiver<Result<u64>>
User->>Main: run binary
Main->>Main: init env_logger, tokio
Main->>Client: construct with URL
Main->>Client: stream_height()
Client-->>Main: mpsc Receiver
Main->>Chan: loop recv()
alt height
Chan-->>Main: Ok(u64)
Main->>Main: println!(height)
else error
Chan-->>Main: Err(e)
Main->>Main: log and exit loop
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Cargo.toml
(1 hunks)examples/height_stream/Cargo.toml
(1 hunks)examples/height_stream/src/main.rs
(1 hunks)hypersync-client/Cargo.toml
(1 hunks)hypersync-client/src/lib.rs
(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
examples/height_stream/src/main.rs (1)
hypersync-client/src/lib.rs (1)
new
(71-93)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test_release
- GitHub Check: test_dev
🔇 Additional comments (4)
hypersync-client/Cargo.toml (1)
57-57
: Enabling reqwest streaming support looks good.Adding the
stream
feature is necessary for accessingbytes_stream()
and similar SSE helpers, so this change is spot on.Cargo.toml (1)
4-15
: Thanks for registering the new example in the workspace.Including
examples/height_stream
here keeps the workspace consistent and ensures the example builds with the rest of the project.examples/height_stream/Cargo.toml (1)
1-10
: Example crate manifest looks solid.The dependencies line up with the runtime you’re using, and the path link back to
hypersync-client
keeps everything in sync.examples/height_stream/src/main.rs (1)
6-30
: Nice, concise example.This is a clear illustration of the new API, and the error handling is straightforward.
/// | ||
/// Returns a channel receiver that yields `u64` heights. The sender task runs in the background | ||
/// and closes the channel if the connection drops or an error occurs. Messages that cannot be | ||
/// parsed are ignored. | ||
pub async fn stream_height(self: Arc<Self>) -> Result<mpsc::Receiver<Result<u64>>> { | ||
let mut url = self.url.clone(); | ||
let mut segments = url.path_segments_mut().ok().context("get path segments")?; | ||
segments.push("height"); | ||
segments.push("sse"); | ||
std::mem::drop(segments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the /height/stream
endpoint path.
The doc comment (and PR objective) call out /height/stream
, but the code currently appends "sse"
, so the client will receive a 404. Please point the request at the documented path instead.
- segments.push("height");
- segments.push("sse");
+ segments.push("height");
+ segments.push("stream");
🤖 Prompt for AI Agents
In hypersync-client/src/lib.rs around lines 555 to 564 the path segments
appended for the height streaming endpoint use "sse" causing requests to hit the
wrong URL; change the appended segment from "sse" to "stream" so the client
targets "/height/stream" as documented (update the segments.push call
accordingly and keep the rest of the function unchanged).
examples/height_stream
.hypersync-client
to support streaming from the/height/stream
SSE endpoint.Cargo.toml
to include necessary libraries for the new functionality.Summary by CodeRabbit